Template data

Template data is passed on to message templates as well as sent as payload to webhook pushes.

NameTypeNotes
ReceiverstringName of the contact point that the notification is being sent to.
Statusstringfiring if at least one alert is firing, otherwise resolved.
AlertsAlertList of alert objects that are included in this notification (see below).
GroupLabelsKeyValueLabels these alerts were grouped by.
CommonLabelsKeyValueLabels common to all the alerts included in this notification.
CommonAnnotationsKeyValueAnnotations common to all the alerts included in this notification.
ExternalURLstringBack link to the Grafana that sent the notification. If using external Alertmanager, back link to this Alertmanager.

The Alerts type exposes functions for filtering alerts:

  • Alerts.Firing returns a list of firing alerts.
  • Alerts.Resolved returns a list of resolved alerts.

Alert

NameTypeNotes
Statusstringfiring or resolved.
LabelsKeyValueA set of labels attached to the alert.
AnnotationsKeyValueA set of annotations attached to the alert.
StartsAttime.TimeTime the alert started firing.
EndsAttime.TimeOnly set if the end time of an alert is known. Otherwise set to a configurable timeout period from the time since the last alert was received.
GeneratorURLstringA back link to Grafana or external Alertmanager.
SilenceURLstringLink to grafana silence for with labels for this alert pre-filled. Only for Grafana managed alerts.
DashboardURLstringLink to grafana dashboard, if alert rule belongs to one. Only for Grafana managed alerts.
PanelURLstringLink to grafana dashboard panel, if alert rule belongs to one. Only for Grafana managed alerts.
FingerprintstringFingerprint that can be used to identify the alert.
ValueStringstringA string that contains the labels and value of each reduced expression in the alert.

KeyValue

KeyValue is a set of key/value string pairs that represent labels and annotations.

Here is an example containing two annotations:

  1. {
  2. "summary": "alert summary",
  3. "description": "alert description"
  4. }

In addition to direct access of data (labels and annotations) stored as KeyValue, there are also methods for sorting, removing and transforming.

NameArgumentsReturnsNotes
SortedPairsSorted list of key & value string pairs
Remove[]stringKeyValueReturns a copy of the Key/Value map without the given keys.
Names[]stringList of label names
Values[]stringList of label values

Functions

Some functions to transform values are also available, along with default functions provided by Go templating.

NameArgumentsReturns
titlestringCapitalizes first character of each word.
toUpperstringConverts all characters to upper case.
matchpattern, stringMatch a string using RegExp.
reReplaceAllpattern, replacement, stringRegExp substitution, unanchored.
joinstring, []stringConcatenates the elements of the second argument to create a single string. First argument is the separator.
safeHtmlstringMarks string as HTML, not requiring auto-escaping.
stringSlice…stringReturns passed strings as slice of strings.