alertmanager如何自定義告警template
配置alertmanager告警模版
template功能:
https://prometheus.io/blog/2016/03/03/custom-alertmanager-templates/
默認的template:
https://github.com/prometheus/alertmanager/blob/main/template/default.tmpl
配置template:
templates:
- '/etc/alertmanager/alert.template'
route:
group_by: ['instance']
group_wait: 30s
group_interval: 30s
repeat_interval: 120m
receiver: 'internal'
routes:
- receiver: 'internal'
group_by: ['alertname','instance', 'group','job']
receivers:
- name: 'internal'
wechat_configs:
- corp_id: 'xxxxx'
api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
send_resolved: true
to_user: 'zejia.lu'
agent_id: 'xxxxxx'
api_secret: 'xxxxxxxx'
message: '{{ template "wechat.default.message" . }}'
自定義template模版:
{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
========= 監(jiān)控報警 =========
告警狀態(tài):{{ .Status }}
告警級別:{{ .Labels.severity }}
告警類型:{{ $alert.Labels.alertname }}
故障主機: {{ $alert.Labels.instance }}
告警主題: {{ $alert.Annotations.summary }}
告警詳情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};
觸發(fā)閥值:{{ .Annotations.value }}
故障時間: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
========== end ==========
{{- end }}
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
========= 異?;謴?=========
告警類型:{{ .Labels.alertname }}
告警狀態(tài):{{ .Status }}
告警主題: {{ $alert.Annotations.summary }}
告警詳情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};
故障時間: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
恢復時間: {{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{- if gt (len $alert.Labels.instance) 0 }}
實例信息: {{ $alert.Labels.instance }}
{{- end }}
========== end ==========
{{- end }}
{{- end }}
{{- end }}
{{- end }}
效果:
告警觸發(fā)文章來源:http://www.zghlxwxcb.cn/news/detail-642554.html
========= 監(jiān)控報警 =========
告警狀態(tài):firing
告警級別:critical
告警類型:目標采集失敗
故障主機: 1.1.1.1:10001
告警主題: Control Plane Instance metrics collect failed
告警詳情: 1.1.1.1:10001 is unavailable for 15 seconds.;
觸發(fā)閥值:
故障時間: 2023-08-07 11:43:02
========== end ==========
告警恢復文章來源地址http://www.zghlxwxcb.cn/news/detail-642554.html
========= 異常恢復 =========
告警類型:目標采集失敗
告警狀態(tài):resolved
告警主題: Control Plane Instance metrics collect failed
告警詳情: 1.1.1.1:10001 is unavailable for 15 seconds.;
故障時間: 2023-08-07 11:43:02
恢復時間: 2023-08-07 11:49:02
實例信息: 1.1.1.1:10001
========== end ==========
到了這里,關于【博客693】alertmanager如何自定義告警template的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!