Prometheus配置钉钉告警

获取钉钉token


 

docker部署prometheus-webhook-dingtalk


prometheus-webhook-dingtalk地址:

https://github.com/timonwong/prometheus-webhook-dingtalk


钉钉token如下:

https://oapi.dingtalk.com/robot/send?access_token=XXXXXX

 

执行docker安装prometheus-webhook-dingtalk指令

docker run -d --restart always -p 8060:8060 timonwong/prometheus-webhook-dingtalk:v0.3.0 --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=XXXXXX"

 

查看prometheus-webhook-dingtalk容器运行情况

root@test03:/usr/local/alertmanager# docker ps|grep prometheus-webhook-dingtalk
34dcac5e1baf        timonwong/prometheus-webhook-dingtalk:v0.3.0   "/bin/prometheus-web…"   16 hours ago        Up 16 hours         0.0.0.0:8060->8060/tcp   clever_varahamihira


配置alertmanager文件

root@test03:/usr/local/alertmanager# cat alertmanager.yml
global:
  resolve_timeout: 5m
route:
  receiver: webhook
  group_wait: 30s
  group_interval: 1m
  repeat_interval: 4h
  group_by: [alertname]
  routes:
  - receiver: webhook
    group_wait: 10s
receivers:
- name: webhook
  webhook_configs:
  - url: http://localhost:8060/dingtalk/webhook1/send 
    send_resolved: true


注意:http://localhost:8060/dingtalk/webhook1/send ,其中webhook1,一定是当时使用docker运行prometheus-webhook-dingtalk容器指定钉钉接口参数的变量:webhook1,如下:webhook1

--ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=XXXXXX"

 

停止node_exporter.service测试钉钉告警

root@test02:~# systemctl stop node_exporter.service


InstanceDown处于PENDING状态,则等待发送告警,期间是等待告警规则持续一分钟up状态都等于0,才会触发告警


InstanceDown处于FIRING状态,则发送告警给接收者


 

查看钉钉告警信息


 

恢复node_exporter.service

root@test02:~# systemctl start node_exporter.service


查看钉钉恢复信息