1

I installed watcher and giving the condition. While giving the condition its giving me error that...

{"error":"WatcherException[failed to put watch [log_error_watch]]; nested: ScriptConditionValidationException[failed to compile script [return ctx.payload.hits.total > 5] with lang [groovy] of type [INLINE]]; nested: ScriptException[dynamic scripting for [groovy] disabled]; ","status":500}

What is dynamic scripting? Its giving me error that it is disabled. My condition to the watcher is as follows.

curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '{
  "metadata" : { 
    "color" : "red"
  },
  "trigger" : { 
    "schedule" : {
      "interval" : "10s"
    }
  },
  "input" : { 
    "search" : {
      "request" : {
        "search_type" : "count",
        "indices" : "logs",
        "body" : {
          "query" : { "match" : { "status" : "error" } }
        }
      }
    }
  },
  "condition" : { 
    "script" : "return ctx.payload.hits.total > 5"
  },
  "transform" : { 
    "search" : {
        "request" : {
          "indices" : "logs",
          "body" : {
            "query" : { "match" : { "status" : "error" } }
          }
        }
    }
  },
  "actions" : { 
    "my_webhook" : {
      "webhook" : {
        "method" : "GET",
        "host" : "mylisteninghost",
        "port" : 9200,
        "path" : "/{{watch_id}}",
        "body" : "Encountered {{ctx.payload.hits.total}} errors"
      }
    },
    "email_administrator" : {
      "email" : {
        "to" : "xxxxxx.xxx@gmail.com",
        "subject" : "Encountered {{ctx.payload.hits.total}} errors",
        "body" : "Too many error in the system, see attached data",
        "attach_data" : true,
        "priority" : "high"
      }
    }
  }
}'
4

2 回答 2

3

@andrei 关于如何在 Elasticsearch 中启用动态脚本是正确的,我正要粘贴相同的链接。

但是,根据您指定的条件,您似乎根本不需要使用脚本!Watcher 有一个compare条件,看起来非常合适:

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

在您的情况下,条件如下所示:

    {
  ...

  "condition" : {
    "compare" : {
      "ctx.payload.hits.total" : { 
        "gte" : 5 
      }
  }
  ...
}
于 2015-06-26T14:51:08.067 回答
0

您需要在 Elasticsearch 中启用动态脚本:https ://www.elastic.co/guide/en/watcher/current/condition.html#condition-script

评估脚本的监视条件。默认的脚本语言是 groovy。您可以使用 Elasticsearch 支持的任何脚本语言,只要该语言支持将表达式计算为布尔值即可。请注意,小胡子和表达式语言过于受限,无法在此条件下使用。有关更多信息,请参阅 Elasticsearch 参考中的脚本。

重要的

您必须在 elasticsearch.yml 中显式启用动态脚本才能使用内联或索引脚本。

并实际启用动态脚本:https ://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting

于 2015-06-26T14:05:43.340 回答