一、复制frequency模板信息python
[root@k8s-slave1 example_rules]# cd /usr/local/elastalert/example_rules/ [root@k8s-slave1 example_rules]# cp example_frequency.yaml test.yaml
二、修改test.yaml监控规则nginx
es_host: 10.3.153.200 #elasticsearch 主机 es_port: 9200 #主机监听端口 name: frequency test rule #规则名,同时也是邮件的标题 type: frequency #规则才用的规则 index: logstash-nginx-* #检查那个索引信息的内容 num_events: 1 #在timeframe时间内,出现了多少次,才发送告警 timeframe: minutes: 1 #统计1分钟内的数据 #如下为过滤匹配的规则,关于具体的查询匹配方法,基本于本博客上的elasticsearch 查询方法文章一致。 filter: - query_string: query: "status: >=500" #status大于500以上 #邮件链接的信息 smtp_host: smtp.163.com smtp_port: 465 smtp_ssl: True smtp_auth_file: /usr/local/elastalert/smtp_auth_file.yaml #密码信息 #回复那个邮箱 email_reply_to: ibm.chick@163.com #用那个邮箱账号发送 from_addr: ibm.chick@163.com alert: - "email" email: - "ibm.chick@163.com" #要接受该邮件的人员
三、建立smtp_auth_file.yaml文件数组
[root@k8s-slave1 ~]# cat /usr/local/elastalert/smtp_auth_file.yaml #邮箱用户名 user: ibm.chick@163.com ##不是邮箱密码,是设置的SMTP密码 password: xxxxxx
一、启用规则
备注:当前为展现效果,启动方式--verbose模式,正常状况下应为后台启动,同时能够对整个rules文件夹的全部规则进行统一加载。app
elastalert --config /usr/local/elastalert/config.yaml --rule /usr/local/elastalert/example_rules/test.yaml &
二、使用代码往该索引插入数据(制造错误信息)elasticsearch
三、发现匹配信息ide
备注:咱们在排查的过程当中,能够使用debug模式启动,可获取的日志信息更多,以下:测试
四、查看邮件内容debug
一、在用python插入数据时,需使用@timestamp字段,此字段数据,是经过--debug模式的检查时间,复制到程序上,并多加1分钟内进行插入数据(后期用上logstash后不须要使用)
二、字段过滤filter,可参考elasticsearch 条件查询文档方法,同时要注意索引下的字段类型,到底是数字仍是字符,能够经过mapping映射查询。
三、在测试验证环节上,能够经过debug模式运行规则,可便于整个过程的排查调试。
四、关于elastalert运行状况与日志信息,能够在elasticsearch上进行查看。调试