2017-01-05 62 views
0

我現在正在配置Watcher以在訪問日誌中進行搜索,並查看到目前爲止有多少錯誤並將其發送到閒置帳戶。 嗯,我有這個問題是因爲我不知道在查詢完成時和我的配置中有多少聚合會像「硬編碼」一樣發送,最多隻能發送5個,但如果結果爲grather比5不行。使用Watcher(ElasticSearch)將所有聚合作爲文本發送

我在尋找的查詢和過濾器404狀態碼僅適用於一臺服務器,那麼我只需要發送的所有斗的結果通知如下:

合計:合計數個,其 日誌: LOG1:數的-結果 的log 2:數的-結果 log3中:數的-結果 LOG4:數的-結果 LOG5:數的-結果 LOG6:數的-結果

這裏我的配置:

"trigger" : { 
    "schedule" : { "interval" : "1h" } 
    }, 
    "input" : { 
    "search" : { 
     "request": { 
     "body": { 
     "query": { 
      "bool": { 
      "must": [ 
       { "range": { 
       "@timestamp": { 
        "gte": "now-1h", 
        "lte": "now" 
       } 
       } 
       }, 
       { 
       "match": { 
        "beat.hostname": "someserver" 
       } 
       } 
      ], 
      "filter": { 
       "term": { 
       "response": "404" 
       } 
      } 
      } 
     }, 
     "aggs": { 
      "host": { 
      "terms": { 
       "field": "beat.hostname", 
       "size": 1 
      } 
      }, 
      "logs_list": { 
      "terms": { 
       "field": "source", 
       "size": 10 
      } 
      } 
     } 
     } 
     } 
    } 
    }, 
    "condition": { 
    "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} 
    }, 
    "actions" : { 
    "notify-slack" : { 
     "throttle_period" : "30m", 
     "slack" : { 
     "message" : { 
      "from": "Watcher", 
      "to" : [ "somechannel" ], 
      "attachments" : [ 
      { 
      "title" : "400 code status found", 
      "text" : "Encountered: {{ctx.payload.hits.total}} in the last hour on {{ctx.payload.aggregations.host.buckets.0.key}} \n Files: \n {{ctx.payload.aggregations.logs_list.buckets.0.key}}: {{ctx.payload.aggregations.logs_list.buckets.0.doc_count}} \n {{ctx.payload.aggregations.logs_list.buckets.1.key}}: {{ctx.payload.aggregations.logs_list.buckets.1.doc_count}} \n {{ctx.payload.aggregations.logs_list.buckets.2.key}}: {{ctx.payload.aggregations.logs_list.buckets.2.doc_count}} \n {{ctx.payload.aggregations.logs_list.buckets.3.key}}: {{ctx.payload.aggregations.logs_list.buckets.3.doc_count}} \n {{ctx.payload.aggregations.logs_list.buckets.4.key}}: {{ctx.payload.aggregations.logs_list.buckets.4.doc_count}} \n {{ctx.payload.aggregations.logs_list.buckets.5.key}}: {{ctx.payload.aggregations.logs_list.buckets.5.doc_count}}", 
      "color" : "danger" 
      } 
     ] 
     } 
     } 
    } 
    } 

我不知道如何發送「文本」的行動,任何想法我應該如何通過所有桶結果? 在此先感謝,我使用的是xpack,ELK和logstash。

回答

0

如果我正確理解你的問題,你想循環你的行動聚合。試試這個:

{{#ctx.payload.aggregations.myAggName.buckets}} 
    {{key}}: {{doc_count}} 
{{/ctx.payload.aggregations.myAggName.buckets}} 
+0

哇,確實非常感謝! – jonhatan