Adding Label Values to Alert Notifications – How is this done?

Hi all, had a question about adding alerts.

document

it’s suggested that the query triggering the alert can have labels from the query templated into the alert message. As per the documentation, this is how:

Refer to the alert query labels in the alert rule name and/or alert notification message field by using the ${Label} syntax.

Who knows where the ${Label} was created? Thanks so much.

welcome to the :grafana: forum, @df1242636102

first question: the docs you linked are for legacy alerting. You should check if you are using legacy alerting or the new unified alerting platform. What version are you on?

I am using legacy alerting

With the Unified Alerting, you can extract labels out of the metric name field. It’s not pretty, but it works. Here’s an example where I have the metrics in the format: diamond.$dc.$role.$host.*

dc: {{ reReplaceAll "^diamond\\.([^.]+).*" "$1" $labels.name  }}
role: {{ reReplaceAll "^diamond\\.[^.]+\\.[^.]+\\.([^.]+).*" "$1" $labels.name  }}
host: {{ reReplaceAll "^diamond\\.[^.]+\\.[^.]+\\.([^.]+).*" "$1" $labels.name  }}

You can then use those labels for silences and notification policies.