2022-05-26 23:06:25 +08:00
---
aliases:
2022-12-10 00:36:04 +08:00
- ../../contact-points/message-templating/
- ../../message-templating/
- ../../unified-alerting/message-templating/
2023-07-18 18:29:00 +08:00
canonical: https://grafana.com/docs/grafana/latest/alerting/fundamentals/alert-rules/message-templating/
2023-01-19 01:26:34 +08:00
description: Notification templating
2022-05-26 23:06:25 +08:00
keywords:
- grafana
- alerting
- guide
- contact point
- templating
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- cloud
- enterprise
- oss
2023-01-19 01:26:34 +08:00
title: Notification templating
2022-10-27 02:07:49 +08:00
weight: 415
2022-05-26 23:06:25 +08:00
---
2021-06-07 19:01:21 +08:00
2023-01-19 01:26:34 +08:00
# Notification templating
2021-06-07 19:01:21 +08:00
2023-03-09 16:18:36 +08:00
Notifications sent via contact points are built using notification templates. Grafana's default templates are based on the [Go templating system ](https://golang.org/pkg/text/template ) where some fields are evaluated as text, while others are evaluated as HTML (which can affect escaping).
The default template [default_template.go ](https://github.com/grafana/alerting/blob/main/templates/default_template.go ) is a useful reference for custom templates.
2021-06-07 19:01:21 +08:00
2023-01-27 01:45:09 +08:00
Since most of the contact point fields can be templated, you can create reusable custom templates and use them in multiple contact points.
2021-06-07 19:01:21 +08:00
2021-10-28 04:57:54 +08:00
### Using templates
2021-06-07 19:01:21 +08:00
2022-01-12 04:16:04 +08:00
The following example shows how to use default templates to render an alert message in Slack. The message title contains a count of alerts that are firing or were resolved. The message body lists the alerts and their status.
2021-06-07 19:01:21 +08:00
2022-05-28 01:37:37 +08:00
{{< figure src = "/static/img/docs/alerting/unified/contact-points-template-fields-8-0.png" class = "docs-image--no-shadow" max-width = "550px" caption = "Default template" > }}
2021-06-07 19:01:21 +08:00
2021-10-28 04:57:54 +08:00
The following example shows the use of a custom template within one of the contact point fields.
2021-06-07 19:01:21 +08:00
2022-05-28 01:37:37 +08:00
{{< figure src = "/static/img/docs/alerting/unified/contact-points-use-template-8-0.png" class = "docs-image--no-shadow" max-width = "550px" caption = "Default template" > }}
2021-06-07 19:01:21 +08:00
2022-01-12 04:16:04 +08:00
### Nested templates
You can embed templates within other templates.
For example, you can define a template fragment using the `define` keyword:
```
{{ define "mytemplate" }}
{{ len .Alerts.Firing }} firing. {{ len .Alerts.Resolved }} resolved.
{{ end }}
```
You can then embed custom templates within this fragment using the `template` keyword. For example:
```
Alert summary:
{{ template "mytemplate" . }}
```
You can use any of the following built-in template options to embed custom templates.
2023-10-03 20:49:27 +08:00
| Name | Notes |
| ----------------------- | ------------------------------------------------------------ |
| `default.title` | Displays high-level status information. |
| `default.message` | Provides a formatted summary of firing and resolved alerts. |
| `teams.default.message` | Similar to `default.message` , formatted for Microsoft Teams. |
2022-01-12 04:16:04 +08:00
2023-01-19 01:26:34 +08:00
### HTML in notification templates
2022-01-12 04:16:04 +08:00
2023-01-19 01:26:34 +08:00
HTML in alerting notification templates is escaped. We do not support rendering of HTML in the resulting notification.
2022-01-12 04:16:04 +08:00
Some notifiers support alternative methods of changing the look and feel of the resulting notification. For example, Grafana installs the base template for alerting emails to `<grafana-install-dir>/public/emails/ng_alert_notification.html` . You can edit this file to change the appearance of all alerting emails.