Grafana JSON Alert Rules
Refer to Grafana official docs for APIs.
We assume that you created an API Key for accessing Grafana.
Download
- Create an alert rule from the Grafana UI.
- Go to the alert rule and use the
copy link
button. In the URL there is the alert rule UID. - Use the UID found in the previous phase to download the alert JSON:
curl -s -H "Authorization: Bearer <my-super-token>" -X GET https://<grafana-url>/api/v1/provisioning/alert-rules/<alert-rule-uid> | tee my-super-alert-rule.json
.
Note: Use
jq
to read the content easely.
Upload
You can choose between 2 options:
- curl for just uploading the alert rule. There are some parameters that could be different between 2 different deploys (e.g., UIDs). It relates only to alert rules and no contact point is created.
- Terraform manages both alert rules and contact points. Repeatable between different Terraform runs.
curl
curl -s -H "Authorization: Bearer <my-super-token>" -X POST https://<grafana-url>/api/v1/provisioning/alert-rules -H "Content-Type: application/json" -d "$(cat my-super-alert-rule.json)"
Delete
It is not possible to delete from the UI alert rules created from APIs.
curl
curl -s -H "Authorization: Bearer <my-super-token>" -X DELETE https://<grafana-url>/api/v1/provisioning/alert-rules/<alert-rule-uid>
Configure the contact point
First you need to setup the contact point to see alerts flowing to slack:
- Go to contact point page and select a new contact point for slack.
- Use a name like
alerts-private-channel
- Insert the
Webhook URL
andtoken
Then you need to create an alert policy or use the root one.
- Go to Alerting > Notification policies > Root policy and select
alerts-private-channel
as default contact point. - Go to Alerting > Notification policies > Create a new policy and set
team=operation
as the matching label together with thealerts-private-channel
as default contact point.