Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

This article explains how to find out the id of a Datasource in Grafana when you know its name.

The article is based on the following documentation: https://grafana.com/docs/grafana/latest/developers/http_api/data_source/#get-a-single-data-source-by-name

\uD83D\uDCD8 Instructions

  1. Use the following script to reach Grafana API by IP with username and password.
    Note: values in this script are only an example. Before running this script on your machine, first update grafana_host, grafana_port, grafana_username, grafana_password, and datasource_name with your own actual values.

    #!/bin/bash
    
    #Get a single data source by name
    #GET /api/datasources/name/:name
    
    grafana_host=10.2.7.100
    grafana_port=80
    grafana_username='admin'
    grafana_password='adminz-password'
    datasource_name='hivemq-metrics-1'
    
    curl --location \
      --header 'Content-Type: application/json' \
      --header 'Accept: application/json' \
      "http://${grafana_username}:${grafana_password}@${grafana_host}:${grafana_port}/api/datasources/name/${datasource_name}"
  2. Use the id value as Datasource id.

  3. If all credentials are valid, the output of the script is JSON like this:

    {
      "id": 52,
      "uid": "abcdef1hijk",
      "orgId": 1,
      "name": "hivemq-metrics-1",
      "type": "prometheus",
      "typeLogoUrl": "",
      "access": "proxy",
      "url": "http://hivemq-my-hivemq-metrics.my-hivemq-namespace.svc.cluster.local:9399",
      "password": "",
      "user": "",
      "database": "",
      "basicAuth": false,
      "basicAuthUser": "",
      "basicAuthPassword": "",
      "withCredentials": false,
      "isDefault": false,
      "jsonData": {},
      "secureJsonFields": {},
      "version": 1,
      "readOnly": false
    }

  4. If the Grafana IP is incorrect you will get an error like this:

    curl: (7) Failed to connect to 10.2.7.100 port 80 after 6058 ms: Couldn't connect to server

  5. If user credentials are invalid you will get an error like this:

    {
      "message": "invalid username or password"
    }

  • No labels