Alerting API

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.

Get alerts

GET /api/alerts/

Example Request:

  1. GET /api/alerts HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Querystring Parameters:

These parameters are used as querystring parameters. For example:

/api/alerts?dashboardId=1

  • 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.
  • 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
  • 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.

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. [
  4. {
  5. "id": 1,
  6. "dashboardId": 1,
  7. "dashboardUId": "ABcdEFghij"
  8. "dashboardSlug": "sensors",
  9. "panelId": 1,
  10. "name": "fire place sensor",
  11. "state": "alerting",
  12. "newStateDate": "2018-05-14T05:55:20+02:00",
  13. "evalDate": "0001-01-01T00:00:00Z",
  14. "evalData": null,
  15. "executionError": "",
  16. "url": "http://grafana.com/dashboard/db/sensors"
  17. }
  18. ]

Get alert by id

GET /api/alerts/:id

Example Request:

  1. GET /api/alerts/1 HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "id": 1,
  5. "dashboardId": 1,
  6. "dashboardUId": "ABcdEFghij"
  7. "dashboardSlug": "sensors",
  8. "panelId": 1,
  9. "name": "fire place sensor",
  10. "state": "alerting",
  11. "message": "Someone is trying to break in through the fire place",
  12. "newStateDate": "2018-05-14T05:55:20+02:00",
  13. "evalDate": "0001-01-01T00:00:00Z",
  14. "evalData": "evalMatches": [
  15. {
  16. "metric": "movement",
  17. "tags": {
  18. "name": "fireplace_chimney"
  19. },
  20. "value": 98.765
  21. }
  22. ],
  23. "executionError": "",
  24. "url": "http://grafana.com/dashboard/db/sensors"
  25. }

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.

Pause alert by id

POST /api/alerts/:id/pause

Example Request:

  1. POST /api/alerts/1/pause HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {
  6. "paused": true
  7. }

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.

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "alertId": 1,
  5. "state": "Paused",
  6. "message": "alert paused"
  7. }

Pause all alerts

See Admin API.