Skip to main content

Provisioning

Grafana supports managing data sources by adding one or more YAML config files in the provisioning/datasources folder.

Configuration

Example of provisioning the Business Satellite Data Source for the remote Grafana instance.

datasources:
- name: Business Satellite
type: volkovlabs-grapi-datasource
access: proxy
uid: grapi
orgId: 1
version: 1
editable: true
jsonData:
url: https://GRAFANA-IP:GRAFANA-PORT
secureJsonData:
token: API-KEY

Data Sources

When provisioned, the data source should be available in the Data sources lists.

Business Satellite Data Source configured for the local Grafana instance.
Business Satellite Data Source configured for the local Grafana instance.

Set Token

To complete the provisioning you need to set the token using UI or HTTP API:

#!/bin/sh

# Generate a new token
jsonTokenApi=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"apiKey-grapi", "role": "Admin"}' \
http://${GRAFANA_USER}:${GRAFANA_PASSWORD}@${GRAFANA_IP}:${GRAFANA_PORT}/api/auth/keys)
token=$(echo $jsonTokenApi | jq .key)

# Get Provisioned Data Source configuration
jsonDataSource=$(curl -X GET -H "Content-Type: application/json" \
http://${GRAFANA_USER}:${GRAFANA_PASSWORD}@${GRAFANA_IP}:${GRAFANA_PORT}/api/datasources/name/grapi)
datasourceId=$(echo $jsonDataSource | jq '.id')

# Add a token to Secure JSON Data
echo $jsonDataSource | jq '. + {"secureJsonData":{"token":'$token'}}' |
jq '. + {"secureJsonFields":{"token":true}}' >.datasource.json

# Update Data Source
curl -X PUT -H "Content-Type: application/json" -d @.datasource.json \
http://${GRAFANA_USER}:${GRAFANA_PASSWORD}@${GRAFANA_IP}:${GRAFANA_PORT}/api/datasources/${datasourceId}