Files
JitaC f5a3ac855d Docs: Refactor contact points section of alerting docs (#49758)
* Initial commit

* weight adjustments

* Checkin changes.
2022-05-27 13:37:37 -04:00

1.5 KiB

aliases keywords title weight
/docs/grafana/latest/alerting/contact-points/message-templating/
/docs/grafana/latest/alerting/message-templating/
/docs/grafana/latest/alerting/unified-alerting/message-templating/
grafana
alerting
guide
contact point
templating
Example message template 115

Example of a custom template

Here's an example of how to use a custom template. You can also use the default template included in the setup.

Step 1: Configure a template to render a single alert.

{{ define "myalert" }}
  [{{.Status}}] {{ .Labels.alertname }}

  Labels:
  {{ range .Labels.SortedPairs }}
    {{ .Name }}: {{ .Value }}
  {{ end }}

  {{ if gt (len .Annotations) 0 }}
  Annotations:
  {{ range .Annotations.SortedPairs }}
    {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}

  {{ if gt (len .SilenceURL ) 0 }}
    Silence alert: {{ .SilenceURL }}
  {{ end }}
  {{ if gt (len .DashboardURL ) 0 }}
    Go to dashboard: {{ .DashboardURL }}
  {{ end }}
{{ end }}

Step 2: Configure a template to render entire notification message.

{{ define "mymessage" }}
  {{ if gt (len .Alerts.Firing) 0 }}
    {{ len .Alerts.Firing }} firing:
    {{ range .Alerts.Firing }} {{ template "myalert" .}} {{ end }}
  {{ end }}
  {{ if gt (len .Alerts.Resolved) 0 }}
    {{ len .Alerts.Resolved }} resolved:
    {{ range .Alerts.Resolved }} {{ template "myalert" .}} {{ end }}
  {{ end }}
{{ end }}

Step 3: Add mymessage in the notification message field.

Alert summary:
{{ template "mymessage" . }}