--- aliases: - /docs/grafana/latest/alerting/contact-points/message-templating/ - /docs/grafana/latest/alerting/contact-points/message-templating/example-template/ - /docs/grafana/latest/alerting/message-templating/ - /docs/grafana/latest/alerting/unified-alerting/message-templating/ keywords: - grafana - alerting - guide - contact point - templating title: Example message template weight: 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" . }} ```