2016-11-24 03:16:24 -06:00
|
|
|
+++
|
|
|
|
title = "Data source HTTP API "
|
|
|
|
description = "Grafana Data source HTTP API"
|
|
|
|
keywords = ["grafana", "http", "documentation", "api", "data source"]
|
|
|
|
aliases = ["/http_api/datasource/"]
|
|
|
|
type = "docs"
|
|
|
|
[menu.docs]
|
|
|
|
name = "Data source"
|
|
|
|
parent = "http_api"
|
|
|
|
+++
|
|
|
|
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2016-02-05 03:47:34 -06:00
|
|
|
# Data source API
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2016-02-05 03:47:34 -06:00
|
|
|
## Get all datasources
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
`GET /api/datasources`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
GET /api/datasources HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id":1,
|
|
|
|
"orgId":1,
|
|
|
|
"name":"datasource_elastic",
|
|
|
|
"type":"elasticsearch",
|
|
|
|
"access":"proxy",
|
|
|
|
"url":"http://mydatasource.com",
|
|
|
|
"password":"",
|
|
|
|
"user":"",
|
|
|
|
"database":"grafana-dash",
|
|
|
|
"basicAuth":false,
|
|
|
|
"basicAuthUser":"",
|
|
|
|
"basicAuthPassword":"",
|
|
|
|
"isDefault":false,
|
|
|
|
"jsonData":null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2016-02-05 03:47:34 -06:00
|
|
|
## Get a single data sources by Id
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
`GET /api/datasources/:datasourceId`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
GET /api/datasources/1 HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2016-03-08 04:19:52 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
|
|
|
|
|
|
|
{
|
|
|
|
"id":1,
|
|
|
|
"orgId":1,
|
|
|
|
"name":"test_datasource",
|
|
|
|
"type":"graphite",
|
|
|
|
"access":"proxy",
|
|
|
|
"url":"http://mydatasource.com",
|
|
|
|
"password":"",
|
|
|
|
"user":"",
|
|
|
|
"database":"",
|
|
|
|
"basicAuth":false,
|
|
|
|
"basicAuthUser":"",
|
|
|
|
"basicAuthPassword":"",
|
|
|
|
"isDefault":false,
|
|
|
|
"jsonData":null
|
|
|
|
}
|
|
|
|
```
|
2016-03-08 04:19:52 -06:00
|
|
|
|
2016-03-10 03:31:10 -06:00
|
|
|
## Get a single data source by Name
|
2016-03-08 04:19:52 -06:00
|
|
|
|
2018-02-23 07:52:45 -06:00
|
|
|
`GET /api/datasources/name/:name`
|
2016-03-08 04:19:52 -06:00
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
GET /api/datasources/name/test_datasource HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
|
|
|
|
|
|
|
{
|
|
|
|
"id":1,
|
|
|
|
"orgId":1,
|
|
|
|
"name":"test_datasource",
|
|
|
|
"type":"graphite",
|
|
|
|
"access":"proxy",
|
|
|
|
"url":"http://mydatasource.com",
|
|
|
|
"password":"",
|
|
|
|
"user":"",
|
|
|
|
"database":"",
|
|
|
|
"basicAuth":false,
|
|
|
|
"basicAuthUser":"",
|
|
|
|
"basicAuthPassword":"",
|
|
|
|
"isDefault":false,
|
|
|
|
"jsonData":null
|
|
|
|
}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2016-03-10 03:31:10 -06:00
|
|
|
## Get data source Id by Name
|
|
|
|
|
|
|
|
`GET /api/datasources/id/:name`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
GET /api/datasources/id/test_datasource HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2016-03-10 03:31:10 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
2016-03-10 03:31:10 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
{
|
|
|
|
"id":1
|
|
|
|
}
|
|
|
|
```
|
2016-03-10 03:31:10 -06:00
|
|
|
|
2016-02-05 03:47:34 -06:00
|
|
|
## Create data source
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
`POST /api/datasources`
|
|
|
|
|
2017-08-10 18:03:42 -05:00
|
|
|
**Example Graphite Request**:
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
POST /api/datasources HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
|
|
|
|
{
|
|
|
|
"name":"test_datasource",
|
|
|
|
"type":"graphite",
|
|
|
|
"url":"http://mydatasource.com",
|
|
|
|
"access":"proxy",
|
|
|
|
"basicAuth":false
|
|
|
|
}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-08-10 18:03:42 -05:00
|
|
|
**Example CloudWatch Request**:
|
2017-10-05 12:01:03 -05:00
|
|
|
|
|
|
|
```http
|
|
|
|
POST /api/datasources HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
|
|
|
|
{
|
|
|
|
"name": "test_datasource",
|
|
|
|
"type": "cloudwatch",
|
|
|
|
"url": "http://monitoring.us-west-1.amazonaws.com",
|
|
|
|
"access": "proxy",
|
|
|
|
"jsonData": {
|
|
|
|
"authType": "keys",
|
|
|
|
"defaultRegion": "us-west-1"
|
|
|
|
},
|
|
|
|
"secureJsonData": {
|
2018-04-17 15:55:07 -05:00
|
|
|
"accessKey": "Ol4pIDpeKSA6XikgOl4p", //should not be encoded
|
|
|
|
"secretKey": "dGVzdCBrZXkgYmxlYXNlIGRvbid0IHN0ZWFs" //should be Base-64 encoded
|
2017-08-10 18:03:42 -05:00
|
|
|
}
|
2017-10-05 12:01:03 -05:00
|
|
|
}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
{"id":1,"message":"Datasource added", "name": "test_datasource"}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2016-02-05 03:47:34 -06:00
|
|
|
## Update an existing data source
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
`PUT /api/datasources/:datasourceId`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
PUT /api/datasources/1 HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
|
|
|
|
{
|
|
|
|
"id":1,
|
|
|
|
"orgId":1,
|
|
|
|
"name":"test_datasource",
|
|
|
|
"type":"graphite",
|
|
|
|
"access":"proxy",
|
|
|
|
"url":"http://mydatasource.com",
|
|
|
|
"password":"",
|
|
|
|
"user":"",
|
|
|
|
"database":"",
|
|
|
|
"basicAuth":true,
|
|
|
|
"basicAuthUser":"basicuser",
|
|
|
|
"basicAuthPassword":"basicuser",
|
|
|
|
"isDefault":false,
|
|
|
|
"jsonData":null
|
|
|
|
}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
{"message":"Datasource updated", "id": 1, "name": "test_datasource"}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-02-14 03:40:55 -06:00
|
|
|
## Delete an existing data source by id
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
`DELETE /api/datasources/:datasourceId`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
DELETE /api/datasources/1 HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
{"message":"Data source deleted"}
|
|
|
|
```
|
2016-02-03 00:59:22 -06:00
|
|
|
|
2017-02-14 03:40:55 -06:00
|
|
|
## Delete an existing data source by name
|
|
|
|
|
|
|
|
`DELETE /api/datasources/name/:datasourceName`
|
|
|
|
|
|
|
|
**Example Request**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
DELETE /api/datasources/name/test_datasource HTTP/1.1
|
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
|
|
|
```
|
2017-02-14 03:40:55 -06:00
|
|
|
|
|
|
|
**Example Response**:
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```http
|
|
|
|
HTTP/1.1 200
|
|
|
|
Content-Type: application/json
|
2017-02-14 03:40:55 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
{"message":"Data source deleted"}
|
|
|
|
```
|
2017-02-14 03:40:55 -06:00
|
|
|
|
2016-02-03 00:59:22 -06:00
|
|
|
## Data source proxy calls
|
|
|
|
|
|
|
|
`GET /api/datasources/proxy/:datasourceId/*`
|
|
|
|
|
|
|
|
Proxies all calls to the actual datasource.
|