好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

elastalert的spike报警类型,监控logstash的filtered/in/out events数量,在一定时间内突增突减情况进行报警

默认分类 | 作者 juneryang | 发布于2019年02月22日 | 阅读数:3177

elk版本为6.3.0,elastalert 版本为0.1.38。使用metricbeat发送logstash节点的信息,保存到es中索引为metricbeat-logstash-*.
这是我的rule:
name: logstash node_stats events out
type: spike_aggregation

es_host: 192.168.10.188
es_port: 9200
es_username: elastic
es_password: elastic
index: metricbeat-logstash-*

buffer_time:
hours: 1

metric_agg_key: logstash.node.stats.events.filtered
metric_agg_type: avg
#query_key: metricset.host
#doc_type: metricsets
#allow_buffer_time_overlap: true
#use_run_every_query_size: true
#threshold_cur: 0.9
#field_value: 8
spike_height: 2000
spike_type: "both"

filter:
- term:
metricset.name: node_stats

alert:
- "debug"

当我尝试启动或者elastalert-test-rule测试规则时,报错:
Traceback (most recent call last):
File "/bin/elastalert-test-rule", line 11, in <module>
load_entry_point('elastalert==0.1.38', 'console_scripts', 'elastalert-test-rule')()
File "/usr/lib/python2.7/site-packages/elastalert/test_rule.py", line 463, in main
test_instance.run_rule_test()
File "/usr/lib/python2.7/site-packages/elastalert/test_rule.py", line 432, in run_rule_test
conf = self.load_conf(rule_yaml, args)
File "/usr/lib/python2.7/site-packages/elastalert/test_rule.py", line 371, in load_conf
load_options(rules, conf, args.file)
File "/usr/lib/python2.7/site-packages/elastalert/config.py", line 183, in load_options
raise EAException("Invalid Rule file: %s\n%s" % (filename, e))
elastalert.util.EAException: Invalid Rule file: spike_test.yaml
{'es_port': 9200, 'name': 'logstash node_stats events out', 'index': 'metricbeat-logstash-*', 'spike_type': 'both', 'es_password': 'elastic', 'spike_height': 2000, 'buffer_time': {'hours': 1}, 'es_username': 'elastic', 'es_host': '192.168.10.188', 'rule_file': 'spike_test.yaml', 'metric_agg_key': 'logstash.node.stats.events.filtered', 'alert': ['debug'], 'type': 'spike_aggregation', 'filter': [{'term': {'metricset.name': 'node_stats'}}], 'metric_agg_type': 'avg'} is not valid under any of the given schemas

Failed validating 'oneOf' in schema:
{'$schema': 'http://json-schema.org/draft-04/schema#',
'definitions': {'arrayOfStrings': {'items': {'type': 'string'},
'type': ['string', 'array']},
'arrayOfStringsOrOtherArrays': {'items': {'type': ['string',
'array']},
'type': ['string',
'array']},
'filter': {},
'mattermostField': {'additionalProperties': False,
'properties': {'args': {'items': {'type': 'string'},
'type': ['string',
'array']},
'short': {'type': 'boolean'},
'title': {'type': 'string'},
'value': {'type': 'string'}},
'type': 'object'},
'timeFrame': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'}},
'oneOf': [{'properties': {'type': {'enum': ['any']}},
'title': 'Any'},
{'properties': {'blacklist': {'items': {'type': 'string'},
'type': 'array'},
'compare_key': {'items': {'type': 'string'},
'type': ['string',
'array']},
'type': {'enum': ['blacklist']}},
'required': ['blacklist', 'compare_key'],
'title': 'Blacklist'},
{'properties': {'compare_key': {'items': {'type': 'string'},
'type': ['string',
'array']},
'ignore_null': {'type': 'boolean'},
'type': {'enum': ['whitelist']},
'whitelist': {'items': {'type': 'string'},
'type': 'array'}},
'required': ['whitelist', 'compare_key', 'ignore_null'],
'title': 'Whitelist'},
{'properties': {'compare_key': {'items': {'type': 'string'},
'type': ['string',
'array']},
'ignore_null': {'type': 'boolean'},
'timeframe': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['change']}},
'required': ['query_key', 'compare_key', 'ignore_null'],
'title': 'Change'},
{'properties': {'attach_related': {'type': 'boolean'},
'doc_type': {'type': 'string'},
'num_events': {'type': 'integer'},
'terms_size': {'type': 'integer'},
'timeframe': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['frequency']},
'use_count_query': {'type': 'boolean'},
'use_terms_query': {'type': 'boolean'}},
'required': ['num_events', 'timeframe'],
'title': 'Frequency'},
{'properties': {'alert_on_new_data': {'type': 'boolean'},
'doc_type': {'type': 'string'},
'spike_height': {'type': 'number'},
'spike_type': {'enum': ['up',
'down',
'both']},
'terms_size': {'type': 'integer'},
'threshold_cur': {'type': 'integer'},
'threshold_ref': {'type': 'integer'},
'timeframe': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['spike']},
'use_count_query': {'type': 'boolean'},
'use_terms_query': {'type': 'boolean'}},
'required': ['spike_height', 'spike_type', 'timeframe'],
'title': 'Spike'},
{'properties': {'doc_type': {'type': 'string'},
'threshold': {'type': 'integer'},
'timeframe': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['flatline']},
'use_count_query': {'type': 'boolean'}},
'required': ['threshold', 'timeframe'],
'title': 'Flatline'},
{'properties': {'alert_on_missing_field': {'type': 'boolean'},
'fields': {'items': {'type': ['string',
'array']},
'type': ['string', 'array']},
'terms_size': {'type': 'integer'},
'terms_window_size': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['new_term']},
'use_terms_query': {'type': 'boolean'}},
'required': [],
'title': 'New Term'},
{'properties': {'cardinality_field': {'type': 'string'},
'max_cardinality': {'type': 'integer'},
'min_cardinality': {'type': 'integer'},
'timeframe': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'type': {'enum': ['cardinality']}},
'required': ['cardinality_field', 'timeframe'],
'title': 'Cardinality'},
{'properties': {'metric_agg_type': {'enum': ['min',
'max',
'avg',
'sum',
'cardinality',
'value_count']},
'type': {'enum': ['metric_aggregation']}},
'required': ['metric_agg_key', 'metric_agg_type'],
'title': 'Metric Aggregation'},
{'properties': {'type': {'enum': ['percentage_match']}},
'required': ['match_bucket_filter'],
'title': 'Percentage Match'},
{'properties': {'type': {'pattern': '[.]'}},
'title': 'Custom Rule from Module'}],
'properties': {'aggregation': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'alert_missing_value': {'type': 'string'},
'alert_text': {'type': 'string'},
'alert_text_args': {'items': {'type': 'string'},
'type': 'array'},
'alert_text_kw': {'type': 'object'},
'alert_text_type': {'enum': ['alert_text_only',
'exclude_fields',
'aggregation_summary_only']},
'alerta_api_key': {'type': 'string'},
'alerta_api_url': {'type': 'string'},
'alerta_attributes_keys': {'items': {'type': 'string'},
'type': 'array'},
'alerta_attributes_values': {'items': {'type': 'string'},
'type': 'array'},
'alerta_correlate': {'items': {'type': 'string'},
'type': 'array'},
'alerta_customer': {'type': 'string'},
'alerta_environment': {'type': 'string'},
'alerta_event': {'type': 'string'},
'alerta_group': {'type': 'string'},
'alerta_new_style_string_format': {'type': 'boolean'},
'alerta_origin': {'type': 'string'},
'alerta_resource': {'type': 'string'},
'alerta_service': {'items': {'type': 'string'},
'type': 'array'},
'alerta_severity': {'enum': ['unknown',
'security',
'debug',
'informational',
'ok',
'normal',
'cleared',
'indeterminate',
'warning',
'minor',
'major',
'critical']},
'alerta_tags': {'items': {'type': 'string'},
'type': 'array'},
'alerta_text': {'type': 'string'},
'alerta_type': {'type': 'string'},
'alerta_value': {'type': 'string'},
'buffer_time': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'command': {'items': {'type': 'string'},
'type': ['string', 'array']},
'email': {'items': {'type': 'string'},
'type': ['string', 'array']},
'email_reply_to': {'type': 'string'},
'es_host': {'type': 'string'},
'es_password': {'type': 'string'},
'es_port': {'type': 'integer'},
'es_username': {'type': 'string'},
'exotel_account_sid': {'type': 'string'},
'exotel_auth_token': {'type': 'string'},
'exotel_from_number': {'type': 'string'},
'exotel_to_number': {'type': 'string'},
'exponential_realert': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'fail_on_non_zero_exit': {'type': 'boolean'},
'field': {},
'filter': {'additionalProperties': False,
'items': {},
'properties': {'download_dashboard': {'type': 'string'}},
'type': ['array', 'object']},
'from_addr': {'type': 'string'},
'generate_kibana_link': {'type': 'boolean'},
'gitter_msg_level': {'enum': ['info', 'error']},
'gitter_proxy': {'type': 'string'},
'gitter_webhook_url': {'type': 'string'},
'hipchat_auth_token': {'type': 'string'},
'hipchat_domain': {'type': 'string'},
'hipchat_from': {'type': 'string'},
'hipchat_ignore_ssl_errors': {'type': 'boolean'},
'hipchat_mentions': {'items': {'type': 'string'},
'type': 'array'},
'hipchat_notify': {'type': 'boolean'},
'hipchat_room_id': {'type': ['string', 'integer']},
'import': {'type': 'string'},
'include': {'items': {'type': 'string'},
'type': 'array'},
'index': {'type': 'string'},
'jira_account_file': {'type': 'string'},
'jira_assignee': {'type': 'string'},
'jira_bump_in_statuses': {'items': {'type': 'string'},
'type': ['string',
'array']},
'jira_bump_not_in_statuses': {'items': {'type': 'string'},
'type': ['string',
'array']},
'jira_bump_tickets': {'type': 'boolean'},
'jira_component': {'items': {'type': 'string'},
'type': ['string', 'array']},
'jira_components': {'items': {'type': 'string'},
'type': ['string', 'array']},
'jira_issuetype': {'type': 'string'},
'jira_label': {'items': {'type': 'string'},
'type': ['string', 'array']},
'jira_labels': {'items': {'type': 'string'},
'type': ['string', 'array']},
'jira_max_age': {'type': 'number'},
'jira_project': {'type': 'string'},
'jira_server': {'type': 'string'},
'jira_watchers': {'items': {'type': 'string'},
'type': ['string', 'array']},
'kibana_dashboard': {'type': 'string'},
'linenotify_access_token': {'type': 'string'},
'match_enhancements': {'items': {'type': 'string'},
'type': 'array'},
'mattermost_channel_override': {'type': 'string'},
'mattermost_icon_url_override': {'type': 'string'},
'mattermost_ignore_ssl_errors': {'type': 'boolean'},
'mattermost_msg_color': {'enum': ['good',
'warning',
'danger']},
'mattermost_msg_fields': {'additionalProperties': False,
'properties': {'args': {'items': {'type': 'string'},
'type': ['string',
'array']},
'short': {'type': 'boolean'},
'title': {'type': 'string'},
'value': {'type': 'string'}},
'type': 'object'},
'mattermost_msg_pretext': {'type': 'string'},
'mattermost_proxy': {'type': 'string'},
'mattermost_username_override': {'type': 'string'},
'mattermost_webhook_url': {'items': {'type': 'string'},
'type': ['string',
'array']},
'max_query_size': {'type': 'integer'},
'name': {'type': 'string'},
'notify_email': {'items': {'type': 'string'},
'type': ['string', 'array']},
'owner': {'type': 'string'},
'pagerduty_client_name': {'type': 'string'},
'pagerduty_event_type': {'enum': ['none',
'trigger',
'resolve',
'acknowledge']},
'pagerduty_service_key': {'type': 'string'},
'pagertree_integration_url': {'type': 'string'},
'pipe_match_json': {'type': 'boolean'},
'priority': {'type': 'integer'},
'query_delay': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'query_key': {'items': {'type': 'string'},
'type': ['string', 'array']},
'raw_count_keys': {'type': 'boolean'},
'realert': {'additionalProperties': False,
'properties': {'days': {'type': 'number'},
'hours': {'type': 'number'},
'milliseconds': {'type': 'number'},
'minutes': {'type': 'number'},
'schedule': {'type': 'string'},
'seconds': {'type': 'number'},
'weeks': {'type': 'number'}},
'type': 'object'},
'replace_dots_in_field_names': {'type': 'boolean'},
'scan_entire_timeframe': {'type': 'boolean'},
'simple_proxy': {'type': 'string'},
'simple_webhook_url': {'items': {'type': 'string'},
'type': ['string', 'array']},
'slack_emoji_override': {'type': 'string'},
'slack_icon_url_override': {'type': 'string'},
'slack_ignore_ssl_errors': {'type': 'boolean'},
'slack_msg_color': {'enum': ['good',
'warning',
'danger']},
'slack_parse_override': {'enum': ['none', 'full']},
'slack_text_string': {'type': 'string'},
'slack_username_override': {'type': 'string'},
'slack_webhook_url': {'items': {'type': 'string'},
'type': ['string', 'array']},
'smtp_host': {'type': 'string'},
'stride_access_token': {'type': 'string'},
'stride_cloud_id': {'type': 'string'},
'stride_conversation_id': {'type': 'string'},
'stride_ignore_ssl_errors': {'type': 'boolean'},
'telegram_api_url': {'type': 'string'},
'telegram_bot_token': {'type': 'string'},
'telegram_room_id': {'type': 'string'},
'timestamp_field': {'type': 'string'},
'top_count_keys': {'items': {'type': 'string'},
'type': 'array'},
'top_count_number': {'type': 'integer'},
'twilio_account_sid': {'type': 'string'},
'twilio_auth_token': {'type': 'string'},
'twilio_from_number': {'type': 'string'},
'twilio_to_number': {'type': 'string'},
'use_kibana_dashboard': {'type': 'string'},
'use_local_time': {'type': 'boolean'},
'use_ssl': {'type': 'boolean'},
'use_strftime_index': {'type': 'boolean'},
'verify_certs': {'type': 'boolean'},
'victorops_api_key': {'type': 'string'},
'victorops_entity_display_name': {'type': 'string'},
'victorops_entity_id': {'type': 'string'},
'victorops_message_type': {'enum': ['INFO',
'WARNING',
'ACKNOWLEDGEMENT',
'CRITICAL',
'RECOVERY']},
'victorops_routing_key': {'type': 'string'}},
'required': ['type', 'index', 'alert'],
'type': 'object'}

On instance:
{'alert': ['debug'],
'buffer_time': {'hours': 1},
'es_host': '192.168.10.188',
'es_password': 'elastic',
'es_port': 9200,
'es_username': 'elastic',
'filter': [{'term': {'metricset.name': 'node_stats'}}],
'index': 'metricbeat-logstash-*',
'metric_agg_key': 'logstash.node.stats.events.filtered',
'metric_agg_type': 'avg',
'name': 'logstash node_stats events out',
'rule_file': 'spike_test.yaml',
'spike_height': 2000,
'spike_type': 'both',
'type': 'spike_aggregation'}

在kibana中,我可以看到相关数据,但时在elastalert中总是规则报错。
 
20190222210632.png 20190222210744.png
已邀请:

要回复问题请先登录注册