Files
Pepe Cano 813632dff1 Alerting Docs: Update Alert rule and Notification Templating (#94069)
* Update links to the new location of the Templates intro page

* Set alert rule template structure

* Update the `Template notifications` structure/sidebar

* Move examples to examples pages

* Update menu titles and URL paths

* WIP reference

* added intro to examples.md

* reference page section intros

* examples title

* Template

* Continue Alert Template Reference

* example sections

* Almost finish with Reference page

* weight pages

* WIP - template variables Intro

* Edits Alert rule templates + Differences with notification templates

* examples-draft-2

* how to map annotations to notif templates

* examples v2

* moved example

* Continue Template annotations and labels

* Preview annotation templates

* Complete `Template annotations and labels`

* Update `Differences with notification templates`

* Polish a bit `Differences with notification tempaltes`

* added logic examples to `Examples`

* Finish sharing Template language

* Minor: set `anchor` link

* Minor edit

* Minor edit

* Minor changes

* Template language changes

* Document missing functions for alert rule templates

* 'Examples' v3

* `Examples` v3.1

* `Examples` v3.2

* added context/intro to `Examples`

* added a how to section to `Examples`

* moved legacy info in `Examples`

* added examples, sections in `Examples`

* formatting

* examples v5

* examples v5.1

* Complete update to `Notification template reference`

* Update `$values` description

* moved steps to `index`

* fixed urls

* removed section in `examples`

* added refs

* fixed urls

* refs fix

* blended the use case into the explanation

* Notification template reference: Minor readibility changes

* Edit `$value` in Alert rule template reference

* Edit `Manage notification templates

* links to ref and lang pages

* Minor copy changes

* Edit Template annotation overview + Prepare Template notifications overview

* `Select` vs `Choose`

* Template Overview

* Fix `heading` does not match `title`

* examples v6

* examples v6.1

* Fix spell errors

* Run `prettier --write` to fix md format errors

* examples v7

* examples v7.1

* examples v7.2

* examples v7.4

* examples v7.5

* examples v7.6

* all pretty, no pity

* Update alert rule examples

* Complete `Labels and annotations template examples`

* Minor changes

* Use `.` notation instead of `index` in examples

* rename `extendeddata` to `notificationdata`

* Complete Notification examples

* minor changes

* Set `go` language when displaying template examples

* Revert "minor changes"

This reverts commit f647c55c8718a4b5c5ab51b3ef88ef0605de3c84.

* Update example and admonition for consistency

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/shared/alerts/template-language.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/shared/alerts/template-language.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/language.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/_index.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/examples.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/examples.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/examples.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/alerting-rules/templates/examples.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/examples.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Update docs/sources/alerting/configure-notifications/template-notifications/manage-notification-templates.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* use `add` instead of `enrich`

* fix prettier content errors

* minor copy change

* Specify which Alert properties are exclusive to Grafana-managed alerts

* Use `Monitor` instead of `Meta monitoring`

* Be more detailed about notifation template limitations

---------

Co-authored-by: tonypowa <tonypowa@gmail.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
2024-10-23 12:43:28 +02:00

5.5 KiB

aliases canonical description keywords labels title weight refs
../manage-notifications/template-notifications/
https://grafana.com/docs/grafana/latest/alerting/configure-notifications/template-notifications/ Customize your notifications using notification templates
grafana
alerting
notifications
templates
products
cloud
enterprise
oss
Template notifications 430
template-annotations-and-labels manage-notification-templates reference examples
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/alerting-rules/templates/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/templates/
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/configure-notifications/template-notifications/manage-notification-templates/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/configure-notifications/template-notifications/manage-notification-templates/
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/configure-notifications/template-notifications/reference/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/configure-notifications/template-notifications/reference/
pattern destination
/docs/grafana/ /docs/grafana/<GRAFANA_VERSION>/alerting/configure-notifications/template-notifications/examples/
pattern destination
/docs/grafana-cloud/ /docs/grafana-cloud/alerting-and-irm/alerting/configure-notifications/template-notifications/examples/

Template notifications

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:

  • Personalize the subject of an email or the title of a message.
  • Modify text within notifications, like selecting or omitting certain labels, annotations, and links.
  • Format text with bold and italic styles, and add or remove line breaks.

However, there are limitations. You cannot:

  • Modify Visual Appearance: Add HTML or CSS to email notifications for visual changes. Alter the design of notifications in messaging services like Slack or Microsoft Teams, such as adding custom blocks or adaptive cards.
  • Manage Media and Data: Customize the data structure or format passed to the templates, like adding new JSON fields or sending XML data for webhooks. Modify HTTP headers in webhooks beyond those defined in the configuration, or adjust the number, size, or placement of images.

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 %}}

Select a notification template for a contact point

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 default.title and default.message, to format notification messages.

More information

For further details on how to write notification templates, refer to: