Logz.io Now Supports the OSS Grafana API

OSS Grafana API with Logz.io

Logz.io has a comprehensive API that allows you to send and query logs or metrics easily. Now, that process is getting even easier for infrastructure monitoring. Logz.io has added support for the open source grafana API. In other words, you can use the OSS grafana’s integration within Logz.io.

The open source grafana API is composed of many supported HTTP APIs that the frontend of OSS grafana uses to manage dashboards and dashboard versions, alerts, send snapshots, manage folders and make annotations. The way we at Logz.io connect to that integration is by attaching the Logz.io API Gateway to one the six supported grafana HTTP API endpoints:

  • Alerting
  • Annotations
  • Dashboard
  • Dashboard versions
  • Folder/dashboard search
  • Snapshot

Simply call the API with a GET request after authenticating your Logz.io X-API-TOKEN:

GET /v1/grafana/api/{GRAFANA_API_URL}

Before you do anything else, you’ll need to create your X-API-TOKEN (or your key) to ship into your Logz.io account.

On your Logz.io Operations dashboard, make sure you are on the Metrics UI. Then hit the cog for Settings (⚙). Go to Tools, then Manage Tokens.

On the MANAGE TOKENS page, select the third option on the menu below the title which reads __API tokens__. Then select + New API Token. To use the API in Logz.io, you’ll need this token.

From there, place it in your API request. On OSS grafana, this is usually written as Authorization bearer <<token>>.

Examples

The following offer some examples of things you can do with the grafana API in the Logz.io API Gateway. Included are the basic versions of requests, their cURL counterparts, and some longer examples.

Dashboard API

The Dashboard API can do many things. You can either update an existing dashboard or generate a new one. Additionally, you can retrieve or delete dashboards, get tags, or move to the home dashboard:

Dashboard APIRequestcURL Example
Create Dashboard
POST /api/dashboards/db
curl POST http://api.logz.io/v1/api/dashboards/db
Get Dashboard by uid
GET /api/dashboards/uid/:uid
curl GET http://api.logz.io/v1/api/dashboards/uid/:uid
Delete dashboard by uid
DELETE /api/dashboards/uid/:uid
curl DELETE http://api.logz.io/v1/api/dashboards/uid/:uid
Home Dashboard
GET /api/dashboards/home
curl GET http://api.logz.io/v1/api/dashboards/home
Tags
GET /api/dashboards/tags HTTP/1.1

In order to create a dashboard, you’ll need to include your desired parameters for the dash itself. Define this in the body of the API.

Alerting API & Alerting Notifications API

Querying parameters for the Alerting API include: dashboardTag, dashboardQuery, panelId, dashboardId, query, folderId, limit, and state(ALL, ok, paused, alerting, pending, no_data).

Alerting APIRequest FormatcURL Format
Get alert by id
GET /api/alerts/:id
curl GET http://api.logz.io/v1/api/alerts/id
Pause alert by id
POST /api/alerts/:id/pause
curl POST http://api.logz.io/v1/api/alerts/id/pause
Get a list of notifications
GET /api/alert-notifications
curl GET http://api.logz.io/v1/api/alert-notifications
Get a list of notifications via lookup
GET /api/alert-notifications/lookup
curl GET http://api.logz.io/v1//api/alert-notifications/lookup
get a notification by uid number
GET /api/alert-notifications/uid/:uid
curl GET http://api.logz.io/v1/api/alert-notifications/uid/:uid
Get a notification by id number
GET /api/alert-notifications/:id
curl GET http://api.logz.io/v1/api/alert-notifications/:id
Test notification
POST /api/alert-notifications/test
curl GET http://api.logz.io/v1/api/alert-notifications/test
POST 'https://api.logz.io/v1/grafana/api/dashboards/db' \

--header 'x-api-token: 9c4fdb5e-****-****-****-15c8d2637828'
Accept: application/json
Content-Type: application/json
Authorization: Bearer 50m3rand0mb3ar3rnum43r{
  "uid": "new-alert-notification", //optional
  "name": "new alert notification",  //required
  "type":  "email", //required
  }
}

Annotations

The Annotations API rolled out with the annotation feature itself. They are filtered by tag once you’ve saved and configured them, in one of the given relational databases: postgres, mysql, or sqlite.

This particular grafana API uses the following query parameters (all of which are optional); to and from (for date and time in milliseconds), tags (for annotations not restricted to a specific panel or dash), type, userId, panelId, dashboardId, alertId, and limit.

This particular grafana API uses the following query parameters (all of which are optional); to and from (for date and time in milliseconds), tags (for annotations not restricted to a specific panel or dash), dashboardTag, dashboardQuery, panelId, dashboardId, query, folderId, state, and limit.

Alerting APIRequest FormatcURL Example
Create annotation
POST /api/annotations
curl GET http://api.logz.io/v1/api/annotations
Update annotation
PUT /api/annotations/:id
curl PUT http://api.logz.io/v1/api/annotations/:id
Patch annotation
PATCH /api/annotations/:id
curl PATCH http://api.logz.io/v1/api/annotations/:id
Delete annotation by id
DELETE /api/annotations/:id
curl DELETE http://api.logz.io/v1/api/annotations/:id

Examples:

Convert your dates to milliseconds and input your search limit. If you want to search for specific tags, you can search for multiple. Input the specific tag where it says <<tag_1>> and <<tag_2>>.

GET /api/annotations?from=1597743821000&to=1603014221000&tags=<<tag_1>>&tags=<<tag_2>>&limit=400

Folder/Dashboard Search API

This API lets you search through folders and/or dashboards using the following query parameters: query, page, tag, limit, type (as in dash-folder or dash-db), starred, and either folderIds or dashboardIds.

Alerting APIRequest FormatcURL Format
Get alert by id
GET /api/alerts/:id
curl GET http://api.logz.io/v1/api/alerts/:id
Pause alert by id
POST /api/alerts/:id/pause
curl POST http://api.logz.io/v1/api/alerts/:id/pause

Snapshot API

Versions of the snapshot feature are available in most UI consoles for major DevOps tools. OSS grafana is no different — get a snapshot of a specific chart or dashboard straight out of your UI for reports or for sending.

Snapshot APIRequest FormatcURL Format
Create new snapshot
POST /api/snapshots
curl POST http://api.logz.io/v1/api//snapshots
Get a list of snapshots
GET /api/dashboard/snapshots
curl GET http://api.logz.io/v1/api/dashboard/snapshots
delete Snapshot by deleteKey
GET /api/snapshots-delete/:deleteKey
curl GET http://api.logz.io/v1/api/snapshots-delete/:deleteKey
delete snapshot by key
DELETE /api/snapshots/:key
curl DELETE http://api.logz.io/v1/api/snapshots/:key
get snapshot by key
GET /api/snapshots/:key
curl GET http://api.logz.io/v1/api/snapshots/:key

Conclusion

With this ability, it will be easier to call data within Logz.io Infrastructure Monitoring. For more information on Logz.io Infrastructure Monitoring, check out

Stay updated with us!

By submitting this form, you are accepting our Terms of Use and our Privacy Policy

Thank you for subscribing!

Internal