Are formatters available in input Mustache templates?

alerting

(Dan Becker) #1

Our Elasticsearch instance has indexes that are named based on the date. For example "cal-root-2016-03-15", "cal-root-2016-03-16", etc.

I'd like to be able to use date formatting in Mustache templates to create the path on the input http clause.

For example, this unformatted Mustache template works in input http:

   "request": {
          "host": "localhost",
          "method": "post",
          "path": "/cal-root-{{ctx.execution_time}}/logs/_search",
          "params": {
            "search_type": "count"
          },
          "body": {...}
   }

To produce this kind of path for a put request path:

"path": "/cal-root-2016-03-16T14:08:51.720Z/logs/_search",

I would like to be able to do this formatted Mustache template in input http:

      "request": {
               "host": "localhost",
              "method": "post",
               "path": "/cal-root-{{dateFormat ctx.execution_time format=\"TTTT-mm-DD\"}}/logs/_search",
               "params": {
                 "search_type": "count"
               },
               "body": {...}
        }

This would produce the desired formatted put request path

"path": "/cal-root-2016-03-16/logs/_search",

Is some sort of date formatting available on the Mustache templates in Watcher?

Thanks, beckerdo


(Alexander Reelsen) #2

Hey,

formatters are not supported. A workaround for your problem might be to not try to have any date logic in your watch, but just use an alias, that points to the currently active index and update this either using a watch during midnight or a tool like curator.

--Alex


(Steve Kearns) #3

It sounds like you could also use the date math in index names support in Elasticsearch to achieve this?


(system) #4