From 8f9edf19a3da65345439b1c1d3879c7c185ba20a Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 12 Apr 2023 14:39:33 +0200 Subject: [PATCH] [v9.5.x] Docs: Add example to extract a specific label value (#66360) Docs: Add the index function (cherry picked from commit a39190b6137ea61e194ef5a1fd7e96f83de19cf7) Co-authored-by: Simon Crute --- .../using-go-templating-language.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md b/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md index b6529d4f7b2..a1b5267c338 100644 --- a/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md +++ b/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md @@ -71,6 +71,16 @@ The name of the annotation is {{ .Name }}, and the value is {{ .Value }} {{ end }} ``` +## The index function + +To print a specific annotation or label use the `index` function. + +``` +{{ range .Alerts }} +The name of the alert is {{ index .Labels "alertname" }} +{{ end }} +``` + ## If statements You can use if statements in templates. For example, to print `There are no alerts` if there are no alerts in `.Alerts` you would write the following: