Elastic stack: 6.2.2
I am trying to convert the payload to JSON and then pass it to a Webhook action.
My Watcher transform script looks like:
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
".watcher-history*"
],
"types": [],
"body": {
"size": 10,
"_source": [
"@timestamp",
"metadata.name",
"watch_id"
],
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-1m/m"
}
}
},
{
"match": {
"watch_id": "Watch_1"
}
}
]
}
},
"sort": [
{
"@timestamp": {
"order": "asc"
}
}
]
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"watcherWebHook": {
"transform" : {
"chain" : [
{
"script": {
"lang": "mustache",
"source": "{{#toJson}}ctx.payload.hits.hits{{/toJson}}"
}
},
{
"script": {
"lang": "painless",
"source": "return [ 'payload': ctx.payload._value.toString() ]"
}
}
]
},
"webhook": {
"scheme": "http",
"host": "webhookEndPointServer",
"port": 80,
"method": "post",
"path": "/raise",
"params": {},
"body": {
"source": {
"payload": {
"execution_time": "{{ctx.execution_time}}",
"watch_id": "{{ctx.watch_id}}",
"body": "{{ctx.payload._value}}"
}
},
"lang": "mustache",
"options": {
"content_type": "application/json; charset=UTF-8"
}
}
}
}
},
"throttle_period_in_millis": 1000
}
Whenever I try to save/simulate the watch, ES throws following error:
[WARN ][r.suppressed ] path: /_xpack/watcher/watch/_execute, params: {}
org.elasticsearch.script.GeneralScriptException: Failed to compile inline script [{{#toJson}}ctx.payload.hits.hits{{/toJson}}] using lang [mustache]
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:340) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.xpack.watcher.transform.script.ExecutableScriptTransform.<init>(ExecutableScriptTransform.java:47) ~[?:?]
at org.elasticsearch.xpack.watcher.transform.script.ScriptTransformFactory.createExecutable(ScriptTransformFactory.java:49) ~[?:?]
at org.elasticsearch.xpack.watcher.transform.script.ScriptTransformFactory.createExecutable(ScriptTransformFactory.java:28) ~[?:?]
at org.elasticsearch.xpack.core.watcher.transform.chain.ChainTransformFactory.createExecutable(ChainTransformFactory.java:55) ~[?:?]
at org.elasticsearch.xpack.core.watcher.transform.chain.ChainTransformFactory.createExecutable(ChainTransformFactory.java:31) ~[?:?]
at org.elasticsearch.xpack.core.watcher.transform.TransformFactory.parseExecutable(TransformFactory.java:53) ~[?:?]
at org.elasticsearch.xpack.core.watcher.transform.TransformRegistry.parse(TransformRegistry.java:64) ~[?:?]
at org.elasticsearch.xpack.core.watcher.transform.TransformRegistry.parse(TransformRegistry.java:53) ~[?:?]
at org.elasticsearch.xpack.core.watcher.actions.ActionWrapper.parse(ActionWrapper.java:224) ~[?:?]
at org.elasticsearch.xpack.core.watcher.actions.ActionRegistry.parseActions(ActionRegistry.java:73) ~[?:?]
at org.elasticsearch.xpack.watcher.watch.WatchParser.parse(WatchParser.java:171) ~[?:?]
at org.elasticsearch.xpack.watcher.watch.WatchParser.parse(WatchParser.java:123) ~[?:?]
at org.elasticsearch.xpack.watcher.watch.WatchParser.parse(WatchParser.java:88) ~[?:?]
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:117) ~[?:?]
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:72) ~[?:?]
at org.elasticsearch.action.support.master.TransportMasterNodeAction.masterOperation(TransportMasterNodeAction.java:88) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$2.doRun(TransportMasterNodeAction.java:167) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:672) [elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.2.jar:6.2.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
Caused by: java.lang.IllegalArgumentException: mustache engine does not know how to handle context [xpack_executable]
at org.elasticsearch.script.mustache.MustacheScriptEngine.compile(MustacheScriptEngine.java:65) ~[?:?]
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:335) ~[elasticsearch-6.2.2.jar:6.2.2]
... 22 more
The same watch definition is compiling in ES 5.6.3, but then it simply generates a string with value if a PagedBytesReference object reference, rather than original JSON value as base64 string.