无法访问elastalert警报部分内的数据

时间:2017-10-18 17:32:13

标签: elasticsearch elastic-stack elastalert

我一直在尝试在我的ELK堆栈上设置elastalert监控。首先,我想设置一个简单的规则,如果文件系统上的任何磁盘使用率达到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错误而失败。长期困在这里。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

更新:针对elastalert' github repo上的同一问题,reply表示某些查询类型不包含完整的字段数据。

虽然我不确定这是否是实现我想要的正确方法但是我能够使用规则类型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

希望它有所帮助。