Grafana Templates only Showing <no value>

I’ve setup alerts, and they’re working when I’m using no template by leaving the message box empty.

However, after a long search I’ve found that you can pick which template is used, by adding the template to the message panel in a certain contact point.

So, I’ve created a Message Template, that is an exact copy of the default one, which looks like this:

{{ define "test_alert" }}
  [{{.Status}}] {{ .Labels.alertname }}

  {{ range .Labels.SortedPairs }}
    {{ .Name }}: {{ .Value }}
  {{ end }}

  {{ if gt (len .Annotations) 0 }}
  {{ 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 }}

Unfortunately, the messages that arrive in Slack, look like this:

[FIRING:1]  (Test VC test)
[<no value>] <no value>

When using no template, the message looks like this:

Value: [ metric='Name of cronjob 1' labels={job=Name of cronjob} value=77777], [ metric='Name of cronjob 2' labels={job=Name of cronjob} value=77777], [ metric='Name of cronjob 3' labels={job=Name of cronjob} value=77777], [ metric='Name of cronjob 4' labels={job=Name of cronjob} value=77777], 
- alertname = Test VC
- test = test

I would like to have the message look like this:

[ metric='Name of cronjob 1' value=77777], 
[ metric='Name of cronjob 2' value=77777], 
[ metric='Name of cronjob 3' value=77777], 
[ metric='Name of cronjob 4' value=77777], 
- alertname = Test VC
- test = test

My questions are:

  1. How can I see/know what variables I can use between the {{}}?
  2. Why are all these values showing as <no value>
  3. How can I split the Array of Values in the message?
  4. Is there some more documentation besides this, that I’m missing?

Can somebody maybe provide me with a working template, so I can see what I did wrong?

The issue was closed, so I’m back here trying to get this working again.

The suggestion by @melori.arellano was:

  1. define the alert template
  2. define the alert message - this one references the alert template created in step 1
  3. reference the alert message template in the message box in the slack contact point
  1. Where should this be created?
  2. I’ve Created a Message template under the Contact Point tab, is this what was meant? The contents of the message are described in the top ticket.
  3. I’ve referenced the alert message in the message box. This works, as I can see the alert (not) working.

Today it is actually my birthday, so it would be a great present if anybody could help me!


This might be one of the greatest tech forum replies i’ve ever seen, i joined the forum just to post this…

BTW, I’m having the same [no value] issue, some work, but some don’t, wondering if there has been a solution found…

No, all my Slack notifications look terrible now, upgrading Grafana was a bad decision, especially since the silences that were the reason for upgrading, aren’t really as useful as I hoped they would be. You can imagine it was the worst birthday of the year.

My issue was resolved by following this tutorial:

1 Like

So the {{ .Annotations }} in the contact points templates is just non-sense or what is that about? Have you figured it out?

Hi! :wave:

First of all, Happy Birthday! :birthday: I’m sorry I didn’t see this before, but a late Birthday present is better than none, right?

It looks like you might have be able to find the information you need, but just in case you didn’t figure it out, I suspect the issue in your original template is that {{ .Status }} and {{ .Labels }} are fields of an alert, but you forgot to range over the alerts with {{ range .Alerts }}. If you are ranging over the alerts before calling the test_alert template then the issue will be something else, but without seeing how you are using the template from your contact point it’s hard to tell.

To answer your questions:

  1. You can find this information in our all new and improved documentation here Customize notifications | Grafana documentation. Look for the Reference at the bottom of the page.

  2. <no value> will show up if whatever field you are trying to use does not exist at that place in the template. This is often the case when the data is not what you expected.

  3. This is called the ValueString, and I’m afraid it cannot be split. However, in recent versions of Grafana (9.3 and later) there is a new variable called $values that will let you use the values of each alert. You can find examples of this in the documentation I linked above.

  4. See 1.

I hope you had a nice birthday and figured out the issue with your templates!

Best regards

George, Alerting Squad @ Grafana Labs

1 Like