[prometheus] alertmanager 自定义告警模板

{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
[告警触发]
----------
{{- range .Alerts.Firing }}
告警名称: {{ .Labels.alertname }}
告警主题: {{ .Annotations.summary}}
告警详情: {{ .Annotations.description}}
故障时间: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{ end }}
{{ end }}

{{- if gt (len .Alerts.Resolved) 0 -}}
[告警恢复]
----------
{{- range .Alerts.Resolved }}
告警名称: {{ .Labels.alertname }}
告警主题: {{ .Annotations.summary}}
告警详情: {{ .Annotations.description}}
告警时间: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{ end }}
{{ end }}
{{- end }}

  注意只有最后一行的end前是"{{-"

posted @ 2023-02-08 17:17  金枪语  阅读(507)  评论(0编辑  收藏  举报