mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 23:32:32 +08:00

* builds out refactored setup topics * Automatically fix some relrefs with mv-manager Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Use refs for tutorials content which is outside of this repository Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Manually fix complicated relrefs Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * consolidates team sync and db encryption topics * Fix relrefs Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * updates setup index file * Convert TOML to YAML Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Add current alias for new alerting content Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Add current aliases to new setup-grafana and configure-security pages Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Update docs/sources/setup-grafana/configure-grafana/_index.md Co-authored-by: Torkel Ödegaard <torkel@grafana.com> * moves saml docs, updates order in TOC * Manually fix relrefs Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * added usage insights topics, adjusted weights * corrected relrefs * Fix relrefs broken in rebase Signed-off-by: Jack Baldry <jack.baldry@grafana.com> Co-authored-by: Jack Baldry <jack.baldry@grafana.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
69 lines
1.6 KiB
Markdown
69 lines
1.6 KiB
Markdown
---
|
|
aliases:
|
|
- /docs/grafana/latest/alerting/contact-points/message-templating/
|
|
- /docs/grafana/latest/alerting/contact-points/message-templating/example-template/
|
|
- /docs/grafana/latest/alerting/message-templating/
|
|
- /docs/grafana/latest/alerting/unified-alerting/message-templating/
|
|
keywords:
|
|
- grafana
|
|
- alerting
|
|
- guide
|
|
- contact point
|
|
- templating
|
|
title: Example message template
|
|
weight: 115
|
|
---
|
|
|
|
# Example of a custom template
|
|
|
|
Here's an example of how to use a custom template. You can also use the default template included in the setup.
|
|
|
|
Step 1: Configure a template to render a single alert.
|
|
|
|
```
|
|
{{ define "myalert" }}
|
|
[{{.Status}}] {{ .Labels.alertname }}
|
|
|
|
Labels:
|
|
{{ range .Labels.SortedPairs }}
|
|
{{ .Name }}: {{ .Value }}
|
|
{{ end }}
|
|
|
|
{{ if gt (len .Annotations) 0 }}
|
|
Annotations:
|
|
{{ range .Annotations.SortedPairs }}
|
|
{{ .Name }}: {{ .Value }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ if gt (len .SilenceURL ) 0 }}
|
|
Silence alert: {{ .SilenceURL }}
|
|
{{ end }}
|
|
{{ if gt (len .DashboardURL ) 0 }}
|
|
Go to dashboard: {{ .DashboardURL }}
|
|
{{ end }}
|
|
{{ end }}
|
|
```
|
|
|
|
Step 2: Configure a template to render entire notification message.
|
|
|
|
```
|
|
{{ define "mymessage" }}
|
|
{{ if gt (len .Alerts.Firing) 0 }}
|
|
{{ len .Alerts.Firing }} firing:
|
|
{{ range .Alerts.Firing }} {{ template "myalert" .}} {{ end }}
|
|
{{ end }}
|
|
{{ if gt (len .Alerts.Resolved) 0 }}
|
|
{{ len .Alerts.Resolved }} resolved:
|
|
{{ range .Alerts.Resolved }} {{ template "myalert" .}} {{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
```
|
|
|
|
Step 3: Add `mymessage` in the notification message field.
|
|
|
|
```
|
|
Alert summary:
|
|
{{ template "mymessage" . }}
|
|
```
|