I create a watch,
The watch action transform tries to replace the payload.
I'm partially successful, but several items do not work as I expected
-
The payload is replaced, but I want to create a list of name-value pairs. I can create a list if I only use names. Once I used name value pairs, I get an array. How do I create a list in the transform?
-
When I try to print just the list, it gets turned into an object. Why is list important to me? Because I wish to use mustache to iterate over the list produced by the execution, and I don't know how to make mustache iterate over an object. Iterate over object key/value pairs? · Issue #457 · janl/mustache.js · GitHub.
Blockquote
DELETE _xpack/watcher/watch/alex_watch
PUT _xpack/watcher/watch/alex_watch
{
"metadata" : {
"name" : "DevOps Salt Minion Errors",
"time_range" : "now-2d"
},
"trigger": { "schedule": { "interval": "30m" } },
"input": {
"search": {
"request": {
"indices": ["salt-minion-*"],
"body": {
"query": {
"bool": {
"must": [
{ "range" : { "@timestamp": { "gte": "{{ctx.metadata.time_range}}" } } },
{ "exists" : { "field" : "text" } },
{ "wildcard" : { "text" : "*failed*" } }
]
}
},
"size" : 0,
"aggregations": { "by_text": { "terms": { "field": "text", "size": 2 } } }
}
}
}
},
"condition": { "compare": { "ctx.payload.hits.total": { "gt": 0 } } },
"actions": {
"send-to-anelson": {
"throttle_period" : "1h",
"transform": {
"script": "return [ 'title':'froggies', 'mylist' : ['bug','sev2'] , 'yourlist' : [ '1':'one', '2':'two'] ] "
},
"webhook" : {
"method" : "POST",
"url" : "https://hooks.slack.com/services/xxx",
"headers" : { "Content-Type" : "application/json" },
"body": "{ \"text\": \" \npayload=>{{ctx.payload}},\nmylist=>{{ctx.payload.mylist}},\nyourlist={{ctx.payload.yourlist}}\n \" } "
}
}
}
}
POST _xpack/watcher/watch/alex_watch/_execute