1

我安裝了監視器並給出了條件。同時給予其條件給我錯誤...無法爲elasticsearch提供條件給觀察者?

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

什麼是動態腳本?它給我錯誤,它被禁用。 我的觀察者狀況如下。

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" : "[email protected]", 
     "subject" : "Encountered {{ctx.payload.hits.total}} errors", 
     "body" : "Too many error in the system, see attached data", 
     "attach_data" : true, 
     "priority" : "high" 
     } 
    } 
    } 
}' 

回答

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

3

@andrei是對有關如何啓用動態腳本在Elasticsearch,我正要貼上相同的鏈接。

但是,根據您指定的條件,看起來您實際上並不需要使用腳本!看守有compare條件,它看起來像一個完美的結合:

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

在你的情況下,條件是這樣的:

{ 
    ... 

    "condition" : { 
    "compare" : { 
     "ctx.payload.hits.total" : { 
     "gte" : 5 
     } 
    } 
    ... 
} 
+0

我刪除守望歷史,並再次安裝。即時通訊得到這樣的錯誤再次.. 。 ------------------------------------------------- ----> {「error」:「WatcherException [未能放置watch [error_status]];嵌套:StrictDynamicMappingException [映射設置爲嚴格,不允許在[watch]內動態引入[_status]];」,「,狀態「:500} –

+0

看起來您已安裝了預發佈版本的觀察器。請按照此處的說明進行升級:https://www.elastic.co/guide/en/watcher/current/release-notes.html#upgrade-instructions –