Prometheus alertmanager

组件下载地址:
https://github.com/prometheus/

vim /etc/systemd/system/alertmanager.service
[Unit]
Description=alertmanager
After=network.target

[Service]
ExecStart=/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/alertmanager \
    --config.file=/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/alertmanager.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

cat alertmanager.yml
---
#global:
# #  resolve_timeout: 5m
#
#route:
#  group_by: ['alertname']
#  group_wait: 10s
#  group_interval: 10s
#  repeat_interval: 1h
#  receiver: 'web.hook'
#receivers:
#- name: 'web.hook'
#  webhook_configs:
#  - url: 'http://127.0.0.1:5001/'
#inhibit_rules:
#  - source_match:
#      severity: 'critical'
#    target_match:
#      severity: 'warning'
#    equal: ['alertname', 'dev', 'instance']



global:
  resolve_timeout: 5m
#  smtp_smarthost: 'smtp.exmail.qq.com:465'
#  smtp_from: 'wuyutang@xxxx.com'
#  smtp_auth_username: 'wuyutang@xxxx.com'
#  smtp_auth_password: 'yyyyy'
#  smtp_require_tls: false

  wechat_api_url: "https://qyapi.weixin.qq.com/cgi-bin/"
  wechat_api_secret: "xxxxxx"
  wechat_api_corp_id: "yyyy"
templates:
- '/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/*.tmpl'

route:
  receiver: 'weixin'
  group_wait: 10s
  group_interval: 5m
  repeat_interval: 5h 
  group_by: ['alertname_wechat']

  #routes:
  #- receiver: weixin
  #  match_re:
  #    severity: email

receivers:
#- name: default
#  email_configs:
#  - to: 'wuyutang@xxxx.com'
#- name: diiing
#  email_configs:
#  - to: 'wuyutang@xxxx.com'

- name: 'weixin'
  wechat_configs:
  - corp_id: 'yyyy'
#    to_party: '620'
    to_user: '@all'
    agent_id: '1000026'
    #message: '{{ template "weixin.tmpl" . }}'
    api_secret: 'yyyyyyyyyyyy'
    send_resolved: true
---

cat weixin.tmpl
{{ define "wechat.default.message" }}
{{ range .Alerts }}
告警主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
监控类型: {{ .Labels.job }}
故障主机: {{ .Labels.instance }}
触发时间: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}