该项目提供了一个 Webhook 服务,用于接收来自 Prometheus Alertmanager 的告警通知,并将其作为交互式卡片转发到飞书。它还提供了一个 Web 管理界面,用于自定义消息模板和配置 Webhook URL。
- Webhook 接收: 接收 Prometheus Alertmanager 的 Webhook 通知。
- 飞书卡片: 将告警格式化为美观的飞书交互式卡片。
- Web 管理界面: 提供一个带登录验证的管理页面,用于:
- 自定义飞书卡片模板。
- 配置飞书 Webhook URL。
- 发送测试告警以验证配置。
- 灵活配置: 所有配置(包括凭据)都通过
config.json文件管理。 - Docker 支持: 提供 Dockerfile,方便容器化部署。
- Python 3.6+
- Pip
-
克隆代码仓库:
git clone https://github.com/muzihuaner/prometheus-webhook-feishu.git cd prometheus-webhook-feishu -
安装依赖:
pip install -r requirements.txt
-
创建配置文件:
复制
config.example.json并重命名为config.json。cp config.example.json config.json
-
编辑
config.json:USERNAME: 设置管理页面的登录用户名。PASSWORD: 设置管理页面的登录密码。FEISHU_WEBHOOK_URL: 你的飞书机器人 Webhook URL。FEISHU_CARD_TEMPLATE: 自定义飞书卡片的消息模板。
-
运行 Webhook 服务:
python fs.py
服务将在
0.0.0.0:5000上启动。 -
访问管理界面:
在浏览器中打开
http://<你的服务器IP>:5000,你将看到应用的首页。点击链接进入登录页面,使用config.json中配置的用户名和密码登录。 -
配置 Prometheus Alertmanager:
在你的 Alertmanager 配置文件 (
alertmanager.yml) 中,添加一个指向该服务的 Webhook 接收器。receivers: - name: 'feishu-webhook' webhook_configs: - url: 'http://<你的服务器IP>:5000/webhook'
或
global: resolve_timeout: 1m route: receiver: feishu-webhook group_by: - alertname group_wait: 5s group_interval: 1m repeat_interval: 30m receivers: - name: feishu-webhook webhook_configs: - url: http://IP:5000/webhook send_resolved: true
-
构建 Docker 镜像:
docker build -t prometheus-webhook-feishu . -
运行 Docker 容器:
在运行容器时,你需要将
config.json文件挂载到容器中。docker run -d -p 5000:5000 \ -v /root/prometheus-webhook-feishu/:/app/ \ --name prometheus-webhook-feishu \ prometheus-webhook-feishu
服务将在你的 Docker 主机的
5000端口上访问。
该项目根据 MIT 许可证授权。