Custom email templates not keeping line breaks from annotations

Hello,

I have tried to create my own email template for alerting on particular alert rules but the email templates never seem to come out the way I want them to.

I created an annotation from an alert which populates the information that I want displayed in an email:

From there, I have a custom template created which pulls the annotation called “AlertValues” into a template:

For the purposes of testing this, I populated the test contact point with test data:
Practice Name: Practice1

  • Practice GUID: 00000000-0000-0000-0000-000000000000
  • Practice ID: 111111
  • IC GUID: 00000000-0000-0000-0000-000000000000
  • Queue Length: 10

Practice Name: Practice2

  • Practice GUID: 00000000-0000-0000-0000-000000000000
  • Practice ID: 222222
  • IC GUID: 00000000-0000-0000-0000-000000000000
  • Queue Length: 10

Practice Name: Practice3

  • Practice GUID: 00000000-0000-0000-0000-000000000000
  • Practice ID: 333333
  • IC GUID: 00000000-0000-0000-0000-000000000000
  • Queue Length: 10

Practice Name: Practice4

  • Practice GUID: 00000000-0000-0000-0000-000000000000
  • Practice ID: 4444444
  • IC GUID: 00000000-0000-0000-0000-000000000000
  • Queue Length: 10

Which results in a run on sentence email alert that does not provide the values I require in an easy to digest format:
AlertValues: Practice Name: Practice1 - Practice GUID: 00000000-0000-0000-0000-000000000000 - Practice ID: 111111 - IC GUID: 00000000-0000-0000-0000-000000000000 - Queue Length: 10 Practice Name: Practice2 - Practice GUID: 00000000-0000-0000-0000-000000000000 - Practice ID: 222222 - IC GUID: 00000000-0000-0000-0000-000000000000 - Queue Length: 10 Practice Name: Practice3 - Practice GUID: 00000000-0000-0000-0000-000000000000 - Practice ID: 333333 - IC GUID: 00000000-0000-0000-0000-000000000000 - Queue Length: 10 Practice Name: Practice4 - Practice GUID: 00000000-0000-0000-0000-000000000000 - Practice ID: 4444444 - IC GUID: 00000000-0000-0000-0000-000000000000 - Queue Length: 10

Any help to try and properly format this data into an email alert would be greatly appreciated. I am not looking to implement this in Slack or Teams.

I should clarify this is for Grafana version 9.2

I am still trying to master this annotation-in-alerting topic, but maybe try this?

In your Template, try replacing the 2nd line {{ .CommonAnnotations.AlertValues }} with

{{ .Annotations.AlertValues }}

and report back here what you see.

I had accidently copied the screenshot from a test scenario I was trying to run, the current configuration indeed has:
{{ .Annotations.AlertValues }}

Configured for the 2nd line and produces the output where the new line characters are stripped out. The CommonAnnotations value seemed to produce the same results from my testing.