SilenceURL doesn't work in discord template

This is the only thing in my template and it doesn’t show the silence URL. In fact, it seems to break the message as it will show 111 but not 222 so it fails when trying to render the silence URL. Seems to be a bug in grafana. Can anyone verify or know a workaround?

{{ define "cosmos.alert3" }}
{{ .SilenceURL }}
{{ end }}

Hi! :wave: I’m afraid this template is incorrect. You have written {{ .SilenceURL }} which is correct, but you haven’t told the template which Silence URL it should use. Notifications can contain multiple alerts, and so there can be multiple Silence URLs. You probably want something like this:

{{- define "cosmos.alert3" -}}
{{ range .Alerts.Firing -}}
Labels: {{ .Labels }}
Silence: {{ .SilenceURL }}

{{ end }}
{{- end -}}

You can find more information on this here.

I would also recommend trying out the new template testing feature in Grafana 10 which should help! :slight_smile:

1 Like

That makes sense. Thank you so much. I’m new and still learning.