Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
The Alerting Provisioning HTTP API can be used to create, modify, and delete resources relevant to Grafana-managed alerts. This API is the one used by our Grafana Terraform provider.
For more information on the differences between Grafana-managed and data source-managed alerts, refer to Introduction to alert rules.
If you are running Grafana Enterprise, you need to add specific permissions for some endpoints. For more information, refer to Role-based access control permissions.
Grafana-managed endpoints
Note
In the Alerting provisioning HTTP API, the endpoints use a JSON format that differs from the format returned by the export endpoints.
The export endpoints allow you to export alerting resources in a JSON format suitable for provisioning via files. However, this format cannot be used to update resources via the HTTP API.
Export all alert rules in provisioning file format.
Example request for new alert rule:
http
POST /api/v1/provisioning/alert-rules
Accept:application/jsonContent-Type:application/jsonAuthorization:Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk{"title":"TEST-API_1","ruleGroup":"API","folderUID":"SET_FOLDER_UID","noDataState":"OK","execErrState":"OK","for":"5m","orgId":1,"uid":"","condition":"B","annotations":{"summary":"test_api_1"},"labels":{"API":"test1"},"data":[{"refId":"A","queryType":"","relativeTimeRange":{"from":600,"to":0},"datasourceUid":"XXXXXXXXX-XXXXXXXXX-XXXXXXXXXX","model":{"expr":"up","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"A"}},{"refId":"B","queryType":"","relativeTimeRange":{"from":0,"to":0},"datasourceUid":"-100","model":{"conditions":[{"evaluator":{"params":[6],"type":"gt"},"operator":{"type":"and"},"query":{"params":["A"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"__expr__","uid":"-100"},"hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"B","type":"classic_conditions"}}]}
Export all contact points in provisioning file format.
Example Request for all the contact points:
http
GET /api/v1/provisioning/contact-points
Accept:application/jsonContent-Type:application/jsonAuthorization:Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Export the notification policy tree in provisioning file format.
Example Request for exporting the notification policy tree in YAML format:
http
GET /api/v1/provisioning/policies/export?format=yaml
Accept:application/jsonContent-Type:application/jsonAuthorization:Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
http
HTTP/1.1200OKContent-Type:text/yamlapiVersion:1
policies:
- orgId: 1
receiver: My Contact Email Point
group_by:
- grafana_folder
- alertname
routes:
- receiver: My Contact Email Point
object_matchers:
- - monitor
- =
- testdata
mute_time_intervals:
- weekends
Notification template groups
Template groups enable you to define multiple notification templates ({{ define "" }}) within a single group. They can be managed from the Grafana Alerting UI.
Example Request for all notification template groups:
http
GET /api/v1/provisioning/templates
Accept:application/jsonContent-Type:application/jsonAuthorization:Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
http
HTTP/1.1200OKContent-Type:application/json[{"name":"custom_email.message","template":"{{ define \"custom_email.message\" }}\n Custom alert!\n{{ end }}","provenance":"file"},{"name":"custom_email.subject","template":"{{ define \"custom_email.subject\" }}\n{{ len .Alerts.Firing }} firing alert(s), {{ len .Alerts.Resolved }} resolved alert(s)\n{{ end }}","provenance":"file"}]
GET /api/v1/provisioning/mute-timings
Accept:application/jsonContent-Type:application/jsonAuthorization:Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
By default, you cannot edit API-provisioned alerting resources in Grafana.
To enable editing these resources in the Grafana UI, add the X-Disable-Provenance: true header to the following API requests:
POST /api/v1/provisioning/alert-rules
PUT /api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}(This endpoint changes provenance for all alert rules in the alert group)
POST /api/v1/provisioning/contact-points
POST /api/v1/provisioning/mute-timings
PUT /api/v1/provisioning/templates/{name}
PUT /api/v1/provisioning/policies
To reset the notification policy tree to the default and unlock it for editing in the Grafana UI, use:
DELETE /api/v1/provisioning/policies
Data source-managed resources
The Alerting Provisioning HTTP API can only be used to manage Grafana-managed alert resources. To manage resources related to data source-managed alerts, consider the following tools:
mimirtool: to interact with the Mimir alertmanager and ruler configuration.
cortex-tools: to interact with the Cortex alertmanager and ruler configuration.
Alternatively, the Grafana Alerting API can be used to access data from data source-managed alerts. This API is primarily intended for internal usage, with the exception of the /api/v1/provisioning/ endpoints. It’s important to note that internal APIs may undergo changes without prior notice and are not officially supported for user consumption.
For Prometheus, amtool can also be used to interact with the AlertManager API.
Paths
Delete a specific alert rule by UID. (RouteDeleteAlertRule)
DELETE /api/v1/provisioning/alert-rules/:uid
Parameters
Name
Source
Type
Go type
Required
Default
Description
UID
path
string
string
✓
Alert rule UID
X-Disable-Provenance: true
header
string
string
Allows editing of provisioned resources in the Grafana UI
Whether any contained secure settings should be decrypted or left redacted. Redacted settings will contain RedactedValue instead. Currently, only org admin can view decrypted secure settings.
download
query
boolean
bool
Whether to initiate a download of the file or not.
format
query
string
string
yaml
Format of the downloaded file, either yaml, json or hcl. Accept header can also be used, but the query parameter will take precedence.
When creating a contact point, the EmbeddedContactPoint.name property determines if the new contact point is added to an existing one. In the UI, contact points with the same name are grouped together under a single contact point.
Parameters
Name
Source
Type
Go type
Required
Default
Description
X-Disable-Provenance: true
header
string
string
Allows editing of provisioned resources in the Grafana UI
Sets the notification policy tree. (RoutePutPolicyTree)
Warning
Since the policy tree is a single resource, provisioning it will overwrite all policies in the notification policy tree. However, it does not affect internal policies created when alert rules directly select a contact point.
PUT /api/v1/provisioning/policies
Parameters
Name
Source
Type
Go type
Required
Default
Description
X-Disable-Provenance: true
header
string
string
Allows editing of provisioned resources in the Grafana UI
EmbeddedContactPoint is the contact point type used by Grafana-managed alerts.
When creating a contact point, the EmbeddedContactPoint.name property determines if the new contact point is added to an existing one. In the UI, contact points with the same name are grouped together under a single contact point.
Properties
Name
Type
Go type
Required
Default
Description
Example
disableResolveMessage
boolean
bool
false
name
string
string
name groups multiple contact points with the same name in the UI.
Matchers is a slice of Matchers that is sortable, implements Stringer, and
provides a Matches method to match a LabelSet against all Matchers in the
slice. Note that some users of Matchers might require it to be sorted.
A Route is a node that contains definitions of how to handle alerts. This is modified
from the upstream alertmanager in that it adds the ObjectMatchers property.
RouteExport is the provisioned file export of definitions.Route. This is needed to hide fields that aren’t usable in
provisioning file format. An alternative would be to define a custom MarshalJSON and MarshalYAML that excludes them.