一、添加机器人
步骤:选择群组 >> 群设置 >> 智能群助手 >> 添加机器人 >> 自定义
注意:选择过程中会有三种安全设置
1.第一个自定义关键字是说你在以后发送的文字中必须要有这个关键字,否则发送不成功。
2.加签是一种特殊的加密方式,第一步,把timestamp+"\n"+密钥当做签名字符串,使用HmacSHA256算法计算签名,然后进行Base64 encode,最后再把签名参数再进行urlEncode,得到最终的签名(需要使用UTF-8字符集)。
3.IP地址就是说你在发送时会获取你的IP地址,如果不匹配就发送不成功。
二、修改配置
1、进行 prometheus-webhook-dingtalk 配置
这里有个小坑
刚添加机器人的时候,参考了网上的指南,选择了加签的方式。将 Webhook 和签值都复制出来,因为配置文件中会用到。
这里 url 配置的是 机器人 Webhook 的地址,secret 配置的是签值,配置完之后,重启 prometheus-webhook-dingtalk,进行 curl 测试之后提示如下信息:
{"errcode":310000,"errmsg":"sign not match"}
最终调整为IP地段,curl 测试通过,prometheus-webhook-dingtalk的配置未做任何修改。
2、进行 alertmanager.yml 配置
global:
# 每一分钟检查一次是否恢复
resolve_timeout: 1m
route:
# 采用哪个标签来作为分组依据
group_by: ['alertname']
# 组告警等待时间。也就是告警产生后等待10s,如果有同组告警一起发出
group_wait: 10s
# 两组告警的间隔时间
group_interval: 10s
# 重复告警的间隔时间,减少相同告警的发送频率
repeat_interval: 1h
# 设置默认接收人
receiver: 'webhook'
routes:
- receiver: webhook
group_wait: 10s
match:
team: node
receivers:
- name: 'webhook'
webhook_configs:
- url: http://localhost:8060/dingtalk/ops_dingding/send
# 告警被解决之后是否通知
send_resolved: true
---
# 检查alertmanager配置文件
./amtool check-config alertmanager.yml
3、进行 prometheus 配置
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "rules/*.yml"
# rules文件夹下的规则配置文件,内容如下
groups:
- name: hostStatsAlert
rules:
- alert: InstanceDown
expr: up == 0
for: 1m
labels:
serverity: warning
annotations:
summary: "Instance {{$labels.instance}} down"
console: "{{$labels.instance}} of job {{$labels.job}} has been down for more than 1 minutes."