用于将 Alertmanager 的告警信息通过企业微信的 Webhook 接口将告警信息发送到指定的企业微信群。
1.运行容器
docker run --name wechat-webhook \
-p 8999:8999 \
--restart=always \
-d \
lushirong/wechat-webhook:latest
镜像版本
latest,即lushirong/wechat-webhook:latest,包含region,适合区分地域/环境的场景,需要在 prometheus 的 labels 增加 region 标签。 镜像版本v2,即lushirong/wechat-webhook:v2,没有region,如果不需要区分地域/环境,则可以用该版本镜像。
2.配置 Alertmanager
在 Alertmanager 的配置文件中,添加 Webhook 接收器,指向上述容器的地址。
receivers:
- name: webhook-test
webhook_configs:
- url: 'http://127.0.0.1:8999/alert?token=xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx'
其中 xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx 是企业微信机器人生成的 Webhook 地址。
3.测试
curl -X POST http://127.0.0.1:8999/alert?token=xxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx \
-H "Content-Type: application/json" \
-d '{
"alerts": [
{
"status": "firing",
"labels": {
"region": "深圳测试环境",
"instance": "172.16.20.20",
"severity": "critical",
"alertname": "InstanceDown"
},
"annotations": {
"summary": "Instance 172.16.20.20 down",
"description": "The instance 172.16.20.20 is down."
},
"startsAt": "2025-03-01T00:30:30Z",
"endsAt": "0001-01-01T00:00:00Z"
},
{
"status": "resolved",
"labels": {
"region": "深圳测试环境",
"instance": "172.16.20.20",
"severity": "critical",
"alertname": "InstanceDown"
},
"annotations": {
"summary": "Instance 172.16.20.20 is back up",
"description": "The instance 172.16.20.20 has recovered."
},
"startsAt": "2025-03-04T14:30:30Z",
"endsAt": "2025-03-04T14:47:05Z"
}
]
}'
Content type
Image
Digest
sha256:0c933ad21…
Size
70.3 MB
Last updated
over 1 year ago
docker pull lushirong/wechat-webhook