@ -63,6 +63,7 @@ In Grafana, you have various options to template your alert notification message
- Labels are used to differentiate an alert instance from all other alert instances.
- Labels are used to differentiate an alert instance from all other alert instances.
- Template labels to add an additional label based on a query value, or when the labels from the query are incomplete or not descriptive enough.
- Template labels to add an additional label based on a query value, or when the labels from the query are incomplete or not descriptive enough.
- Avoid displaying query values in labels as this can create numerous alert instances—use annotations instead.
1. [Notification templates ](#template-notifications )
1. [Notification templates ](#template-notifications )
- Notification templates are used by contact points for consistent messaging in notification titles and descriptions.
- Notification templates are used by contact points for consistent messaging in notification titles and descriptions.
@ -124,18 +125,16 @@ You can also template labels based on query results. This is helpful if the labe
- Add a new label to change how alerts are identified and grouped into different alert groups.
- Add a new label to change how alerts are identified and grouped into different alert groups.
- Add a new label used by notification policies or silences to manage how the alert is handled.
- Add a new label used by notification policies or silences to manage how the alert is handled.
Here’s an example of templating a `severity` label based on the query value :
Here’s an example of templating a new `env` label based on the value of a query label :
```go
```go
{{ if (gt $values.A.Value 90.0) -}}
{{- if eq $labels.instance "prod-server-1" -}}
critical
production
{{ else if (gt $values.A.Value 80.0) -}}
{{- else if eq $labels.instance "staging-server-1" -}}
high
staging
{{ else if (gt $values.A.Value 60.0) -}}
{{- else -}}
medium
development
{{ else -}}
{{- end -}}
low
{{- end }}
```
```
For more details on how to template labels, refer to [Template annotations and labels ](ref:templating-labels-annotations ).
For more details on how to template labels, refer to [Template annotations and labels ](ref:templating-labels-annotations ).