2017-10-18 109 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 

希望它可以帮助别人。