@ -111,6 +111,12 @@ The name of the alert is {{ .Labels.alertname }}
{{ end }}
```
You can then use the template by passing the [notification data (dot `.`)](ref:reference-notification-data):
```go
{{ template "custom_message" . }}
```
```template_output
The name of the alert is InstanceDown
@ -140,7 +146,11 @@ In this example:
- A template (`alert.summary_and_description`) is defined to print the `summary`, `status`, and `description` of one [alert](ref:reference-alert).
- The main template `custom.alerts` iterates the list of alerts (`.Alerts`) in [notification data](ref:reference-notification-data), executing the `alert.summary_and_description` template to print the details of each alert.
The notification message would look like this:
Execute the template by passing the dot (`.`):
```go
{{ template "custom.alerts" . }}
```
```template_output
2 alert(s)
@ -178,7 +188,11 @@ The following example is similar to the previous one, but it separates firing an
Instead of `.Alerts`, the template accesses `.Alerts.Firing` and `.Alerts.Resolved` separately to print details for each alert.
- The `custom.alert_labels_and_annotations` template iterates over the list of resolved and firing alerts, similar to previous examples. It then executes `alert.labels_and_annotations` for each alert.
- The `alert.labels_and_annotations` template prints all the alert labels and annotations by accessing `.Labels.SortedPairs` and `.Annotations.SortedPairs`.