# Grafana 8 Alerting Value Template

**URL:** <https://community.grafana.com/t/grafana-8-alerting-value-template/53141>\
**Category:** Configuration\
**Tags:** unified-alerting, templating, alert-templating\
**Created:** [September 10, 2021, 11:54am UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141 "2021-09-10T11:54:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![masterblaster](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@masterblaster](https://community.grafana.com/u/masterblaster)\
**Post date:** [September 10, 2021, 11:54am UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/1 "2021-09-10T11:54:15Z")

</div>

Hey Guys,

We did some testing with the ngalerting.  
Setup:  
Grafana 8.1.2  
Datasource is elastic.

I have some Questions now:

1. In the alert message, i want to have the url to the dasboard as HTML. I tried the following:

> {{ define “alert” }}  
> {{ range .Alerts.Firing }}  
> [New Alert]  
> {{ range .Labels.SortedPairs }}  
> {{ .Name | title }}: {{ .Value | title }}  
> {{ end }}  
> Silence alert: {{ .SilenceURL | safeHtml }}
> 
> Dashboard: {{ .DashboardURL | safeHtml }}  
> {{ range .Annotations.SortedPairs }}  
> {{ .Name }}: {{ .Value }}  
> {{ end }}  
> {{ end }}  
> {{ end }}

Did i missed something?

1. I want to have a nice and clean alert. But i can not format the value somehow:  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/6/6/66b95dc84d87dc05437c4825789fb0e8277a8e03.png)  
I just want the Lable and the Value. Not the hole string.  
How can i format that?

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [September 14, 2021, 9:52pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/2 "2021-09-14T21:52:06Z")

</div>

Hi @masterblaster

What kind of alerting rule did you create: a classic condition or a multidimensional rule? I believe message template only works with multi-dimensional rules. Check out this link for an explanation of the two and a brief intro to alert templating:

> **[Create Grafana managed alert rule](https://grafana.com/docs/grafana/latest/alerting/unified-alerting/alerting-rules/create-grafana-managed-rule/#query)**
>
> Create Grafana managed alert rule

---

<div class="post-metadata">

**Author:** ![masterblaster](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@masterblaster](https://community.grafana.com/u/masterblaster)\
**Post date:** [September 15, 2021, 6:08am UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/3 "2021-09-15T06:08:20Z")

</div>

Hey @anon70503803,

I think i createt a multi-dimensional rule. Because the template is working, just not in that way i wanted.

 ![alert](https://us1.discourse-cdn.com/grafana/original/3X/f/b/fb0e73f2ffcc196d4d4565e60db8e199d9567fe0.png)

 ![tempolate](https://us1.discourse-cdn.com/grafana/original/3X/8/2/82a150ff0278b89f05706eef883eab065401915c.png)

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [September 15, 2021, 10:22pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/4 "2021-09-15T22:22:39Z")

</div>

According to your screenshot this is using a classic condition rule:

 ![CleanShot 2021-09-15 at 12.21.24@2x](https://us1.discourse-cdn.com/grafana/original/3X/0/4/043ab28aa54b031a46f5d435ef0436685e8d1748.jpeg)

Maybe try reformulating the alert to use reduce or something and see how that impacts your templating?

---

<div class="post-metadata">

**Author:** ![janczewskimarcin](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@janczewskimarcin](https://community.grafana.com/u/janczewskimarcin)\
**Post date:** [September 28, 2021, 4:59pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/5 "2021-09-28T16:59:21Z")

</div>

hello, did you managed to solve your problem?

I have the pretty same issue.  
I was able to configure multi rule:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/6/2/62f25956eac45437b3a364a17c628e34cc94f9ac.png)  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/6/2/62d2c6f8dfb62939db4474bf5b66784f96c1c80e.png)

but having a problem with value format.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/c/c/cca3a5ebe85af87ec1e8441b19730a853d474c5f.png)

{{ define “message-sst” }}  
{{ range .Alerts.Firing }}  
{{ range .Labels.SortedPairs}} {{ .Name}} : {{ .Value }}, {{ end }}  
{{ end }}  
{{ end }}

I need to extract only one exact label name and value for every entity in the new line or at least after the comma…

how to do it? I suppose I should use one of these:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/c/b/cb19a3829b62b4018cc151c190909ed928d69dfb.png)

[Template data | Grafana Labs](https://grafana.com/docs/grafana/v8.0/alerting/unified-alerting/message-templating/template-data/)

---

<div class="post-metadata">

**Author:** ![masterblaster](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@masterblaster](https://community.grafana.com/u/masterblaster)\
**Post date:** [September 29, 2021, 9:52am UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/6 "2021-09-29T09:52:49Z")

</div>

Hey, Not yet ☹

I tried today with the math expression an not the classic.  
But there i got the follwing error:  
invalid format of evaluation results for the alert definition : frame cannot uniquely be identified by its labels: has duplicate results with labels {}

No idea how to fix this.

---

<div class="post-metadata">

**Author:** ![janczewskimarcin](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@janczewskimarcin](https://community.grafana.com/u/janczewskimarcin)\
**Post date:** [September 29, 2021, 3:57pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/7 "2021-09-29T15:57:45Z")

</div>

hej,

I managed to work around the problem by using a variable in the configuration for the alert.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/8/187e9ef1d7dfe341c28c426b3875d195f2dd1ccd.png)

then in message template

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/e/5/e53a8f14a70f80ed86ef4dd721a9e7d3d75571b4.png)

Right now have other issue 😃  
How to disable pending state or how to work around it to be able not to wait for another 12h to execute check for pending condition  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/6/46270b6237708dacf06126cc8a471ded83ee1e78.png)

---

<div class="post-metadata">

**Author:** ![masterblaster](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@masterblaster](https://community.grafana.com/u/masterblaster)\
**Post date:** [October 1, 2021, 9:32am UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/8 "2021-10-01T09:32:49Z")

</div>

Hey,

So it worked with the reduce in between, but there i miss the last value, because we cannot work with average.  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/0/0/00cffffa949bb4613f22ce827370705e4ae618e5.png)

The problem ist that my info is in a single row and not in different rows like yours.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/3/43628d1b438f1054c30eb8ec4f2ece44005b8bf3.png)

I put that in on our end: ![image](https://us1.discourse-cdn.com/grafana/original/3X/5/3/53a51752c64c0f4b8a86efc55fa969065f6d0e5b.png)

So its just two minutes till the alarm gets fired in my understanding.

---

<div class="post-metadata">

**Author:** ![janczewskimarcin](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@janczewskimarcin](https://community.grafana.com/u/janczewskimarcin)\
**Post date:** [October 4, 2021, 4:36pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/9 "2021-10-04T16:36:20Z")

</div>

1. use “SUM” it will do the same as “Last” if you set a proper time rande for your query.
2. depend on your Garafan version set “evaluate every” on the 30s if don’t you will not receive a notification when the alert starts to firing. (its a bug that will be fixed in 8.1.7)
3. you will not able to set pending on zero. there should be such an option …
4. it doesnt matter how many tag’s you will have at the end. One or more …

---

<div class="post-metadata">

**Author:** ![ged](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/ged/32/1049_2.png) [@ged](https://community.grafana.com/u/ged)\
**Post date:** [February 21, 2022, 4:17pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/10 "2022-02-21T16:17:51Z")

</div>

Hi guys,  
Using Grafana 8.3.0 with Prometheus datasource.  
I’m testing local disk usage alert having it configured as shown below (using query, math expression and reduce expression):

 ![alert_conf](https://us1.discourse-cdn.com/grafana/original/3X/0/5/0511f80ef7fcc944da177887154b96264cffe4d9.jpeg)

Alert is sent via email, and what I receive in email’s body is:

 ![alert_message](https://us1.discourse-cdn.com/grafana/original/3X/e/b/ebe19b3427d2203ab59814f0ec670e969cff78ad.jpeg)

And here is the question:  
In **Value** section I can see **value=1** which I believe is result of expression **$Local\_disk\_usage \> 80** however exact value of disk usage in this case is 84.  
Is it possible to extract this 84 and show in message body with message template ?

Thank you in advance !  
Ged

---

<div class="post-metadata">

**Author:** ![grimzly](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@grimzly](https://community.grafana.com/u/grimzly)\
**Post date:** [June 7, 2022, 2:16pm UTC](https://community.grafana.com/t/grafana-8-alerting-value-template/53141/11 "2022-06-07T14:16:27Z")

</div>

This is the query setup I use

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/9/4/94005e34b5848dc0486dc71b77a5f136505e1889.png)

Then for ‘Alert Detail’ I use the following in which you’ll have to use you’ll have to translate to your own label names:

{{ $labels.exported\_instance }} on {{ $labels.instance }} ({{ $labels.job }}) disk usage at {{ $values.top\_value.Value | printf “%.2f”}}%
