06alertmanager配置邮件触发告警

发布时间 2023-03-22 21:16:06作者: 冷夜O

配置前提:

1.部署好prometheus,alertmanager

2.配置好告警规则,alertmanager要先可以接收到告警

 

一.配置alertmanager

 

1.查看alertmanager.yml配置文件

 

 

2.添加发送人邮箱

global:
  resolve_timeout: 5m
  smtp_from: '163xxxxxx@qq.com'
  smtp_smarthost: 'smtp.qq.com:465'
  smtp_auth_username: '163xxxx@qq.com'
  smtp_auth_password: 'mlaatixxxxxehac'
  smtp_require_tls: false
  smtp_hello: 'qq.com'

smtp_auth_password:是你qq邮箱开通的第三方授权码

smtp_require_tls:false 是关闭tls

3.添加邮箱路由

route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: 'email'

receiver:添加对应的接收器

4.设置接收器

receivers:
  - name: 'web.hook'
    webhook_configs:
      - url: 'http://127.0.0.1:5001/'

  - name: 'email'
    email_configs:
    - to: '195xxxxxxx@139.com'
      send_resolved: true

 

send_resolved:设置为true,则告警恢复后会发送邮件通知

 

重启alertmanager.

二.测试

cat /del/zero > /del/null

通过压测cpu使用率使告警生效。

告警发送邮件

 

 

 告警恢复邮件

 

 

 三.添加多个收件人

 

 逗号隔开写上邮箱地址。

- to : 'xxx123@163.com,xxx456@qq.com'