使用alertmanager對監控對象進行報警(微信)三

上篇主要講了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: '[email protected]'
  smtp_auth_username: '[email protected]'
  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: '[email protected]'
    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








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章