Notification Template Examples
In this example we’ve customised our Slack notification to send a URL to our organisation’s wiki on how to deal with the particular alert that’s been sent.
In this example we again customize the text sent to our Slack receiver accessing the and description
stored in the CommonAnnotations
of the data sent by the Alertmanager.
groups:
- name: Instances
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
# Prometheus templates apply here in the annotation and label fields of the alert.
description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
summary: 'Instance {{ $labels.instance }} down'
Receiver
Finally, assuming the same alert as the previous example, we customize our receiver to range over all of the alerts received from the Alertmanager, printing their respective annotation summaries and descriptions on new lines.
- name: 'default-receiver'
slack_configs:
- channel: '#alerts'
title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"
Going back to our first example, we can also provide a file containing named templates which are then loaded by Alertmanager in order to avoid complex templates that span many lines. Create a file under /alertmanager/template/myorg.tmpl
and create a template in it named “slack.myorg.txt”:
The configuration now loads the template with the given name for the “text” field and we provide a path to our custom template file:
global:
slack_api_url: '<slack_webhook_url>'
receiver: 'slack-notifications'
group_by: [alertname, datacenter, app]
receivers:
- name: 'slack-notifications'
slack_configs:
- channel: '#alerts'
text: '{{ template "slack.myorg.text" . }}'
templates: