Watcher: Fix watch history template for dynamic slack attachments (#30172)

The part of the history template responsible for slack attachments had a
dynamic mapping configured which could lead to problems, when a string
value looking like a date was configured in the value field of an
attachment.

This commit fixes the template by setting this field always to text.
This also requires a change in the template numbering to be sure this
will be applied properly when starting watcher.
This commit is contained in:
Alexander Reelsen 2018-05-17 11:57:54 +02:00 committed by GitHub
parent 2ac1f9fe89
commit 11d776ecf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View File

@ -12,8 +12,9 @@ public final class WatcherIndexTemplateRegistryField {
// version 3: include watch status in history
// version 6: upgrade to ES 6, removal of _status field
// version 7: add full exception stack traces for better debugging
// version 8: fix slack attachment property not to be dynamic, causing field type issues
// Note: if you change this, also inform the kibana team around the watcher-ui
public static final String INDEX_TEMPLATE_VERSION = "7";
public static final String INDEX_TEMPLATE_VERSION = "8";
public static final String HISTORY_TEMPLATE_NAME = ".watch-history-" + INDEX_TEMPLATE_VERSION;
public static final String TRIGGERED_TEMPLATE_NAME = ".triggered_watches";
public static final String WATCHES_TEMPLATE_NAME = ".watches";

View File

@ -507,6 +507,13 @@
"properties" : {
"color" : {
"type" : "keyword"
},
"fields" : {
"properties" : {
"value" : {
"type" : "text"
}
}
}
}
}

View File

@ -16,7 +16,13 @@
},
"input": {
"simple": {
"foo" : "something from input"
"foo" : "something from input",
"hits" : {
"hits" : [
{ "_source" : { "name" : "first", "value" : "2018-04-26T11:45:12.518Z" } },
{ "_source" : { "name" : "second", "value" : "anything" } }
]
}
}
},
"actions": {
@ -49,12 +55,25 @@
}
]
}
],
"dynamic_attachments" : {
"list_path" : "ctx.payload.hits.hits",
"attachment_template" : {
"title": "Title",
"fields" : [
{
"title" : "Field title {{_source.name}}",
"value" : "{{_source.value}}",
"short" : true
}
]
}
}
}
}
}
}
}
- do:
xpack.watcher.execute_watch: