elastalert
我一直在尝试在我的 ELK 堆栈上设置监控。首先,我想设置一个简单的规则,如果文件系统上的任何磁盘已达到 80% 的使用率,它将生成通知。该规则似乎工作正常,但在该alert
部分中我无法将数据传递给 python 脚本。该alert
部分中未注释的命令给出以下错误
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
我得到了输出
Successfully loaded Metricbeat high FS percentage
Got 149161 hits from the last 1 day
Available terms in first hit:
tags
beat.hostname
beat.name
beat.version
type
@timestamp
system.filesystem.available
system.filesystem.files
system.filesystem.mount_point
system.filesystem.free_files
system.filesystem.free
system.filesystem.device_name
system.filesystem.used.bytes
system.filesystem.used.pct
system.filesystem.total
host
@version
metricset.rtt
metricset.name
metricset.module
我应该能够访问上面提到的任何字段。当我使用 python -m elastalert.elastalert --verbose --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
错误而失败。被这件事困了很久。任何帮助表示赞赏。