例如:/data/feishu-alert/config.yaml
例如:/data/feishu-alert/rules
#指定告警文件存放目录
rules_folder: /opt/elastalert/rules
#ElastAlert查询Elasticsearch的频率,这个单位可以是几周到几秒不等
run_every:
minutes: 1
#ElastAlert将缓冲最近的一段时间的结果,以防某些日志源不是实时的
buffer_time:
minutes: 1
#Elasticsearch主机
es_host: xxxxxxxxx
#Elasticsearch端口
es_port: xxxx
#es_host上的索引,用于元数据存储。这可以是一个未映射的索引,但建议你运行。设置一个映射。
writeback_index: elastalert_status
#如果一个警报因某种原因而失败,ElastAlert将重试,直到这个时间段过后
alert_time_limit:
days: 2
文件名称随便自定义,可存创建多个告警文件,放至rules/都会生效
例如:/data/feishu-alert/rules/alert_error.yaml
#rule name 必须是独一的
name: alert_error
#必须设置的值,多种type可上alert官方文档查询
type: frequency
#指定index,支持正则匹配
index: easyspeed-cloud-logs-*
use_strftime_index: true
#时间触发的次数
num_events: 1
#和num_events参数关联,1分钟内出现1次会报警
timeframe:
minutes: 1
#同一规则的两次警报之间的最短时间。在此时间内发生的任何警报都将被丢弃。默认值为一分钟。
realert:
minutes: 1
#用来拼配告警规则,elasticsearch 的query语句,支持 AND&OR等
#我这里是根据业务需求,查询level是ERROR并且type是production且排除message里不带有“开始执行批量/更新轨迹维护/接口请求超时关键字
#简单匹配查询,可以直接query: “level: ERROR“表示level值是ERROR的触发告警通知。
filter:
- query:
query_string:
query: "NOT message: (开始执行批量 OR 更新轨迹维护 OR 接口请求超时) AND level: ERROR AND type: production"
#只需要的字段 https://elastalert.readthedocs.io/en/latest/ruletypes.html#include
include: ["spanId", "level", "@timestamp", "_index", "source", "traceId","host","message"]
#告警方式
alert:
- "elastalert_modules.feishu_alert.FeishuAlert"
# 飞书机器人接口地址
feishualert_url: "https://open.feishu.cn/open-apis/bot/v2/hook/"
# 飞书机器人id
feishualert_botid:
"xxx-xxx-xxx"
# 告警标题
feishualert_title:
"业务日志ERROR异常"
#00-08点不告警
feishualert_skip:
start: "00:00:00"
end: "08:00:00"
#告警内容,使用{}可匹配matches
feishualert_body:
"
【告警主题】: {feishualert_title}\n
【告警时间】: {feishualert_time}\n
【告警环境】: 【production】\n
【告警模块】: {source}\n
【业务索引】: {_index}\n
【时间戳】: {@timestamp}\n
【日志级别】: {level}\n
【spanId】: {spanId}\n
【traceId】: {traceId}\n
【host】: {host}\n
【message】: {message}
"
docker run -d --name elastalert --restart=always \
-v /data/feishu-alert/config.yaml:/opt/elastalert/config.yaml \
-v /data/feishu-alert/rules:/opt/elastalert/rules \
-v /etc/localtime:/etc/localtime \
dengchuanfu/feishualert:v0.1 --verbose
Content type
Image
Digest
sha256:120aa3dc6…
Size
113.9 MB
Last updated
over 3 years ago
docker pull dengchuanfu/feishualert:v0.1