# AlertManager警報通知 E-mail 微信 模板
#AlertManager配置
#alertmanager.yml
# 全局配置項
global:
resolve_timeout: 5m #超時,默認5min
#郵箱smtp服務
smtp_smarthost: 'smtp.qq.com:587'
smtp_from: 'report@elven.vip'
smtp_auth_username: 'report@elven.vip'
smtp_auth_password: 'xxx密碼'
smtp_hello: 'qq.com'
#smtp_require_tls: false
#wechat
#wechat_api_url: "https://qyapi.weixin.qq.com/cgi-bin/"
wechat_api_corp_id: "wwe518* 企業微信賬號唯一ID"
wechat_api_secret: "自定義應用 應用的密鑰"
# 模板
templates:
- '/alertmanager/*.tmpl'
# 路由
route:
group_by: ['alertname'] # 報警分組依據
group_wait: 20s #組等待時間
group_interval: 20s # 發送前等待時間
repeat_interval: 12h #重復周期
receiver: 'email' # 默認警報接收者
#子路由
routes:
- receiver: 'wechat'
match:
severity: test #標簽severity為test時滿足條件,使用wechat警報
# 警報接收者
receivers:
- name: 'email' #警報名稱
email_configs:
- to: '228@elven.vip' # 接收警報的email
html: '{{ template "emai.html" . }}' # 模板
headers: { Subject: " {{ .CommonLabels.instance }} {{ .CommonAnnotations.summary }}" } #標題
- name: 'wechat' #警報名稱
wechat_configs:
- send_resolved: true
to_party: '2' #接收部門id
agent_id: '1000002' #應用ID
to_user: ''
to_tag: ''
message: '{{ template "wechat.html" . }}'
send_resolved: true 恢復后通知
to_user: 企業微信用戶ID
corp_id: 企業微信賬號唯一ID 可以在 我的企業 查看
to_party: 需要發送的組id
agent_id: 應用的 ID,應用管理 --> 打開自定應用查看
api_secret: 應用的密鑰打開企業微信注冊 https://work.weixin.qq.com
微信API官方文檔 https://work.weixin.qq.com/api/doc#90002/90151/90854
#email模板
vi email.tmpl
{{ define "emai.html" }}
{{ range .Alerts }}
<pre>
實例: {{ .Labels.instance }}
信息: {{ .Annotations.summary }}
詳情: {{ .Annotations.description }}
時間: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
</pre>
{{ end }}
{{ end }}
#微信模板
vi wecaht.tmpl
{{ define "wechat.html" }}
{{- if gt (len .Alerts.Firing) 0 -}}{{ range .Alerts }}
@警報
實例: {{ .Labels.instance }}
信息: {{ .Annotations.summary }}
詳情: {{ .Annotations.description }}
時間: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
{{ end }}{{ end -}}
{{- if gt (len .Alerts.Resolved) 0 -}}{{ range .Alerts }}
@恢復
實例: {{ .Labels.instance }}
信息: {{ .Annotations.summary }}
時間: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
恢復: {{ .EndsAt.Format "2006-01-02 15:04:05" }}
{{ end }}{{ end -}}
{{- end }}
警報通知內容,根據需求配置,我本人喜歡內容簡潔
郵件通知