Templating Alerting message title

Hi,
I am trying to customize the message the Alertmanager is sending to opsgenie.
I am using:
Grafana 9.1
Alertmanager Grafana
I noticed that the message can be templated without problems, the full template data are available (i.e .Annotations, .Labels etc). On the contrary the title is impossible to template, it seems there is something wrong in the data visibility.

level=warn msg="failed to template Opsgenie message" err="template: :1:14: executing \"\" at <.Annotations.summary>: can't evaluate field Annotations in type *channels.ExtendedData"

has somebody some hints? probably a bug?

@melori.arellano have you come across an issue like this?

1 Like

Alert templating for the OpsGenie title was just introduced in 9.0.2 with Optional custom title and description for OpsGenie by santihernandezc · Pull Request #50131 · grafana/grafana · GitHub so it’s possible that there’s a bug.

@joel can you share a screenshot of the annotation your template refers to and the title you’ve created in your OpsGenie contact point?

1 Like

I am having a very simialr issue when sending alerts to Discord:

logger=alerting.notifier.discord t=2023-02-27T20:14:15.846740432Z level=warn msg="failed to template Discord notification title" error="template: main:3:30: executing \"main\" at <.Annotations.summary>: can't evaluate field Annotations in type *channels.ExtendedData"

This is what the contact point template looks like:

{{ define "main" }}
  [{{.Status| toUpper}}] {{ .CommonLabels.alertname }}
  Annotations: {{ .Annotations.Summary }}
{{ end }}

(I’ve also tried with a lower case ‘s’ for ‘summary’)

Is this also not implemented in discord? Grafana does send information related to the instances (found in the queries themselves), but only when I use the default template (nothing filled in). The problem with that is that I’ve no idea what the go template actually looks like, so I don’t know how to access that label.

I’m using Grafana 9.3.6

Hi! The template is incorrect as you need to first range over the alerts first. We have some examples of this in our new and improved documentation Customize notifications | Grafana documentation.

1 Like

Thanks, I realised that basically the moment you answered, funnily enough :slight_smile: