Alert templates question? .ValueString not working?

Running 9.0.2 and experimenting with alerting templates with the following simple example:

{{ define "test" }}
{{ .ValueString }}
{{ end }}

in the email contact point message i have:

{{ template "test" .}}

when firing an alert or even the test alert i get just an empty alert:

does valuestring work like this? as i need to trim and extract sections eventually.

heres a sample from a non templated alert showing the string i need :

Value: [ var=‘B0’ metric=‘RMF’ labels={description=% eappl (total) by job, label=DBB, resource=ABC,*,PROCESSOR} value=156.2 ]

I wold like to display

label=DBB
resource=ABC,*,PROCESSOR
value=156.2

maybe a timestamp if possible?

Thanks

@mrdibbley welcome to the :grafana: community!

I created a detailed example for this in a response to this post, I hope it’s helpful!

Wow that is awesome and a lot easier. Can you still use reReplaceAll and regex to tweak the labels in AlertValues ?

I tried a simple:

{{ with .Status }} reReplaceAll “.*” “fred” . }} {{ end }}

but it just printed Alert summary:

1 firing: reReplaceAll “.*” “fred” . }}

treating it a text

Thanks

HI Melori,
seen your post i am alos looking for the same solution can u please help me with same

Value: [ var=‘B0’ metric=‘RMF’ labels={description=% eappl (total) by job, label=DBB, resource=ABC,*,PROCESSOR} value=156.2 ]

I wold like to display

label=DBB
resource=ABC,*,PROCESSOR
value=156.2

@mrdibbley yes, these should still work! There’s an example here:

Hey @melori.arellano ,

I am using the Grafana Oncall template and in that getting value string in
“valueString”: “[ var=‘B0’ metric=‘Deploy-QA-MAIN-1 (GH)’ labels={} value=1 ]”,
this way ,
As grafana Oncall using the Jinja 2 template can u please help me to print
this value in list format Like below
metric=‘Deploy-QA-MAIN-1 (GH)’
value=1

@maheshmane since this is for Grafana OnCall - I did a little research for you and wondered if this post in our oncall github repo was also yours: Grafana Oncall templates new helper filter regex_replace() · Issue #226 · grafana/oncall · GitHub

That github repository is where the docs direct community members looking for help with on-call templates. If you have a cloud subscription, support may also be able to help you with this one.

Hi Melorii,

Greetings,

I am trying to upgrade grafana from v8 to v9 and I have done below things:

I have upgraded from grafana v8 to v9,
Added data source: Azure monitor,
Added Notifying contact points, Created dashboard with Azure Resources(Virtual Machines),

however, after adding dashboards and configuring alerts, I am getting “metric name”, “threshold value” of thatresource but, not getting the “resourcename” while sending the alerts on Notifying contact point

Can anyone help me please?

@proharshraj10 do you still need help with this?

You might need to update your alert message template to include those labels. Check out my answer in this post to see an example.

Pay special attention to the step where you can use the preview alerts button when you’re configuring the alert. It will show you all of the available labels that can be referenced in your alert.

Hi Melori,

Thanks for the reply

As you mentioned, I have tried it, kindly check it below:

Description:
{{ define “myalert” }}
Alert: {{ .Labels.variable }} on {{ .Labels.location }} is above threshold of {{ .Labels.threshold }}. {{ .Annotations.Description }}For more detail, {{ .PanelURL }}.
{{ end }}

Description:
Location: {{ $values.A.Labels.location }}
Variable: {{ $values.A.Labels.variable }} {{ $values.A.Value }}

Even after configuring the template, I am not getting the “resourcename” of the Azure resources
in Unified alerting of grafana version 9+
Kindly help me

Thanks,
Harsh

@proharshraj10 you’ll want to replace the label names in my example with your own. For example, if you have a label called resourcename you would use something like this in your annotation:

{{ $values.A.Labels.resourcename }}

If you can provide a screenshots to your post it might help the community to see what steps you’ve followed and give more specific advice. Some of these are in different parts of the alert UI, you can refer back to my other post for help finding them.

  • the output of the preview alert button on your alert configuration page
  • the annotations section of your alert
  • your alert template
  • your message template

Hi Melori,

Sharing the screenshots with you for your reference, kindly find it in an attachment and please guide me if I am missing anything,

Can I ask your slack channel details if any? Kindly let me know accordingly,

Thanks,
Harsh

Alert summary.png

Shouldn’t this be called myalerts (not AlertValues)? Maybe try it and post back here.