2

elastalertELK スタックで監視を設定しようとしています。最初に、ファイル システム上のいずれかのディスクの使用率が 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エラーで失敗します。これに長い間立ち往生しています。どんな助けでも大歓迎です。

4

1 に答える 1