How To Use Alert Message Templates in Grafana

Unless the log content appears in the Preview Alerts box, then I do not know how you can get it into your Slack template.

Do I have to do something to make it appear there?

Have you created an alert that is currently working? If yes, what do you see when you click on the Preview Alerts button?

I only see this

I just have that rare value

Click Edit (upper right in your screenshot), then scroll down to the Preview Alerts button and click it, then paste the output here.

i only get this

is it because of the type of query?
or how could I have more information about my log?

I think you will have to go back and redo your query so that it produces the info you want in the Info section of your Preview Alerts box.

There may be a better way to do this, but grabbing log data is not my forte.

Should these same concepts apply to a custom subject in Contact Points? I’m trying to use

{{ $values.A.Labels }} in the subject but it keeps sending emails with a blank subject and the following error message in the logs:
level=warn msg="failed to template email message" err="template: :1: undefined variable \"$values\""

Welcome @shoffman to the forum.

I am not sure if the templating applies to a custom subject in the Contact Point. Can you inspect your results when you click Preview alerts and then use the following? (something-here should be apparent when you click Preview alerts)

 {{ $values.A.Labels.something-here }}

I did
Test {{ $values.A.Labels.node_name }}
which renders correctly in the body of the email itself and the preview alerts but get the same error in the logs and still a blank subject line. the only things I’ve been able to use in the subject are the Template Data vars but was hoping to use the Alert vars to make a more meaningful Subject. I’ll poke around it a bit and open a new thread so as not to ad noise here.

1 Like

Hi @grant2, is there any update on this? I’m still getting no message on Slack…

@melori.arellano @grant2 I was finally able to resolve my screenshot upload issue so attaching here if that helps.

Email Contact Point Configuration

Something strange is happening that I don’t understand, when I use a template I don’t get the alert data, but when I don’t use a template I do get the values

this is the template for slack

this is the text body

what would be wrong?, if you could help me please

1 Like

Hello there, I hope you are doing fine. I’ve been following your methods, however I am not able to get certain values fetched.

Here’s a little context for you.

Problem: Receiving alerts on google hangouts, however certain values are empty.


Alert notification (Google Groups Chat)

As you can see in alert notification received, I am not getting instance and job labels, however I do get those in the value array. What am I doing wrong here?


@milinpatel13298 the Message field should have a reference to the message template you created. If you refer back to the solution for this post, there’s an example of how to do that. The example is for slack, but the syntax will be the same for email.

The default alert template will print Annotations, so that is why you’re seeing them without your customized alert template.

From the screenshot, it looks like you created the “myalert” template which formats a single alert, but not the “mymessage” template which will iterate through and print “my alert”. Can you try creating the “mymessage” template from the solution post and referencing it in your slack contact point?

Hi @melori.arellano i have gone through this doc for my alert it is unfortunate that im not able to get result from my alert can you help me out plz.

below i have provided details.

Here is my query preview

Screenshot from 2022-11-16 17-39-01

And here is the result im getting on slack
Screenshot from 2022-11-16 17-42-49

can you plz help.

And here is the test result from slack.

Value: [ var='B0' metric='value' labels={labels.client_id=119049, labels.job_id=483374} value=1 ], [ var='B1' metric='value' labels={labels.client_id=164840, labels.job_id=1779411} value=1 ], [ var='B2' metric='value' labels={labels.client_id=154959, labels.job_id=1779374} value=1 ], [ var='B3' metric='value' labels={labels.client_id=147525, labels.job_id=1779369} value=1 ], [ var='B4' metric='value' labels={labels.client_id=154959, labels.job_id=1779347} value=1 ], [ var='B5' metric='value' labels={labels.client_id=170033, labels.job_id=1779262} value=1 ], [ var='B6' metric='value' labels={labels.client_id=170033, labels.job_id=1779205} value=1 ], [ var='B7' metric='value' labels={labels.client_id=154959, labels.job_id=1779202} value=1 ], [ var='B8' metric='value' labels={labels.client_id=170033, labels.job_id=1779195} value=1 ], [ var='B9' metric='value' labels={labels.client_id=170033, labels.job_id=1779190} value=1 ], [ var='B10' metric='value' labels={labels.client_id=170033, labels.job_id=1779188} value=1 ], [ var='B11' metric='value' labels={labels.client_id=165276, labels.job_id=1779165} value=1 ], [ var='B12' metric='value' labels={labels.client_id=170033, labels.job_id=1779155} value=1 ], [ var='B13' metric='value' labels={labels.client_id=67722, labels.job_id=1532293} value=1 ], [ var='B14' metric='value' labels={labels.client_id=67722, labels.job_id=1532292} value=1 ], [ var='B15' metric='value' labels={labels.client_id=67135, labels.job_id=1532209} value=1 ], [ var='B16' metric='value' labels={labels.client_id=87740, labels.job_id=1232704} value=1 ], [ var='B17' metric='value' labels={labels.client_id=111156, labels.job_id=1232666} value=1 ], [ var='B18' metric='value' labels={labels.client_id=79632, labels.job_id=1141244} value=1 ]
- alertname = TrendHarvestAlert
- severity = warning
- AlertValues = {{ with $values }}
{{ range $k, $v := . }}
  Location: {{ index $values.B0.Labels “labels.client_id” }}
  Alerting value: {{ $v }}
{{ end }}
{{ end }}

i just want to get client_it and job_id with value on alert

Do I understand that all of the above applies only to Slack? Props to melori.arellano for taking the time, and did a good job of documenting the templating for Slack. In the forums. But this 79 posts five-month back-and-forth topic needs to be consolidated and put into documentation.

What about the sixteen (16) OTHER Contact Point types that AM supposedly supports? Where is the documentation for those, Grafana? And why do 16 different CP’s have different ways of templating? :face_with_raised_eyebrow: You are asking people who need to send to multiple CPs to learn different syntax for each one.

If Grafana does not document HOW to configure for the other Contact Points, including which code to put into which Alert field or Template field, it seems to me that it only theoretically supports them. In practical terms, Grafana does not, in truth, support them, and is padding the numbers of supported platforms, and wasting a lot of users time.