ElastAlert通过飞书机器人发送报警通知

前言

公司采用ELK架构搜集业务系统的运行日志,只有在业务出现问题的时候,才会去kibana上进行日志搜索操作,每次都是被用户告知系统出问题了,这简直是被啪啪打脸~

重新build ElastAlert2镜像

由于官方的镜像中不包含飞书通知方式,因此需要重新拉取镜像和elastalert-feishu-plugin源码

源码下载地址:

复制代码
https://github.com/jmucaicai/elastalert-feishu-plugin

拉取elastalert2

复制代码
docker pull docker.1ms.run/jertel/elastalert2

配置elastalert.yaml

复制代码
rules_folder: /opt/elastalert/rules

run_every:
  seconds: 10

buffer_time:
  minutes: 15

es_host: localhost
es_port: 9200
es_username: XXXXX
es_password: XXXXX
use_ssl: True
verify_certs: False 

writeback_index: elastalert_status

alert_time_limit:
  days: 2

启动容器

复制代码
docker run --net=host -d --name elastalert --restart=always -v $(pwd)/elastalert.yaml:/opt/elastalert/config.yaml -v $(pwd)/rules:/opt/elastalert/rules  -v /etc/localtime:/etc/localtime elastalert2 --verbose

启动后,将elastalert-feishu-plugin目录里面的两个文件复制到容器里面

复制代码
docker cp __init__.py elastalert:/usr/local/lib/python3.13/site-packages/elastalert/elastalert_modules/__init__.py

docker cp feishu_alert.py elastalert:/usr/local/lib/python3.13/site-packages/elastalert/elastalert_modules/feishu_alert.py

创建新镜像后,再去执行容器的启动命令

复制代码
docker commit elastalert elastalert2:latest

配置预警规则

在当前目录创建一个rules目录,并配置一个yaml文件。配置重启容器即可

复制代码
name: "sms-error-rule"
type: "any"            # 有多种类型,不同的类型配置项有不同
index: "sms-errorlog-*"
is_enabled: true

# 时间触发的次数
# num_events: 1

# 和num_events参数关联,1分钟内出现1次会报警
# timeframe:
#   minutes: 1

# 同一规则的两次警报之间的最短时间。在此时间内发生的任何警报都将被丢弃。默认值为一分钟。
# realert:
#   minutes: 0

# terms_size: 50

use_strftime_index: true

filter:
- query:
    query_string:
      query: "message : 'SMS9999"   # 错误级别是ERROR并且msg字段包含java开头Exception结尾的内容就匹配成功,elastalert就会推送报警
      
include: ["@timestamp", "_index", "host.name", "LogLevel", "message"]  # 这里是es索引中的字段,下边报警模板会使用

alert:
  - "elastalert.elastalert_modules.feishu_alert.FeishuAlert"

# 飞书机器人接口地址
feishualert_url: "https://open.feishu.cn/open-apis/bot/v2/hook/"
# 飞书机器人id
feishualert_botid: "xxxxxxxxxxxxx7"

# 告警标题
feishualert_title: "重发禁止时间段内走非95通道下发"

# 这个时间段内的匹配将不告警,适用于某些时间段请求低谷避免误报警
# feishualert_skip:
#   start: "01:00:00"
#   end: "08:00:00"

# 告警内容,使用{}可匹配matches
feishualert_body:
  "
  【告警主机】:  {host.name}\n
  【告警主题】:  {feishualert_title}\n
  【总请求数】:  {num_hits}\n
  【告警时间】:  {feishualert_time}\n
  【业务索引】:  {_index}\n
  【时间戳】:  {@timestamp}\n
  【日志级别】:  {LogLevel}\n
  【错误日志】:  {message}
  "

参考链接:https://blog.csdn.net/qq_22917163/article/details/132168407
参考链接:https://github.com/jertel/elastalert2

相关推荐
夜幕龙12 小时前
宇树 G1 部署(十)——数据格式转换与 IL 训练
人工智能·机器人·具身智能
GitLqr13 小时前
AI洞察 | 智元、阿里在机器人领域的重磅开源
meta·机器人·llm
ZPC821015 小时前
Fanuc 机器人rmi 功能
机器人
是乐谷16 小时前
阿里云杭州 AI 产品法务岗位信息分享(2025 年 8 月)
java·人工智能·阿里云·面试·职场和发展·机器人·云计算
学术小白人21 小时前
会议征稿2025年能源互联网与电气工程国际学术会议(EIEE 2025)
人工智能·机器人·能源
沫儿笙2 天前
焊接机器人保护气体效率优化
人工智能·机器人
javgo.cn2 天前
Spring AI Alibaba - 聊天机器人快速上手
人工智能·ai·机器人
zskj_zhyl2 天前
科技赋能千年养生丨七彩喜艾灸机器人,让传统智慧触手可及
人工智能·科技·机器人
人类发明了工具2 天前
【机器人-基础知识】ROS常见功能架构
机器人
计算机sci论文精选2 天前
CVPR2025敲门砖丨机器人结合多模态+时空Transformer直冲高分,让你的论文不再灌水
人工智能·科技·深度学习·机器人·transformer·cvpr