Невозможно получить доступ к данным в разделе предупреждений elastalert

Я пытался настроить 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 ошибка. Застрял над этим надолго. Любая помощь приветствуется.

1 ответ

Решение

ОБНОВЛЕНИЕ: Ответ на ту же проблему в репозитории 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

Надеюсь, это поможет кому-то.

Другие вопросы по тегам