-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
设置自定义模版,发送出来的还是默认的 #117
Comments
@levy0519 解决了没 |
文档有点简陋,我这里有一个例子,可以参考一下: {{ define "my.__text_alert_list" }}
**告警级别:** \[{{ .Labels.severity | upper }}\] {{ .Annotations.summary }}
**告警应用:** {{ .Labels.source }}
**告警实例:** {{ .Labels.instance }}
**告警描述:** {{ .Annotations.description }}
**Prometheus:** [📈]({{ .GeneratorURL }})
**告警详情:**
{{ range .Labels.SortedPairs }}
{{- if and (ne (.Name) "severity") (ne (.Name) "summary") }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}{{ end }}
{{ end }}
{{ define "my.__text_firing_list" }}{{ range . }}
**告警时间:** {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
{{ template "my.__text_alert_list" . }}
{{ end }}{{ end }}
{{ define "my.__text_resolved_list" }}{{ range . }}
**恢复时间:** {{ dateInZone "2006.01.02 15:04:05" (.EndsAt) "Asia/Shanghai" }}
{{ template "my.__text_alert_list" . }}
{{ end }}{{ end }}
{{ define "my.title" }}{{ template "__subject" . }}{{ end }}
{{ define "my.content" }}\[{{ if eq .Status "firing" }}PROBLEM:{{ .Alerts.Firing | len }}{{ else }}RECOVERY:{{ .Alerts.Resolved | len }}{{ end }}\] **[{{ index .GroupLabels "alertname" }}]({{ template "__alertmanagerURL" . }})**
{{ if gt (len .Alerts.Firing) 0 -}}
**Alerts Firing**
{{ template "my.__text_firing_list" .Alerts.Firing }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}
**Alerts Resolved**
{{ template "my.__text_resolved_list" .Alerts.Resolved }}
{{- end }}
{{- end }}
{{ define "ding.link.title" }}{{ template "my.title" . }}{{ end }}
{{ define "ding.link.content" }}{{ template "my.content" . }}{{ end }} |
试着改了一下,改文件没用,到底要怎么改默认的消息??? 每次发出来的都是这几行:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`
##alertmanager.base.yml
templates:
##default.tmpl
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver }}{{ end }}
{{ define "__text_alert_list" }}{{ range . }}
Labels
{{ range .Labels.SortedPairs }}> - {{ .Name }}: {{ .Value | html }}
{{ end }}
Annotations
{{ range .Annotations.SortedPairs }}> - {{ .Name }}: {{ .Value | html }}
{{ end }}
Source: [{{ .GeneratorURL }}]({{ .GeneratorURL }})
{{ end }}{{ end }}
{{ define "default.__text_alert_list" }}{{ range . }}
告警级别: {{ .Labels.severity | upper }}
运营团队: {{ .Labels.team | upper }}
触发时间: {{ dateInZone "2006.01.02 15:04:05" (.StartsAt) "Asia/Shanghai" }}
事件信息:
{{ range .Annotations.SortedPairs }}> - {{ .Name }}: {{ .Value | markdown | html }}
{{ end }}
......
[root@f75f3c0030d8 temp]# amtool check-config ../alertmanager.base.yml
Checking '../alertmanager.base.yml' SUCCESS
Found:
SUCCESS
`
The text was updated successfully, but these errors were encountered: