[v9.5.x] Docs: Add example to extract a specific label value (#66360)
Docs: Add the index function
(cherry picked from commit a39190b613)
Co-authored-by: Simon Crute <simonc6372@users.noreply.github.com>
This commit is contained in:
co-authored by
Simon Crute
parent
fe530beebd
commit
8f9edf19a3
+10
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user