Add label and formatted JSON example (#1465)

# What this PR does
- Updates documentation 

## Which issue(s) this PR fixes
- Removed visible backticks to correct formatting
- Added example of a variable that returns alert labels
- Added details on how to send labels in formatted JSON

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com>
This commit is contained in:
sarah-spang 2023-03-23 10:12:19 -06:00 committed by GitHub
parent b2bb408dd7
commit 44171fc7b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,14 +38,26 @@ the first alert in the alert group:
`alert_payload` is always the first level of any variable you want to call.
The following is an example of an entry in the **Data** field that might return an alert name and description.
The following is an example of an entry in the **Data** field that would return an alert name and description.
```json
{
"name": "{{ alert_payload.labels.alertname }}",
"message": "{{ alert_payload.annotations.description }}"
}
```
The following is an example would return an alert name and the alert's labels.
{
"alertname" : "{{ alert_payload.labels.alertname }}",
"labels" : "{{ alert_payload.labels }}"
}
By default, this will return labels in a list format. If you'd like your labels to be sent in formatted JSON, please use `| tojson()` in your data. For example:
{
"alertname" : "{{ alert_payload.labels.alertname }}",
"labels" : "{{ alert_payload.labels | tojson() }}"
}
> **NOTE:** If you receive an error message and cannot create an outgoing webhook, verify that your JSON is
> formatted correctly.