docs/sources/alerting/configure-notifications/template-notifications/_index.md
You can use notification templates to change the title, message, and format of notifications.
Grafana provides a default template for notification titles (default.title) and one default template for notification messages (default.message). Both templates display common alert details.
You can also create a notification template to customize the content and format of your notification messages. For example:
However, there are limitations. You cannot:
Here's an example that displays the summary and description annotations for each alert in the notification:
{{ define "custom.alerts" -}}
{{ len .Alerts }} alert(s)
{{ range .Alerts -}}
{{ template "alert.summary_and_description" . -}}
{{ end -}}
{{ end -}}
{{ define "alert.summary_and_description" }}
Summary: {{.Annotations.summary}}
Status: {{ .Status }}
Description: {{.Annotations.description}}
{{ end -}}
The notification message would look like this:
2 alert(s)
Summary: The database server db1 has exceeded 75% of available disk space.
Status: firing
Description: This alert fires when a database server is at risk of running out of disk space. You should take measures to increase the maximum available disk space as soon as possible to avoid possible corruption.
Summary: The web server web1 has been responding to 5% of HTTP requests with 5xx errors for the last 5 minutes.
Status: resolved
Description: This alert fires when a web server responds with more 5xx errors than is expected. This could be an issue with the web server or a backend service.
{{< admonition type="note" >}} Avoid adding extra information about alert instances in notification templates, as this information will only be visible in the notification message.
Instead, you should use annotations or labels to add information directly to the alert, ensuring it's also visible in the alert state and alert history within Grafana. You can then print the new alert annotation or label in notification templates. {{< /admonition >}}
Notification templates are not tied to specific contact point integrations, such as email or Slack, and the same template can be shared across multiple contact points.
The notification template is assigned to the contact point to determine the notification message sent to contact point integrations.
{{< figure src="/media/docs/alerting/how-notification-templates-works.png" max-width="1200px" caption="A flow of the alert notification process, from querying the alert rule to sending the alert notification message." >}}
By default, Grafana provides default templates, such as {{define "default.title"}} and {{define "default.message"}}, to format notification messages.
Grafana Cloud users can use built-in AI tool to generate templates in the appropriate alerting template language for you.
To use AI to create your template, follow these steps:
Go to Alerting -> Contact points.
Click the Notification Templates tab then, click the + New notification template button.
Name your template.
In the Template group section, click the Generate with AI button.
Supply the AI tool with a prompt or select from one of the example prompts and edit that if necessary.
Click Save.
For further details on how to write notification templates, refer to:
{{< admonition type="tip" >}} For a practical example of templating, refer to our Getting Started with Templating tutorial. {{< /admonition >}}