alertmanager 配置邮件+邮件模板

alertmanager启动脚本

 /usr/lib/systemd/system/alertmanager.service
[Unit]
Description=alertmanager

[Service]
ExecStart=/data/alertmanager/alertmanager ---
config.file=/data/alertmanager/alertmanager.yml --
storage.path=/data/alertmanager/data --web.listen-address=:9093 --
data.retention=120h

Restart=on-failure

[Install]
WantedBy=multi-user.targe
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.163.com:465'
  smtp_from: '[email protected]'
  smtp_auth_username: '[email protected]'
  smtp_auth_password: 'VSFGFMZVREDBZHNQ'
  smtp_require_tls: false

templates:
- '/data/alertmanager/template/default.tmpl'

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 20m
  repeat_interval: 10m
  receiver: 'email'
  routes:
  - receiver: 'email'
    match:
      severity: Disaster
#  routes:
#  - match_re:
#      resource: ^(memory|cpu|disk)$
#    receiver: system-pager
#    continue: false
#    routes:
#    - match:
#        severity: critical
#      receiver:  critical-pager
#    - match:
#        resource: net
#      receiver: net-pager
#
#    - match:
#        resource: host
#      receiver: system-pager
#      continue: true
#      routes:
#      - match:
#          severity: crirical
#        receiver: critical-pager
receivers:
      - name: 'email'
        email_configs:
          - to: '[email protected]'
            html: '{{ template "default.html" .}}'
#            headers: { Subject: "{{ .GroupLabels.SortedPairs.Values }} [{{ .Status | toUpper }}:{{ .Alerts.Firing | len }}]" }
            send_resolved: true
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']
{{ define "default.html" }}
{{- if gt (len .Alerts.Firing) 0 -}}
[{{ .Status | toUpper }}:{{ .Alerts.Firing | len }}]
{{ range $i, $alert := .Alerts }}
告警程序: prometheus_alert 
告警级别: {{ .Labels.severity }} 级
告警类型: {{ .Labels.alertname }}
故障主机: {{ .Labels.instance }}
告警主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
开始时间:{{ $alert.StartsAt.Local }}
{{ end }} {{ end }} {{- if gt (len .Alerts.Resolved) 0 -}} [{{ .Status | toUpper }}:{{ .Alerts.Resolved | len }}] {{ range $i, $alert := .Alerts }}
告警程序: prometheus_alert 
故障主机: {{ .Labels.instance }}
故障主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
告警时间: {{ .StartsAt.Local.Format "2006-01-02 15:04:05" }}
恢复时间: {{ .EndsAt.Local.Format "2006-01-02 15:04:05" }}
{{ end }} {{ end }} {{- end }}

你可能感兴趣的:(前端,python,javascript)