2017-01-03 01:12:18 -06:00
+++
title = "Alerting HTTP API "
description = "Grafana Alerting HTTP API"
keywords = ["grafana", "http", "documentation", "api", "alerting"]
aliases = ["/http_api/alerting/"]
type = "docs"
[menu.docs]
name = "Alerting"
parent = "http_api"
+++
# Alerting API
2017-04-12 13:57:22 -05:00
You can use the Alerting API to get information about alerts and their states but this API cannot be used to modify the alert.
To create new alerts or modify them you need to update the dashboard json that contains the alerts.
2017-01-03 01:12:18 -06:00
This API can also be used to create, update and delete alert notifications.
## Get alerts
`GET /api/alerts/`
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
GET /api/alerts HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2017-05-03 10:24:27 -05:00
Querystring Parameters:
These parameters are used as querystring parameters. For example:
`/api/alerts?dashboardId=1`
2018-06-01 07:36:40 -05:00
- **dashboardId** – Limit response to alerts in specified dashboard(s). You can specify multiple dashboards, e.g. dashboardId=23& dashboardId=35.
- **panelId** – Limit response to alert for a specified panel on a dashboard.
- **query** - Limit response to alerts having a name like this value.
2017-05-03 10:24:27 -05:00
- **state** - Return alerts with one or more of the following alert states: `ALL` ,`no_data`, `paused` , `alerting` , `ok` , `pending` . To specify multiple states use the following format: `?state=paused&state=alerting`
2018-06-01 07:36:40 -05:00
- **limit** - Limit response to *X* number of alerts.
- **folderId** – Limit response to alerts of dashboards in specified folder(s). You can specify multiple folders, e.g. folderId=23& folderId=35.
- **dashboardQuery** - Limit response to alerts having a dashboard name like this value.
- **dashboardTag** - Limit response to alerts of dashboards with specified tags. To do an "AND" filtering with multiple tags, specify the tags parameter multiple times e.g. dashboardTag=tag1& dashboardTag=tag2.
2017-05-03 10:24:27 -05:00
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
[
{
"id": 1,
"dashboardId": 1,
2018-05-15 03:06:26 -05:00
"dashboardUId": "ABcdEFghij"
2018-05-14 13:50:08 -05:00
"dashboardSlug": "sensors",
2018-05-15 03:06:26 -05:00
"panelId": 1,
2017-10-05 12:01:03 -05:00
"name": "fire place sensor",
"state": "alerting",
2018-05-14 13:50:08 -05:00
"newStateDate": "2018-05-14T05:55:20+02:00",
2017-10-05 12:01:03 -05:00
"evalDate": "0001-01-01T00:00:00Z",
2018-05-14 13:50:08 -05:00
"evalData": null,
2017-10-05 12:01:03 -05:00
"executionError": "",
2018-05-15 03:06:26 -05:00
"url": "http://grafana.com/dashboard/db/sensors"
2017-10-05 12:01:03 -05:00
}
]
```
2017-01-03 01:12:18 -06:00
## Get one alert
`GET /api/alerts/:id`
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
GET /api/alerts/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
{
2018-05-15 03:06:26 -05:00
"id": 1,
"dashboardId": 1,
"dashboardUId": "ABcdEFghij"
"dashboardSlug": "sensors",
"panelId": 1,
"name": "fire place sensor",
"state": "alerting",
"message": "Someone is trying to break in through the fire place",
"newStateDate": "2018-05-14T05:55:20+02:00",
"evalDate": "0001-01-01T00:00:00Z",
"evalData": "evalMatches": [
{
"metric": "movement",
"tags": {
"name": "fireplace_chimney"
},
"value": 98.765
}
],
"executionError": "",
"url": "http://grafana.com/dashboard/db/sensors"
2017-10-05 12:01:03 -05:00
}
```
2017-01-03 01:12:18 -06:00
2018-05-14 13:50:44 -05:00
**Important Note**:
"evalMatches" data is cached in the db when and only when the state of the alert changes
(e.g. transitioning from "ok" to "alerting" state).
If data from one server triggers the alert first and, before that server is seen leaving alerting state,
a second server also enters a state that would trigger the alert, the second server will not be visible in "evalMatches" data.
2017-01-03 01:12:18 -06:00
## Pause alert
`POST /api/alerts/:id/pause`
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
POST /api/alerts/1/pause HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
2017-01-03 01:12:18 -06:00
2017-10-05 12:01:03 -05:00
{
"paused": true
}
```
2017-01-03 01:12:18 -06:00
2017-05-03 10:24:27 -05:00
The :id query parameter is the id of the alert to be paused or unpaused.
JSON Body Schema:
- **paused** – Can be `true` or `false` . True to pause an alert. False to unpause an alert.
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
{
"alertId": 1,
"state": "Paused",
"message": "alert paused"
}
```
2017-01-03 01:12:18 -06:00
2017-11-22 02:30:03 -06:00
## Pause all alerts
`POST /api/admin/pause-all-alerts`
```http
POST /api/admin/pause-all-alerts HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"paused": true
}
```
JSON Body Schema:
- **paused** – Can be `true` or `false` . True to pause an alert. False to unpause an alert.
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-11-22 02:30:03 -06:00
{
"state": "Paused",
"message": "alert paused",
"alertsAffected": 1
}
```
2017-01-03 01:12:18 -06:00
## Get alert notifications
`GET /api/alert-notifications`
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
GET /api/alert-notifications HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2017-05-03 10:24:27 -05:00
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2017-04-12 13:57:22 -05:00
2018-08-23 11:56:37 -05:00
[
{
"id": 1,
"name": "Team A",
"type": "email",
"isDefault": false,
"sendReminder": false,
"settings": {
"addresses": "carl@grafana.com;dev@grafana.com"
},
"created": "2018-04-23T14:44:09+02:00",
"updated": "2018-08-20T15:47:49+02:00"
}
]
2017-10-05 12:01:03 -05:00
```
2017-01-03 01:12:18 -06:00
## Create alert notification
2018-10-06 10:09:41 -05:00
You can find the full list of [supported notifiers ](/alerting/notifications/#all-supported-notifier ) at the alert notifiers page.
2017-12-14 07:44:58 -06:00
2017-04-12 13:57:22 -05:00
`POST /api/alert-notifications`
2017-01-03 01:12:18 -06:00
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
POST /api/alert-notifications HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"name": "new alert notification", //Required
"type": "email", //Required
"isDefault": false,
2018-08-23 11:56:37 -05:00
"sendReminder": false,
2017-10-05 12:01:03 -05:00
"settings": {
"addresses": "carl@grafana.com;dev@grafana.com"
}
}
```
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
{
"id": 1,
"name": "new alert notification",
"type": "email",
"isDefault": false,
2018-08-23 11:56:37 -05:00
"sendReminder": false,
"settings": {
"addresses": "carl@grafana.com;dev@grafana.com"
},
"created": "2018-04-23T14:44:09+02:00",
"updated": "2018-08-20T15:47:49+02:00"
2017-10-05 12:01:03 -05:00
}
```
2017-01-03 01:12:18 -06:00
## Update alert notification
2017-04-12 13:57:22 -05:00
`PUT /api/alert-notifications/1`
2017-01-03 01:12:18 -06:00
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
PUT /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"id": 1,
"name": "new alert notification", //Required
"type": "email", //Required
"isDefault": false,
2018-08-23 11:56:37 -05:00
"sendReminder": true,
"frequency": "15m",
2017-10-05 12:01:03 -05:00
"settings": {
"addresses: "carl@grafana.com;dev@grafana.com"
}
}
```
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
{
"id": 1,
"name": "new alert notification",
"type": "email",
"isDefault": false,
2018-08-23 11:56:37 -05:00
"sendReminder": true,
"frequency": "15m",
"settings": {
"addresses": "carl@grafana.com;dev@grafana.com"
},
2017-10-05 12:01:03 -05:00
"created": "2017-01-01 12:34",
"updated": "2017-01-01 12:34"
}
```
2017-01-03 01:12:18 -06:00
## Delete alert notification
2017-04-12 13:57:22 -05:00
`DELETE /api/alert-notifications/:notificationId`
2017-01-03 01:12:18 -06:00
**Example Request**:
2017-10-05 12:01:03 -05:00
```http
DELETE /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2017-01-03 01:12:18 -06:00
**Example Response**:
2017-10-05 12:01:03 -05:00
```http
HTTP/1.1 200
Content-Type: application/json
2018-08-23 11:56:37 -05:00
2017-10-05 12:01:03 -05:00
{
"message": "Notification deleted"
}
2018-02-05 02:42:41 -06:00
```