Last active
October 14, 2022 16:03
-
-
Save Firxiao/bc122b3f6531297e51de94d1d705d6e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/grafana/grafana/blob/main/pkg/services/ngalert/notifier/channels/default_template.go | |
# | |
{{ define "subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }}{{ end }} | |
{{ define "text_values_list" }}{{ $len := len .Values }}{{ if $len }}{{ $first := gt $len 1 }}{{ range $refID, $value := .Values -}} | |
{{ $refID }}={{ $value }}{{ if $first }}, {{ end }}{{ $first = false }}{{ end -}} | |
{{ else }}[no value]{{ end }}{{ end }} | |
{{ define "text_alert_list" }}{{ range . }} | |
{{ .Labels.instance}} | |
{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }} | |
{{ end }} | |
{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }} | |
{{ end }} | |
{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }} | |
{{ end }} | |
{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }} | |
{{ end }} | |
{{ end }}{{ end }} | |
{{ define "title" }}{{ template "subject" . }}{{ end }} | |
{{ define "message" }} | |
{{ if gt (len .Alerts.Firing) 0 }} | |
**Firing** | |
{{ template "text_alert_list" .Alerts.Firing }} | |
{{ if gt (len .Alerts.Resolved) 0 }}{{ end }} | |
{{ end }} | |
{{ if gt (len .Alerts.Resolved) 0 }} | |
**Resolved** | |
{{ template "text_alert_list" .Alerts.Resolved }} | |
{{ end }} | |
{{ end }} | |
{{ define "teams_text_alert_list" }} | |
{{ range . }} | |
{{ .Labels.instance}} | |
{{ if gt (len .GeneratorURL) 0 }}Source: [{{ .GeneratorURL }}]({{ .GeneratorURL }}) | |
{{ end }} | |
{{ if gt (len .SilenceURL) 0 }}Silence: [{{ .SilenceURL }}]({{ .SilenceURL }}) | |
{{ end }} | |
{{ if gt (len .DashboardURL) 0 }}Dashboard: [{{ .DashboardURL }}]({{ .DashboardURL }}) | |
{{ end }} | |
{{ if gt (len .PanelURL) 0 }}Panel: [{{ .PanelURL }}]({{ .PanelURL }}) | |
{{ end }} | |
{{ end }} | |
{{ end }} | |
{{ define "teams.message" }} | |
{{ if gt (len .Alerts.Firing) 0 }}**Firing** | |
{{ template "teams_text_alert_list" .Alerts.Firing }} | |
{{ if gt (len .Alerts.Resolved) 0 }} | |
{{ end }} | |
{{ end }} | |
{{ if gt (len .Alerts.Resolved) 0 }}**Resolved** | |
{{ template "teams_text_alert_list" .Alerts.Resolved }} | |
{{ end }} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment