Watcher Condition "script" : { "script" : ""}}. Not working

alerting

(Rohit Gupta) #1

Tried using the example mentioned in the documents for scripts inside condition block. It is throwing an error.
Will appreciate any pointers.

"condition" : {
"script" : {
"script" : "return ctx.payload.hits.total > threshold",
"params" : {
"threshold" : 5
}
}
}

Error:

{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "unexpected field [script]"
}
],
"type": "parse_exception",
"reason": "could not parse [script] condition for watch [sample_watcher]. failed to parse script",
"caused_by": {
"type": "parse_exception",
"reason": "unexpected field [script]"
}
},
"status": 400
}


(Uri Boness) #2

try this instead (note s/script/inline)

{
  "condition": {
    "script": {
      "inline": "return ctx.payload.hits.total > threshold",
      "params": {
        "threshold": 5
      }
    }
  }
}

https://www.elastic.co/guide/en/watcher/current/condition.html#_using_a_script_condition


(Rohit Gupta) #3

Yes, the inline worked. So s/script/script is not a valid command.


(carmelo) #4

I tried your example and I got this error:
{ "error": { "root_cause": [ { "type": "script_exception", "reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits.total > threshold] of type [groovy]" } ], "type": "script_exception", "reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits.total > threshold] of type [groovy]" }, "status": 500 }

What can I do to solve this problem ?


(PG) #5

Im also receiving the same error when attempting to setup a new watch.
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.memory && node.memory.value >= 75;] of type [groovy]"
}
],
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.memory && node.memory.value >= 75;] of type [groovy]"
},
"status": 500
}

Reference: https://www.elastic.co/guide/en/watcher/current/watching-marvel-data.html#watching-memory-usage

Any help would be grateful.


Compatibility issues in Watcher?
(carmelo) #6

I Fixed my error:
the problem was on my elasticsearch.yml

I added this :

script.inline: on
script.indexed: on

and now it is working


(PG) #7

Thanks @carmelom. I added those two lines throughout my nodes and master and it has accepted the script.


(Lu) #8

oh !thank you, my friend . my es script is working now!


(system) #9