Browse Source

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.
Alexander Reelsen 7 years ago
parent
commit
11d776ecf0

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

@@ -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";

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

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

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

@@ -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,7 +55,20 @@
                           }
                         ]
                       }
-                    ]
+                    ],
+                    "dynamic_attachments" : {
+                      "list_path" : "ctx.payload.hits.hits",
+                      "attachment_template" : {
+                        "title": "Title",
+                        "fields" : [
+                          {
+                            "title" : "Field title {{_source.name}}",
+                            "value" : "{{_source.value}}",
+                            "short" : true
+                          }
+                        ]
+                      }
+                    }
                   }
                 }
               }