2017-10-18 113 views
2

我一直在嘗試在我的ELK堆棧上設置elastalert監控。一開始,我想設置一個簡單的規則,如果文件系統上的任何磁盤使用率達到80%,將生成通知。該規則似乎工作正常,但在alert部分我無法將數據傳遞給python腳本。 alert部分中的未註釋命令給出以下錯誤無法訪問elastalert警報部分內的數據

ERROR:root:Error while running alert command: Error formatting command: 'system.filesystem.mount_point'錯誤。

這是我的規則文件。請原諒yaml的格式。

name: Metricbeat high FS percentage 
type: metric_aggregation 

es_host: localhost 
es_port: 9200 

index: metricbeat-* 

buffer_time: 
minutes: 1 

metric_agg_key: system.filesystem.used.pct 
metric_agg_type: max 
query_key: beat.name.keyword 
doc_type: metricsets 

bucket_interval: 
    minutes: 1 

realert: 
    minutes: 2 

sync_bucket_interval: true 
#allow_buffer_time_overlap: true 
#use_run_every_query_size: true 

max_threshold: 0.8 

filter: 
- query: 
    query_string: 
     query: "system.filesystem.device_name: dev" 
     analyze_wildcard: true 
- term: 
    metricset.name: filesystem 

# (Required) 
# The alert is use when a match is found 

alert: 
    - debug 
    - command 
command: ["/home/ubuntu/sendToSlack.py","beat-name","%(beat.name.keyword)s","used_pc","%(system.filesystem.used.pct_max)s","mount_point","%(system.filesystem.mount_point)s"] 
# command: ["/home/ubuntu/sendToSlack.py","--beat-name","{match[beat.name.keyword]}","--mount_point","{match[system.filesystem.mount_point]}"] 
# command: ["/home/ubuntu/sendToSlack.py","--beat-name","{match[beat][name]}","--mount_point","{match[system][filesystem][mount_point]}"] 
#pipe_match_json: true 
#- command: 
# command: ["/home/ubuntu/sendToSlack.py","%(system.filesystem.used.bytes)s"] 

一些觀察: 使用命令python -m elastalert.test_rule rules/high_fs.yaml測試規則文件我得到的輸出

我應該能夠訪問上述任何領域。當我運行使用這個規則被打印在屏幕

@timestamp: 2017-10-18T17:15:00Z 
beat.name.keyword: my_server_name 
num_hits: 98 
num_matches: 5 
system.filesystem.used.pct_max: 0.823400020599 

我能夠訪問此列表中的所有鍵值對的列表。列表之外的任何內容都會因爲formatting錯誤而失敗。長期以來一直困在這。任何幫助表示讚賞。

回答

0

更新:一個reply對elastalert的GitHub庫同樣的問題說,某些查詢類型不包含完整的現場數據。

雖然我不確定這是否是實現我所尋找的正確方法,但我可以使用規則類型any並編寫我自己的過濾器來獲得所需的輸出。這是我的一個規則文件目前的樣子。

name: High CPU percentage 
type: any 

es_host: localhost 
es_port: 9200 

index: consumer-* 
query_key: 
    - beat.name 

filter: 
- range: 
    system.cpu.total_norm_pct: 
     from: 0.95 
     to: 10.0 

realert: 
    minutes: 60 

alert: 
- command: 
    command: ["/home/ubuntu/slackScripts/sendCPUDetails.py","{match[beat][name]}","{match[system][cpu][total_norm_pct]}"] 
new_style_string_format: true 

希望它可以幫助別人。