this is awesome! isn’t it odd that templates are under contact points?
Hi, thanks for your detail instructions. those helps me a lot.
However, I would like to send the alert to webhook which did not have any option to pairing with custom message/template that we already created. I have seeking many threads or in config file but still did not get any idea to use custom template into webhook alert (not like optional slack settings).
Have you try with webhook? thanks in advance
@melori.arellano do you know what tweaks are needed when not using a classic query as the current example returns two results with a reduce and use C for results alert:
I have tried $values.C in the alert in place of $values but the results in the email just ignoring the options:
Thanks
@ardianre these instructions are meant to be for slack. The webhook has a different format the json body sent uses the valueString
property for the metric values returned by the alert: Webhook notifier | Grafana documentation
@mrdibbley Can you share an example of the reduce condition? I tried an example that uses input C as the alert condition and it still worked for me:
When I preview the alert, the values are in var=B
even though it references the query result C:
My alert returns only the results of expression B (based on query C):
@mrdibbley thank you for sharing this! Can you also show me what shows in the box when you click Preview Alerts button? That will show me what the values look like.
@mrdibbley I’m just getting back from some time away. Just to confirm - is this working for you now using $values.B
?
Another interesting use case I want to capture in this thread. What to do about metric names that have a dot in the label name!
The template variables for values are now described here: How to template annotations and labels | Grafana documentation
If you have a label like netflow.ipv4_dst_addr
with a value of 192.168.1.1
, you might find that your alert template just shows the raw template (which is what happens if there’s an error in the evaluation).
If you’re using a classic condition, here’s an example of using the go index function:
{{ index $values.B0.Labels “netflow.ipv4_dst_addr” }}
if your alert has two or more conditions or an expression, then you can use the $labels variable:
{{ index $labels “netflow.ipv4_dst_addr” }}
Hi melori,
I have this exact issue and i have been stranded for days now.
This is my alert preview
Can you please assist with how the template will be?
@sijuade644 What values are you trying to display in your alert?
You should be able to do something like:
{{ index $values.B0.Labels “host.hostname” }}
Thanks for this post.
It was very useful for me to recover the data.
On the other hand, I can’t remove the Value part.
do you have to create your own message template?
Hi @melori.arellano, I am trying to create a similar template as @sijuade644 but I’m not receiving any data on my Slack channel. Could you please help me? This is my basic configuration to try to make it work, there must be something wrong in one of the steps:
This is my current alert and the annotation I’m using
The basic template
And the basic text body:
{{ template “myalert” .}}
I’m using a classic condition and it’s firing, but my result shows nothing in Slack.
I appreciate the support. Best regards.
I deleted the last dot in the text body and no I’m receiving the message
< no value >
Hey @melori.arellano,
Is there any way to add variables in custom Labels for Azure data source in Alerting.
I am trying to add resourcename as a variable. Could you please help me?
@jlu1 the dot is needed to provide the context.
Are you getting any notifications to slack, even a blank one?
Check out my post at the top of this thread, if you see your label shown in the alert preview output, then you can use it in the alert by following the steps there.
Yes, I receive a blank one if I use the dot.
But I couldn’t find a way of retrieving any data.