Template reference
The data a notification template can read. The top-level context is one notification, covering a group of alerts.
Top-level fields
Fields on each alert
Inside {{ range .Alerts }}, the dot becomes one alert:
Common compared with group labels
These three are easy to confuse:
.GroupLabels: the labels named ingroup_by. Always present, always identical across the group..CommonLabels: labels that happen to be identical across every alert in the group. A wider set than.GroupLabels, and it shrinks as the group becomes more varied..Labels, inside a range: that one alert’s labels, including the ones that differ.
A template using .CommonLabels.instance renders correctly while a group holds one instance and renders empty the moment a second joins. When a value has to be present, use .GroupLabels or read it per alert inside a range.
Accessing a label
{{ .GroupLabels.alertname }}
{{ .CommonLabels.severity }}
{{ range .Alerts }}{{ .Labels.instance }}{{ end }}For label names that aren’t valid identifiers—anything with a dot or dash—use index:
{{ index .CommonLabels "k8s.namespace" }}Formatting times
{{ .StartsAt.Format "2006-01-02 15:04:05 MST" }}Go’s reference time is 2006-01-02 15:04:05; the layout string is that exact moment written the way you want your output to look.
Where the annotation content comes from
.Annotations holds values the ruler already rendered during evaluation. A notification template can read and rearrange them, but it can’t recover information the alert never carried. That has to be added at the rule. Refer to Template annotations and labels.


