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

相关推荐
冰糖小新新20 分钟前
基于CanMV K230的工地巡检机器人
人工智能·信息可视化·机器人
WWZZ20251 小时前
ROS2——基础6(TF2机器人坐标系管理器、Gazebo)
机器人·大模型·slam·ros2·激光雷达·具身智能
G果1 小时前
修改nav2导航速度发布名称
机器人·ros2·导航·速度·navigation2·cmd_vel
沐欣工作室_lvyiyi2 小时前
一种简易高灵活性机械四足机器人的设计与实现(论文+源码)
单片机·机器人·毕业设计·四足机器人
全栈视界师2 小时前
《机器人实践开发③:Foxglove可视化机器人的眼睛-视频》
opencv·机器人·音视频
大侠课堂3 小时前
无人机与机器人经典面试题100道-大疆篇
机器人·无人机
deephub4 小时前
BipedalWalker实战:SAC算法如何让机器人学会稳定行走
人工智能·机器学习·机器人·强化学习
扬道财经10 小时前
科技赋能鸟击防控:杭州萧山国际机场引入全天候自主驱鸟机器人系统
科技·机器人
Eric.Lee202113 小时前
物理引擎MuJoCo 项目介绍
人工智能·机器人·仿真·robot·物理引擎·mujoco
想要成为计算机高手13 小时前
π*0.6: 从实践中学习 -- 2025.11.17 -- Physical Intelligence (π) -- 未开源
人工智能·学习·机器人·多模态·具身智能·vla