上篇主要讲了alertmanager组件使用邮件对监控对象进行报警,本文讲解下使用企业微信进行报警,前提环境依赖上文配置。

前提:注册企业微信,添加一个报警的应用,并获取相关信息

agent_id和api_secret

blob.png

to_party

blob.png

corp_id 企业微信页面---->我的企业---->底部的企业ID

blob.png

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

编辑微信报警模板文件

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

收到报警

blob.png