I’m currently facing an issue with accessing the results of a Query Expression within my custom notification template for Managed Grafana alerts. Despite configuring everything correctly (to my knowledge), when I try to use the template variable {{ .Values.value }} to display the query result value in my alarms, it consistently returns 0, indicating that the actual value is not being fetched or accessed correctly. Attached is a screenshot of the Metric expression setup for context.
I have already invested a considerable amount of time trying to troubleshoot and resolve this issue but to no avail. If anyone here has encountered a similar problem or has insights on how to properly access and use Query Expression results in custom notification templates for alerts in Managed Grafana, your guidance would be greatly appreciated. Below is a snippet of how I’m attempting to access the value in the template:
*Value*: {{ .Values.value }}
Thank you in advance for your help and suggestions!
so B value(s) will be {{ index $values "B" }} or {{ $values.B }}.
But this is not a task for notification template. You should use it in the alert annotation, e.g. meaningful description:
Pod: {{ $labels.container }} in namespace: {{ $labels.namespace }} on cluster: {{ $labels.kubernetes_cluster }} has high CPU utilization: {{ humanize $values.B.Value }}%
and notification template just use that annotation.
You should use alert rule annotations such like the description to add extra info to the alert. This information can then be visible on the alert state history within Grafana and in notifications.
Note
Avoid adding extra information about alert instances in notification templates, as this information will only be visible in the notification message.
Instead, you should use annotations or labels to add information directly to the alert, ensuring it’s also visible in the alert state and alert history within Grafana. You can then print the new alert annotation or label in notification templates.