Failing to access __dashboardUid__ in notification template

I’m struggling to decant the variable appearing as .Annotations.__dashboardUid__ in the “payload” window of the notifications template groups window in grafana cloud and use it in my template.

My goal is to rewrite dashboard urls programmatically in the template to link individual alerts back to the dashboard from a slack ping. I had this working previously but never with a variable that starts __ so maybe this is not possible? Seems an awful shame to have that information in the payload and not be able to leverage it.

To be explicit I’m looking to access the value targetUid from a (mostly redacted) payload that looks like the example below.

  {
    "status": "firing",
    "annotations": {
      "__dashboardUid__": "targetUid",
      "__orgId__": "1",
      "__panelId__": "60",
      "__value_string__": "foobar",
      "__values__": "{\"B\":1,\"C\":1}",
      "summary": "foo :: bar"
    },
    "labels": {
      "Environment": "production",

I’ve had success accessing the summary variable in the annotations object using {{ .Annotations.summary }} but no luck with getting at that dashboardUid variable and no luck finding explainations of it’s special nature in the grafana docs.

Can anyone shed light on this or perhaps propose a work around?

If the alert rule has linked a dashboard and panel via annotations, {{.Alert.DashboardURL}} and {{.Alert.PanelURL}} will provide the URL of the dashboard and panel respectively.

Related docs:

In the case that the DashboardURL or PanelURL don’t provide the value you are looking for, you can edit the values using String templating functions, such like reReplaceAll.

Alternatively, you can create a custom annotation with the value of the URL, and read it from the template as {{Annotations.custom_annotation_name}}.

Hope this helps. Let us know otherwise.

Thanks for the response!

I ended up solving this using labels. I set a label on the alert equal to the Dashboard UID and then was able to reference that in my template.

I did try to set the custom annotation but I struggled to use it in the notification template same as the apparently inaccessible __dashboardUid__ value.

I’ll do some testing and see if the {{.Alert.DashboardURL}} could have worked but I suspect because I was setting some variables with my template in the dashboardURL that this will be problematic.

For posterity this was my solution.

I set the alert labels in the Alert Rules screen.


And then used them in my template like this.
https://foobar.grafana.net/d/{{ .Labels.dashboardUID}}/dashboard-name?orgId=1
Which was the solution I ended landed on eventually.

Since my template was for a slack channel the final url looked actually looked slightly different for slacks markdown + my extra variables being set.
<https://foobar.grafana.net/d/{{ .Labels.dashboardUID }}/dashboard-name?orgId=1&var-cluster={{ .Labels.cluster }}&var-deployment_env=All&var-app=All&var-namespace={{ .Labels.namespace }}&var-deployment=All&var-repository=All&var-container={{ .Labels.container }}|Dashboard>


Am I correct in understanding that annotations that are delimited with __ are inaccessible from the notifications templates? If so can someone direct me to which docs they would suggest I add that to please? I have not found it stated in any of the docs I read including the very helpful ones you linked @pepecano.

"annotations": {
      "__dashboardUid__": "targetUid",
      "__orgId__": "1",
      "__panelId__": "60",
      "__value_string__": "foobar",
      "__values__": "{\"B\":1,\"C\":1}",
      "summary": "foo :: bar"
    },

You cannot access __ properties through {{ .Alert.Annotations }}.

However, most of these properties are available as other alert fields: dashboardURL ,panelURL, Values ,ValuesString.

The following example works when linking the alert rule to a dashboard panel:

{{ range .Alerts -}}
  - Dashboard: {{ .DashboardURL }}
  - Panel: {{ .PanelURL }}
  - AlertGenerator: {{ .GeneratorURL }}
  - Silence: {{ .SilenceURL }}
{{ end }}

This would print something like:

- Dashboard: https://alerttest.grafana.net/d/ce2bl9hrri800c?orgId=1
- Panel: https://alerttest.grafana.net/d/ce2bl9hrri800c?orgId=1&viewPanel=1
- AlertGenerator: https://alerttest.grafana.net/alerting/grafana/edo4r2gokl4w0c/view?orgId=1
- Silence: https://alerttest.grafana.net/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dfrontend1&matcher=grafana_folder%3DAlerts&matcher=severity%3Dhigh&matcher=team%3Dfrontend&orgId=1

Anyway, it’s common to build the URL as you’ve done to link to the dashboard with query parameters.

As a recommendation, instead of creating a label, I’d suggest creating a custom annotation for this case and then accessing it as follows:

{{ .Annotations.custom_annotation_name }}

Annotations are used to enrich the alert with relevant information, while labels are for differentiating alerts. You can read more about labels vs annotations in the docs.

1 Like

Can you point me to the documentation I missed where it says this? Happy to commit an addition if it needs to be added also.