深色模式
钉钉/飞书/企业微信通知
摘要:三类 IM 都提供“群机器人 Webhook”,但入参格式不同。最省事的做法是用
prometheus-webhook-dingtalk等适配器做格式转换,Alertmanager 只管往一个统一地址发。
适用环境
- 已运行 Alertmanager
- 在对应 IM 群里添加一个自定义机器人,拿到 webhook 地址
操作步骤
1. 部署钉钉适配器(飞书/企微类似)
bash
# 以 prometheus-webhook-dingtalk 为例
docker run -d -p 8060:8060 \
-e 'DINGTALK_WEBHOOK=https://oapi.dingtalk.com/robot/send?access_token=XXXX' \
timonwong/prometheus-webhook-dingtalk1
2
3
4
2
3
4
2. 在 Alertmanager 里配 receiver
yaml
receivers:
- name: 'dingtalk'
webhook_configs:
- url: 'http://localhost:8060/dingtalk/webhook'
- name: 'feishu'
webhook_configs:
- url: 'http://localhost:8070/open/feishu' # 飞书适配器地址
- name: 'wecom'
webhook_configs:
- url: 'http://localhost:8080/webhook/wecom' # 企微适配器地址1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
3. 路由到对应群
yaml
route:
routes:
- matchers: ['team="infra"']
receiver: 'dingtalk'
- matchers: ['team="payment"']
receiver: 'feishu'1
2
3
4
5
6
2
3
4
5
6
DANGER
机器人 webhook 的 token 等于“能往群里发消息的钥匙”,务必放密钥管理/环境变量,别提交进代码仓库。
验证
bash
amtool alert add alertname=ImTest severity=warning team=infra
# 对应 IM 群应收到一条卡片/文本告警1
2
2
常见坑
WARNING
- 钉钉/企微机器人有频率限制(通常每分钟 20 条),告警风暴会被限流丢弃,关键告警走电话/OnCall 更稳。
- 飞书卡片消息需在适配器里配模板,否则只发纯文本。