Can you create hyperlink-like behavior in Slack alert Subject?

In my Contact Point, I have the following for the alert subject:

{{ define "alert_subject" }}
        {{ if eq .Status "firing" }}
                {{ .Labels.node_name }} Load Alert
        {{ end }}
        {{ if eq .Status "resolved" }}
                {{ .Labels.node_name }} OK
        {{ end }}
{{ end }}

It shows the correct text, but the link takes me to the https://<grafana_url>/graph/alerting/list screen in Grafana. Is there any way to change the URL of the link to be the .PanelURL instead? I have been unable to find this information.

1 Like

Can you confirm: are you using the new Grafana Alerting platform (first released in Grafana 8) or the legacy alerting platform? I should note that the legacy platform is no longer actively developed:

https://grafana.com/docs/grafana/next/alerting/migrating-alerts/

and grafana version?

I am using the new Alert Manager in Grafana 8.3.5.

Get BlueMail for Android

I figured it out. In order for the links to show up, I needed to add the Dashboard UID and Panel ID in the Alert Rule. Now I can show them using the .DashboardURL and .PanelURL template variables.

And I went ahead and upgraded to Grafana 9.1.2.

@devopssauce Could you provide an example of how you’ve done this? I’d also like to have hyperlinks in strings to point to the panel url, but I’m still not sure how.

I was able to add proper links to message, but
were you able to change link in subject?..

Something like this:

{{ define "slack.default.message" }}
{{ range . }}
{{ if gt (len .Annotations.summary) 0 }}{{ .Annotations.summary }}{{ end }}
{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}{{ end }}
{{ end }}
{{ end }}

Then in the Alert Rule, make sure the Dashboard UID and Panel ID are showing.