告警-微信

修改alertmanager.yml

global:
  resolve_timeout: 2m
  smtp_smarthost: 'smtp.163.com:25'
  smtp_from: 'alizabbix@163.com'
  smtp_auth_username: 'alizabbix@163.com'
  smtp_auth_password: 'aabb1122'
  smtp_require_tls: false
templates:
  - 'xxxx/wechat.tmpl'            # 微信摸版路径
route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 1h 
  receiver: 'wechat'               # 优先使用wechat报警
  routes:
  - receiver: mail
    match_re:
      serverity: mail              # 匹配到serverity时mail的使用邮件报警,这里的serverity是rules文件中的labels指定的
receivers:
- name: 'mail'
  email_configs:
  - to: 'xxx@xxx.com'
    send_resolved: true
- name: 'wechat'
  wechat_configs:
  - corp_id: 'xxx'  #企业ID
    to_party: 'xxx'   #组id
    agent_id: 'xxx'   #agentid
    api_secret: 'xxxx'    #生成的secret
    send_resolved: true

只告警,恢复后不发送消息

{{ define “wechat.default.message” }}
{{ range .Alerts }}
========start==========
告警程序:prometheus_alert
告警级别:{{ .Labels.severity }}
告警类型:{{ .Labels.alertname }}
故障主机:{{ .Labels.instance }}
告警主题:{{ .Annotations.summary }}
告警详情:{{ .Annotations.description }}
触发时间:{{ .StartsAt.Format “2006-01-02 15:04:05” }}
========end==========
{{ end }}
{{ end }}

带恢复告警的模版 注:需要在alertmanager.yml的wechat_configs中加上配置send_resolved: true

{{ define "wechat.default.message" }}
{{ range $i, $alert :=.Alerts }}
===alertmanager监控报警===
告警状态:{{   .Status }}
告警级别:{{ $alert.Labels.severity }}
告警类型:{{ $alert.Labels.alertname }}
告警应用:{{ $alert.Annotations.summary }}
故障主机:{{ $alert.Labels.instance }}
告警主题:{{ $alert.Annotations.summary }}
触发阀值:{{ $alert.Annotations.value }}
告警详情:{{ $alert.Annotations.description }}
触发时间:{{ $alert.StartsAt.Format “2006-01-02 15:04:05” }}
===========end============
{{ end }}
{{ end }}

Last updated