Alertmanager 同时触发邮件报警和钉钉报警
所有文章索引:https://blog.51cto.com/liujingyu/2541908
获取钉钉群组机器人的 Webhook 地址;
- 添加 Webhook 类型的群机器人
- 获取 token 地址,并通过白名单机制进行接入,如果不知道自己的访问钉钉的IP,则可以在服务器上使用 curl 命令获取;
- 获取IP办法
curl 'https://oapi.dingtalk.com/robot/send?access_token=******' -H 'Content-Type: application/json' -d '{"msgtype": "text","text": {"content": "我就是我, 是不一样的烟火"}}'
安装 prometheus-webhook-dingtalk
GitHub地址:https://github.com/timonwong/prometheus-webhook-dingtalk
docker pull timonwong/prometheus-webhook-dingtalk:latest
docker run -d --restart always -p 8060:8060 timonwong/prometheus-webhook-dingtalk:latest --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=******"
调整报警策略,加入之前邮件报警的 receiver 组中,使之同时触发报警
[root@localhost alertmanager]# cat alertmanager.yml
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.163.com:25'
smtp_from: '******@163.com'
smtp_auth_username: '******@163.com'
smtp_auth_password: '******'
route:
group_by: ['alertname']
group_wait: 10s # 报警触发等待时间
group_interval: 1m # 报警触发时间
repeat_interval: 5m # 轮询报警触发时间
receiver: jsb # 接收方
routes:
- receiver: jsb
group_wait: 10s
group_interval: 1m
repeat_interval: 5m
receivers:
- name: 'jsb'
email_configs:
- to: "*****@qq.com, ******@163.com"
webhook_configs: # 可以在另写一个 receiver_name ,然后进行匹配,为了同时验证效果写在一个 name 下边,这样邮件和钉钉可以同时触发
- url: http://192.168.202.239:8060/dingtalk/webhook1/send
send_resolved: true
systemctl restart alertmanager.service
报警演示