Alertmanager告警模板
钉钉
{{ define "dingding.to.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
========= **监控告警** =========
**告警程序:** Alertmanager
**告警类型:** {{ $alert.Labels.alertname }}
**告警级别:** {{ $alert.Labels.severity }} 级
**告警状态:** {{ .Status }}
**故障主机:** {{ $alert.Labels.instance }} {{ $alert.Labels.device }}
**告警主题:** {{ .Annotations.summary }}
**告警详情:** {{ $alert.Annotations.message }}{{ $alert.Annotations.description}}
**主机标签:** {{ range .Labels.SortedPairs }} </br> [{{ .Name }}: {{ .Value | markdown | html }} ]
{{- end }} </br>
**故障时间:** {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
========= = end = =========
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
========= 告警恢复 =========
**告警程序:** Alertmanager
**告警主题:** {{ $alert.Annotations.summary }}
**告警主机:** {{ .Labels.instance }}
**告警类型:** {{ .Labels.alertname }}
**告警级别:** {{ $alert.Labels.severity }} 级
**告警状态:** {{ .Status }}
**告警详情:** {{ $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" }}
========= = **end** = =========
{{- end }}
{{- end }}
{{- end }}
邮件表格
{{ define "email.to.html" }}
{{ if gt (len .Alerts.Firing) 0 }}
{{ range $i, $alert := .Alerts }}
<h3>告警邮件</h3>
<table border="1">
<tr>
<td><strong>告警项:</strong></td>
<td>{{ index $alert.Labels "alertname" }}</td>
</tr>
<tr>
<td><strong>告警实例:</strong></td>
<td>{{ index $alert.Labels "instance" }}</td>
</tr>
<tr>
<td><strong>告警级别:</strong></td>
<td bgcolor="{{ index $alert.Labels "severity" }}">{{ index $alert.Labels "severity" }}</td>
</tr>
<tr>
<td><strong>告警主题:</strong></td>
<td>{{ index $alert.Annotations "summary" }}</td>
</tr>
<tr>
<td><strong>告警描述:</strong></td>
<td>{{ index $alert.Annotations "description" }}</td>
</tr>
<tr>
<td><strong>触发时间:</strong></td>
<td>{{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}</td>
</tr>
<tr>
<td><strong>当前告警值:</strong></td>
<td>{{ index $alert.Annotations "value" }}</td>
</tr>
</table>
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
{{ range $i, $alert := .Alerts }}
<h3>告警恢复邮件</h3>
<table border="1">
<tr>
<td><strong>告警项:</strong></td>
<td>{{ index $alert.Labels "alertname" }}</td>
</tr>
<tr>
<td><strong>告警实例:</strong></td>
<td>{{ index $alert.Labels "instance" }}</td>
</tr>
<tr>
<td><strong>告警级别:</strong></td>
<td bgcolor="green"></td>
</tr>
<tr>
<td><strong>告警主题:</strong></td>
<td>{{ index $alert.Annotations "summary" }}</td>
</tr>
<tr>
<td><strong>告警描述:</strong></td>
<td>{{ index $alert.Annotations "description" }}</td>
</tr>
<tr>
<td><strong>恢复时间:</strong></td>
<td>{{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}</td>
</tr>
<tr>
<td><strong>当前值:</strong></td>
<td>{{ index $alert.Annotations "value" }}</td>
</tr>
</table>
{{ end }}
{{ end }}
{{ end }}
webhook-通用
{{ define "wechat.default.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
==========异常告警==========
告警类型: {{ $alert.Labels.alertname }}
告警级别: {{ $alert.Labels.severity }}
告警详情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};{{$alert.Annotations.summary}}
故障时间: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{- if gt (len $alert.Labels.instance) 0 }}
实例信息: {{ $alert.Labels.instance }}
{{- end }}
{{- if gt (len $alert.Labels.namespace) 0 }}
命名空间: {{ $alert.Labels.namespace }}
{{- end }}
{{- if gt (len $alert.Labels.node) 0 }}
节点信息: {{ $alert.Labels.node }}
{{- end }}
{{- if gt (len $alert.Labels.pod) 0 }}
实例名称: {{ $alert.Labels.pod }}
{{- end }}
============END============
{{- end }}
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
{{- if eq $index 0 }}
==========异常恢复==========
告警类型: {{ $alert.Labels.alertname }}
告警级别: {{ $alert.Labels.severity }}
告警详情: {{ $alert.Annotations.message }}{{ $alert.Annotations.description}};{{$alert.Annotations.summary}}
故障时间: {{ ($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 }}
{{- if gt (len $alert.Labels.namespace) 0 }}
命名空间: {{ $alert.Labels.namespace }}
{{- end }}
{{- if gt (len $alert.Labels.node) 0 }}
节点信息: {{ $alert.Labels.node }}
{{- end }}
{{- if gt (len $alert.Labels.pod) 0 }}
实例名称: {{ $alert.Labels.pod }}
{{- end }}
============END============
{{- end }}
{{- end }}
{{- end }}
{{- end }}