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.
Alerting provisioning HTTP API
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.
Alert rules
Example request for new alert rule:
Example Response:
Contact points
Example Request for all the contact points:
GET /api/v1/provisioning/contact-points
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"uid": "",
"name": "email receiver",
"type": "email",
"settings": {
"addresses": "<example@email.com>"
},
"disableResolveMessage": false
}
]
Notification policies
Example Request for exporting the notification policy tree in YAML format:
GET /api/v1/provisioning/policies/export?format=yaml
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
HTTP/1.1 200 OK
Content-Type: text/yaml
apiVersion: 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:
GET /api/v1/provisioning/templates
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
HTTP/1.1 200 OK
Content-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"
}
]
Mute timings
Example Request for all mute timings:
GET /api/v1/provisioning/mute-timings
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Example Response:
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"name": "weekends",
"time_intervals": [
{
"weekdays": [
"saturday",
"sunday"
]
}
],
"version": "",
"provenance": "file"
}
]
Edit resources in the Grafana UI
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:
PUT /api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}
: This action also sets the provenance for the rule group and all its alert rules.POST /api/v1/provisioning/alert-rules
: The provenance of the new alert rule must match the provenance value configured for its rule 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:
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.
- lokitool: to configure the Loki Ruler.
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
All responses
Responses
204 - The alert rule was deleted successfully.
Status: No Content
Schema
Delete a contact point. (RouteDeleteContactpoints)
DELETE /api/v1/provisioning/contact-points/:uid
Parameters
All responses
Responses
204 - The contact point was deleted successfully.
Status: No Content
Schema
Delete a mute timing. (RouteDeleteMuteTiming)
DELETE /api/v1/provisioning/mute-timings/:name
Parameters
All responses
Responses
204 - The mute timing was deleted successfully.
Status: No Content
Schema
409 - Conflict
Status: Conflict
Schema
Delete a notification template group. (RouteDeleteTemplate)
DELETE /api/v1/provisioning/templates/:name
Parameters
All responses
Responses
204 - The template was deleted successfully.
Status: No Content
Schema
409 - Conflict
Status: Conflict
Schema
Get a specific alert rule by UID. (RouteGetAlertRule)
GET /api/v1/provisioning/alert-rules/:uid
Parameters
All responses
Responses
200 - ProvisionedAlertRule
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Export an alert rule in provisioning file format. (RouteGetAlertRuleExport)
GET /api/v1/provisioning/alert-rules/:uid/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - AlertingFileExport
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Get a rule group. (RouteGetAlertRuleGroup)
GET /api/v1/provisioning/folder/:folderUid/rule-groups/:group
Parameters
All responses
Responses
200 - AlertRuleGroup
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Export an alert rule group in provisioning file format. (RouteGetAlertRuleGroupExport)
GET /api/v1/provisioning/folder/:folderUid/rule-groups/:group/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - AlertingFileExport
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Get all the alert rules. (RouteGetAlertRules)
GET /api/v1/provisioning/alert-rules
All responses
Responses
200 - ProvisionedAlertRules
Status: OK
Schema
Export all alert rules in provisioning file format. (RouteGetAlertRulesExport)
GET /api/v1/provisioning/alert-rules/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - AlertingFileExport
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Get all the contact points. (RouteGetContactpoints)
GET /api/v1/provisioning/contact-points
Parameters
All responses
Responses
200 - ContactPoints
Status: OK
Schema
Export all contact points in provisioning file format. (RouteGetContactpointsExport)
GET /api/v1/provisioning/contact-points/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - AlertingFileExport
Status: OK
Schema
403 - PermissionDenied
Status: Forbidden
Schema
Get a mute timing. (RouteGetMuteTiming)
GET /api/v1/provisioning/mute-timings/:name
Parameters
All responses
Responses
200 - MuteTimeInterval
Status: OK
Schema
404 - Not found.
Status: Not Found
Schema
Get all the mute timings. (RouteGetMuteTimings)
GET /api/v1/provisioning/mute-timings
All responses
Responses
200 - MuteTimings
Status: OK
Schema
Export all mute timings in provisioning file format. (RouteGetMuteTimingsExport)
GET /api/v1/provisioning/mute-timings/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - MuteTimingsExport
Status: OK
Schema
403 - PermissionDenied
Status: Forbidden
Schema
Export a mute timing in provisioning file format. (RouteGetMuteTimingExport)
GET /api/v1/provisioning/mute-timings/:name/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - MuteTimingExport
Status: OK
Schema
403 - PermissionDenied
Status: Forbidden
Schema
Get the notification policy tree. (RouteGetPolicyTree)
GET /api/v1/provisioning/policies
All responses
Responses
200 - Route
Status: OK
Schema
Export the notification policy tree in provisioning file format. (RouteGetPolicyTreeExport)
GET /api/v1/provisioning/policies/export
Produces
application/json
application/yaml
application/terraform+hcl
text/yaml
text/hcl
These outputs are for file provisioning or Terraform provisioning, and they-including the JSON output—cannot be used to update resources via the HTTP API.
Parameters
All responses
Responses
200 - AlertingFileExport
Status: OK
Schema
404 - NotFound
Status: Not Found
Schema
Get a notification template group. (RouteGetTemplate)
GET /api/v1/provisioning/templates/:name
Parameters
All responses
Responses
200 - NotificationTemplate
Status: OK
Schema
404 - Not found.
Schema
Get all notification template groups. (RouteGetTemplates)
GET /api/v1/provisioning/templates
All responses
Responses
200 - NotificationTemplates
Status: OK
Schema
Create a new alert rule. (RoutePostAlertRule)
POST /api/v1/provisioning/alert-rules
This action creates a new alert rule.
The provenance (X-Disable-Provenance
) of the new rule must match the provenance configured for its rule group. Mixing provisioned and unprovisioned alert rules within the same rule group is not allowed.
Parameters
All responses
Responses
201 - ProvisionedAlertRule
Status: Created
Schema
400 - ValidationError
Status: Bad Request
Schema
Create a contact point. (RoutePostContactpoints)
POST /api/v1/provisioning/contact-points
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
All responses
Responses
202 - EmbeddedContactPoint
Status: Accepted
Schema
400 - ValidationError
Status: Bad Request
Schema
Create a new mute timing. (RoutePostMuteTiming)
POST /api/v1/provisioning/mute-timings
Parameters
All responses
Responses
201 - MuteTimeInterval
Status: Created
Schema
400 - ValidationError
Status: Bad Request
Schema
Update an existing alert rule. (RoutePutAlertRule)
PUT /api/v1/provisioning/alert-rules/:uid
Parameters
All responses
Responses
200 - ProvisionedAlertRule
Status: OK
Schema
400 - ValidationError
Status: Bad Request
Schema
Update the interval or alert rules of a rule group. (RoutePutAlertRuleGroup)
PUT /api/v1/provisioning/folder/:folderUid/rule-groups/:group
This action also changes the provenance setting (X-Disable-Provenance
) for all alert rules in the alert group.
Parameters
All responses
Responses
200 - AlertRuleGroup
Status: OK
Schema
400 - ValidationError
Status: Bad Request
Schema
Update an existing contact point. (RoutePutContactpoint)
PUT /api/v1/provisioning/contact-points/:uid
Parameters
All responses
Responses
202 - Ack
Status: Accepted
Schema
400 - ValidationError
Status: Bad Request
Schema
Replace an existing mute timing. (RoutePutMuteTiming)
PUT /api/v1/provisioning/mute-timings/:name
Parameters
All responses
Responses
200 - MuteTimeInterval
Status: OK
Schema
400 - ValidationError
Status: Bad Request
Schema
409 - Conflict
Status: Conflict
Schema
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
All responses
Responses
202 - Ack
Status: Accepted
Schema
400 - ValidationError
Status: Bad Request
Schema
Create or update a notification template group. (RoutePutTemplate)
PUT /api/v1/provisioning/templates/:name
All responses
Responses
202 - NotificationTemplate
Status: Accepted
Schema
400 - ValidationError
Status: Bad Request
Schema
409 - Conflict
Status: Conflict
Schema
Clears the notification policy tree. (RouteResetPolicyTree)
DELETE /api/v1/provisioning/policies
All responses
Responses
202 - Ack
Status: Accepted
Schema
Models
Ack
AlertQuery
Properties
AlertQueryExport
Properties
AlertRuleExport
Properties
AlertRuleGroup
Properties
AlertRuleGroupExport
Properties
AlertingFileExport
Properties
ContactPointExport
Properties
ContactPoints
Duration
EmbeddedContactPoint
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
Json
MatchRegexps
MatchType
Matcher
Properties
Matchers
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.
[] Matcher
MuteTimeInterval
Properties
MuteTimingExport
Properties
MuteTimingsExport
Properties
MuteTimings
NotFound
NotificationPolicyExport
Properties
NotificationTemplate
Properties
NotificationTemplateContent
Properties
NotificationTemplates
ObjectMatchers
Inlined models
PermissionDenied
Provenance
ProvisionedAlertRule
Properties
ProvisionedAlertRules
RawMessage
ReceiverExport
Properties
Regexp
A Regexp is safe for concurrent use by multiple goroutines, except for configuration methods, such as Longest.
RelativeTimeRange
RelativeTimeRange is the per query start and end time for requests.
Properties
Route
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.
Properties
RouteExport
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.
Properties
TimeInterval
TimeInterval describes intervals of time. ContainsTime will tell you if a golang time is contained within the interval.
Properties
TimeRange
For example, 4:00PM to End of the day would Begin at 1020 and End at 1440.
Properties
ValidationError
Properties
GenericPublicError
Properties