ElastAlert配置和告警规则各种用法
config.yaml配置说明
#用来加载rule的目录,默认是example_rules
rules_folder: example_rules
#用来设置定时向elasticsearch发送请求
run_every:
minutes: 1
#用来设置请求里时间字段的范围
buffer_time:
minutes: 15
#elasticsearch的host地址
es_host: 192.168.232.191
#elasticsearch 对应的端口号
es_port: 9200
#可选的,es url前缀
#es_url_prefix:elasticsearch
#可选的,查询es的方式,默认是GET
#es_send_get_body_as:GET
#可选的,选择是否用SSL连接es,true或者false
#use_ssl: True
#可选的,是否验证TLS证书,设置为true或者false,默认为- true
#verify_certs: True
#es认证的username和password
#es_username: someusername
#es_password: somepassword
#elastalert产生的日志在elasticsearch中的创建的索引
writeback_index: elastalert_status
#失败重试的时间限制
alert_time_limit:
days: 2
创建ElastAlert索引
可以在/usr/bin/目录下看到以下四个命令:
$ ll /usr/bin/elastalert*
-rwxr-xr-x 1 root root 399 Nov 20 16:39 /usr/bin/elastalert
-rwxr-xr-x 1 root root 425 Nov 20 16:39 /usr/bin/elastalert-create-index
-rwxr-xr-x 1 root root 433 Nov 20 16:39 /usr/bin/elastalert-rule-from-kibana
-rwxr-xr-x 1 root root 419 Nov 20 16:39 /usr/bin/elastalert-test-rule
- elastalert-create-index会创建一个索引,ElastAlert 会把执行记录存放到这个索引中,默认情况下,索引名叫 elastalert_status。其中有4个_type,都有自己的@timestamp 字段,所以同样也可以用kibana来查看这个索引的日志记录情况。
- elastalert-rule-from-kibana从Kibana已保存的仪表盘中读取Filtering 设置,帮助生成config.yaml里的配置。不过注意,它只会读取 filtering,不包括queries。
- elastalert-test-rule测试自定义配置中的rule设置。
执行elastalert-create-index在ES创建索引,这不是必须的步骤,但是强烈建议创建。因为对于审计和测试很有用,并且重启ES不影响计数和发送
$ elastalert-create-index
1.邮箱报警配置
# Alert when the rate of events exceeds a threshold
# (Optional)
# Elasticsearch host
es_host: 192.168.232.191
# (Optional)
# Elasticsearch port
es_port: 9200
# (OptionaL) Connect with SSL to Elasticsearch
#use_ssl: True
# (Optional) basic-auth username and password for Elasticsearch
#es_username: someusername
#es_password: somepassword
# (Required)
# Rule name, must be unique
name: Example frequency rule
# (Required)
# Type of alert.
# the frequency rule type alerts when num_events events occur with timeframe time
type: frequency
# (Required)
# Index to search, wildcard supported
index: metricbeat-*
# (Required, frequency specific)
# Alert when this many documents matching the query occur within a timeframe
num_events: 5
# (Required, frequency specific)
# num_events must occur within this amount of time to trigger an alert
timeframe:
hours: 4
# (Required)
# A list of Elasticsearch filters used for find events
# These filters are joined with AND and nested in a filtered query
# For more info: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html
filter:
- query_string:
query: "system.process.cpu.total.pct: > 10%" // field支持嵌套
smtp_host: smtp.163.com
smtp_port: 25
smtp_auth_file: /opt/elastalert/smtp_auth.yaml
#回复给那个邮箱
email_reply_to: xxx@163.com
##从哪个邮箱发送
from_addr: xxx@163.com
# (Required)
# The alert is use when a match is found
alert:
- "email"
# (required, email specific)
# a list of email addresses to send alerts to
email:
- "yyy@qq.com"
上述配置表示选择metricbeat作为告警索引,在4小时内讲匹配过滤规则,当CPU使用百分比的值为10%超过5次后,即满足告警条件,然后发送邮件
还有一个smtp_auth.yaml文件,这个里面记录了发送邮箱的账号和密码,163邮箱有授权码机制,所以密码处应该填写授权码(没有的话则需要开启)。
#发送邮件的邮箱
user: xxx@163.com
#不是邮箱密码,是设置的POP3密码
password: xxx
高级配置
避免重复告警
# 5分钟内相同的报警不会重复发送
realert:
minutes: 5
# 指数级扩大 realert 时间,中间如果有报警,
# 则按照5>10>20>40>60不断增大报警时间到制定的最大时间,
# 如果之后报警减少,则会慢慢恢复原始realert时间
exponential_realert:
hours: 1
聚合相同告警
# 根据报警的内容,将相同的报警安装 name 来聚合
aggregation_key: name
# 聚合报警的内容,只展示 name 与 message
summary_table_fields:
- name
- message
告警内容格式化
可以自定义告警内容,内部是使用Python的format来实现的
alert_subject: "Error {} @{}"
alert_subject_args:
- name
- "@timestamp"
alert_text_type: alert_text_only
alert_text: |
### Error frequency exceeds
> Name: {}
> Message: {}
> Host: {} ({})
alert_text_args:
- name
- message
- hostname
- host
测试rule
可以在运行rule之前先通过elastalert-test-rule命令来测试一下
$ elastalert-test-rule ~/elastalert/example_rules/example_frequency.yaml
运行rule
启动elastalert服务,监听es,这里加了--rule example_frequency.yaml
表示只运行example_frequency.yaml这一个rule文件,如果不加该选项则会运行rules_folder下所有rule文件,上面配置中的rules_folder为默认的example_rules。
$ python -m elastalert.elastalert --verbose --rule example_frequency.yaml
为了让服务后台运行并且可以达到守护进程的效果,在生产环境中笔者建议使用supervisor管理。
ElastAlert配置和告警规则各种用法的更多相关文章
- 实用干货丨如何使用Prometheus配置自定义告警规则
前 言 Prometheus是一个用于监控和告警的开源系统.一开始由Soundcloud开发,后来在2016年,它迁移到CNCF并且称为Kubernetes之后最流行的项目之一.从整个Linux服务器 ...
- elastalert 配置post告警方式(备忘)
最近在做把elk告警日志发送到kinesis 流,供后续数据分析处理使用........ 基于尽量不修改elastalert ,把修改工作放到接收端服务的原则.计划把elk的告警数据通过远程api ...
- 采用docker方式安装ElastAlert,图形化配置告警规则----具体内容有删改,仅供查看
1.创建几个文件夹保存ElastAlert相关配置信息,用来挂载到容器中使用 2.编写核心配置,创建 ${ELASTALERT}/config/config.yaml用来存储核心配置: 3.Elast ...
- 基于Elastalert的安全告警剖析
https://www.freebuf.com/sectool/164591.html *本文作者:bigface,本文属 FreeBuf 原创奖励计划,未经许可禁止转载. elastalert 是一 ...
- Prometheus监控学习笔记之Prometheus 2.0 告警规则介绍
0x00 变化 Prometheus 2.0 已经发布一段时间了,从今天开始我将分几篇文章为大家介绍其中的一些变化. 此篇文章主要介绍 2.0 的告警规则声明的新写法. 从 1.x 到 2.0 规则声 ...
- ElastAlert监控日志告警Web攻击行为
由于公司需要监控web攻击行为,而因某些原因搭不了waf,才不得不用ElastAlert进行告警,此为前提. 一.ELK安装 Elasticsearch 是一个分布式.可扩展.实时的搜索与数据分析引擎 ...
- ElastAlert监控日志告警Web攻击行为---tomcat和nginx日志json格式
一.ELK安装 1.2 elk配置 logstash自定义配置文件,取名为filebeat_log.conf : input { beats { port => 5044 client_inac ...
- zabbix的自动发现、自定义添加监控项目、配置邮件告警
1.zabbix的自动发现这里的自动发现,所显示出来的是规则的上自动了现 然后 可以对其内容进行相关的配制,如时间或周期 注意:对于单个主机的规则,可以自行添加或删除, 但对于已经添加好了的规则,若需 ...
- 配置AutoMapper映射规则《转》
配置AutoMapper映射规则 AutoMapper是基于约定的,因此在实用映射之前,我们需要先进行映射规则的配置. public class Source { public int SomeVal ...
随机推荐
- X86寄存器
前置知识 x86泛指一系列基于Intel 8086且向后兼容的中央处理器指令集架构.最早的8086处理器于1978年由Intel推出,为16位微处理器. 80X86 包括Intel 8086.8018 ...
- SpringBoot数据库管理 - 用flyway对数据库管理和迁移
上文介绍了Liquibase,以及和SpringBoot的集成.除了Liquibase之外,还有一个组件Flyway也是经常被使用到的类似的数据库版本管理中间件.本文主要介绍Flyway, 以及Spr ...
- Cube Stacking 来源:洛谷
题目 题目oj(洛谷) Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes ...
- Class对象共嫩
需求:写一个"框架",不能改变该类的任何代码的前提下,可以帮我们创建任意类的对象,并且执行其中任意方法 实现: 1.配置文件 2.反射 步骤: 1.将需要创建的对象的全类名和需要执 ...
- 用JavaScript写随机出一个颜色
function changeColor(){ var r = parseInt(Math.random()*255) var g = parseInt(Math.random()*255) var ...
- Auto.js pro 开发环境配置
本文仅供学习交流使用,如侵立删!demo下载见文末 Auto.js pro 开发环境配置 准备: 1.Auto.js Pro Auto.js 已暂停维护 -下载链接放在了文章底部,有需要自行下载 2. ...
- http、https和Cookie
http和https http,https 都是网络传输协议 是用于网络相关传输,http走的是明文传输,https走的密文传输(内部采用对称加密以及非对称加密).对应的https安全性要高于http ...
- Luogu[YNOI2019]排序(DP,线段树)
要最优?就要一步到位,不能做"马后炮",走"回头路",因此将序列映射到一个假定最优序列,发现移动原序列等价于删除原序列元素,以便生成最大不下降子序列.可线段树维 ...
- 树莓派4B无屏幕连接Wi-Fi/启用ssh/创建用户
前边总得说点什么 最近每次在Win10上写代码需要启动Redis,残血Redis For Windows有卡死系统的bug.由于主机内存不大够用(已经扩到顶了),开虚拟机运行Redis更别提了..想起 ...
- 设置 Git 用户名和邮箱
安装完 Git 之后,要做的第一件事就是设置你的用户名和邮件地址.因为每一个提交都会使用这些信息,如果你不完善它们,在 GitHub 远程仓库里很有可能没有你的贡献统计. 以下操作需要你打开 Git ...