prometheus使用阿里云企业邮箱告警
修改/data/alertmanager/alertmanager.yml 加入邮件配置
# 全局配置项
global:
resolve_timeout: 5m # 处理超时时间,默认为5min
smtp_from: 'seafile@pdabc.com'
smtp_smarthost: 'smtp.mxhichina.com:465'
smtp_auth_username: 'seafile@pdabc.com'
smtp_auth_password: '${password}'
smtp_require_tls: false
# 定义路由树信息
route:
group_by: [alertname] # 报警分组依据
receiver: ops_notify # 设置默认接收人
group_wait: 30s # 最初即第一次等待多久时间发送一组警报的通知
group_interval: 60s # 在发送新警报前的等待时间
repeat_interval: 1h # 重复发送告警时间。默认1h
routes:
- receiver: ops_notify # 基础告警通知
group_wait: 10s
match_re:
alertname: 实例存活告警|磁盘使用率告警 # 匹配告警规则中的名称发送
- receiver: info_notify # 消息告警通知
group_wait: 10s
match_re:
alertname: 内存使用率告警|CPU使用率告警
# 定义基础告警接收者
receivers:
- name: ops_notify
webhook_configs:
- url: http://localhost:8060/dingtalk/ops_dingding/send
send_resolved: true # 警报被解决之后是否通知
email_configs:
# - to: '423308591@qq.com‘ 如果两个邮箱中间需要空格
- to: '423308591@qq.com, hugo.xu@pdabc.com'
send_resolved: true
# 定义消息告警接收者
- name: info_notify
webhook_configs:
- url: http://localhost:8060/dingtalk/info_dingding/send
send_resolved: true
# 一个inhibition规则是在与另一组匹配器匹配的警报存在的条件下,使匹配一组匹配器的警报失效的规则。两个警报必须具有一组相同的标签。
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
修改完毕之后重启alertmanager服务
systemctl restart alertmanager
systemctl status alertmanager
然后关闭某台主机测试 钉钉和邮件同时告警
如果发送失败 可以使用下面命令查看日志
journalctl -f -u alertmanager
通知两个邮箱