Issue with title template for MS Teams

Hi,

I’ve been trying to learn how to use templates in my alerting.
I’m using Grafana v10.0.3 (eb8dd72637), and sending alerts to MS Teams.

I’m just trying to do some really basic things at first, but already struggling with my understanding. I’m guessing there is a really silly mistake, but I can’t find it.

I’ve defined some templates, including one called “myTitle”:

For my contact point I’ve included these:
image

Now I will do a test send, using the following (note I’m only testing the title here)

I end up with a blank message in Teams
image

If I remove my title template, leaving the field blank, thus invoking the default template I will get a message in Teams when doing test send
image

I hope someone will see the mistake I’m surely making. Thanks!

Hi!

The mistake is that in myTitle you are not iterating over the list of alerts. You have done this in myMessage though.

In myTitle you are trying to print the alertTitle annotation, but you haven’t said which alert it should use. The first alert, the second alert, all alerts? You can either use a range like you have done in myMessage or use the index function to access the first alert, for example.

2 Likes

Yes! Thank you! I knew there was some simple misunderstanding!

For anyone coming across this post, my solution was to index the first alert:

{{ define "myTitle" }}
  {{ (index .Alerts 0).Annotations.alertTitle }}
{{ end }}

Thank you @georgerobinson