Skip to content

Commit e7debce

Browse files
committed
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.
1 parent 279f292 commit e7debce

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherIndexTemplateRegistryField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public final class WatcherIndexTemplateRegistryField {
1212
// version 3: include watch status in history
1313
// version 6: upgrade to ES 6, removal of _status field
1414
// version 7: add full exception stack traces for better debugging
15+
// version 8: fix slack attachment property not to be dynamic, causing field type issues
1516
// Note: if you change this, also inform the kibana team around the watcher-ui
16-
public static final String INDEX_TEMPLATE_VERSION = "7";
17+
public static final String INDEX_TEMPLATE_VERSION = "8";
1718
public static final String HISTORY_TEMPLATE_NAME = ".watch-history-" + INDEX_TEMPLATE_VERSION;
1819
public static final String TRIGGERED_TEMPLATE_NAME = ".triggered_watches";
1920
public static final String WATCHES_TEMPLATE_NAME = ".watches";

x-pack/plugin/core/src/main/resources/watch-history.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@
507507
"properties" : {
508508
"color" : {
509509
"type" : "keyword"
510+
},
511+
"fields" : {
512+
"properties" : {
513+
"value" : {
514+
"type" : "text"
515+
}
516+
}
510517
}
511518
}
512519
}

x-pack/qa/third-party/slack/src/test/resources/rest-api-spec/test/slack/10_slack.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
},
1717
"input": {
1818
"simple": {
19-
"foo" : "something from input"
19+
"foo" : "something from input",
20+
"hits" : {
21+
"hits" : [
22+
{ "_source" : { "name" : "first", "value" : "2018-04-26T11:45:12.518Z" } },
23+
{ "_source" : { "name" : "second", "value" : "anything" } }
24+
]
25+
}
2026
}
2127
},
2228
"actions": {
@@ -49,7 +55,20 @@
4955
}
5056
]
5157
}
52-
]
58+
],
59+
"dynamic_attachments" : {
60+
"list_path" : "ctx.payload.hits.hits",
61+
"attachment_template" : {
62+
"title": "Title",
63+
"fields" : [
64+
{
65+
"title" : "Field title {{_source.name}}",
66+
"value" : "{{_source.value}}",
67+
"short" : true
68+
}
69+
]
70+
}
71+
}
5372
}
5473
}
5574
}

0 commit comments

Comments
 (0)