Files
2025-06-19 17:31:13 +01:00

4.3 KiB
Raw Permalink Blame History

aliases weight canonical description keywords labels title menuTitle refs
../../manage-notifications/template-notifications/using-go-templating-language/
../../configure-notifications/template-notifications/using-go-templating-language/
104 https://grafana.com/docs/grafana/latest/alerting/configure-notifications/template-notifications/language/ Use Go template language to create your notification and alert rule templates
grafana
alerting
templates
write templates
products
cloud
enterprise
oss
Alerting template language Template language
alert-rule-template-reference alert-rule-template-reference-variables notification-template-reference reference-notificationdata
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/alerting-rules/templates/reference/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/templates/reference/
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/alerting-rules/templates/reference/#variables
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/templates/reference/#variables
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/configure-notifications/template-notifications/reference/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/configure-notifications/template-notifications/reference/
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/configure-notifications/template-notifications/reference/#notification-data
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/configure-notifications/template-notifications/reference/#notification-data

Alerting template language

Notification templates and alert rule templates, such as annotations and labels, both use the Go template language, text/template.

Both types of templates can use the same keywords, functions, and comparison operators of the Go template language, such as range, if, and, index, eq, and more.

However, it's important to note that because notifications and alert rules operate in distinct context, some additional variables and functions are only available for either notification or alert rule templates. Refer to:

This documentation provides an overview of the functions and operators of the Go template language that are available for both notification and alert rule templates.

Print

To print the value of something, use {{ and }}. You can print the value of a variable, a field of a variable, the result of a function, or the value of dot.

{{ $values }}
{{ $values.A.Value }}
{{ humanize 1000.0 }}
{{ .Alerts }}

Dot

In text/template, there is a special cursor called dot, written as .. You can think of this cursor as a variable whose value changes depending on where in the template it is used.

At the start of notification templates, dot (.) refers to Notification Data.

{{ .Alerts }}

In annotation and label templates, dot (.) is initialized with all alert data. Its recommended to use the $labels and $values variables instead to directly access the alert labels and query values.

{{< admonition type="note" >}} Dot (.) might refer to something else when used in a range, a with, or when writing templates used in other templates. {{< /admonition >}}

{{< docs/shared lookup="alerts/template-language.md" source="grafana" version="<GRAFANA_VERSION>" >}}