Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Identifying the unique identifier (ID) of a datasource in Grafana is essential for interacting with its configuration via the Grafana API. This process is particularly useful for automation and integration tasks where direct access to the datasource's ID is required. The following procedure demonstrates how to retrieve the datasource ID using its name, based on the official Grafana HTTP API documentation.

For more details, refer to the official Grafana HTTP API documentation.

Table of Contents
stylenone

\uD83D\uDCD8 Instructions

To find the ID of a Grafana datasource by its name, use the following script.

Prerequisites

Update these variables with your Grafana details:

  • HOST: Grafana server IP

  • PORT: Grafana port

  • USER: Grafana username

  • PASS: Grafana password

  • DS_NAME: Datasource name

Script

...

languagebash

...

Prerequisites

Before retrieving the Grafana datasource ID, ensure the following:

  1. Grafana Server Access: Ensure network access to the Grafana instance, with the correct IP and port.

  2. User Credentials: A valid username and password with permission to access the API.

  3. Datasource Name: You must know the exact name of the datasource whose ID you wish to retrieve.

  4. Command-line Tools:

    • curl: To send HTTP requests.

    • jq: (Optional) A tool to parse JSON responses. If not installed, the full response will be returned.

Instructions

  1. Get the Datasource ID by Name: Replace the variables (admin, 10.2.7.100

...

  1. , adminz-password

...

  1. , 80, hivemq-prometheus-1

...

  1. ) with your actual Grafana details and run the following command:

    Code Block
    languagebash
    curl -s -u "

...

  1. admin:

...

  1. adminz-password" 

...

  1. "http://

...

  1. 10.2.7.100:80/api/datasources/name/

...

  1. hivemq-prometheus-1" | jq '.id'
  2. Expected Output

...

  1. : The

...

  1. command will return the datasource ID as a JSON response. For example:

    Code Block
    languagetext
    11
  2. Error Messages:

    • Connection

...

    • Error: curl: (7) Failed to connect

    • Invalid

...

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

    • Unauthorized: {"message": "Unauthorized"}

  1. List All Datasources

...

  1. : To list all available datasources, use the following command:

    Code Block
    languagebash
    curl -s -u "

...

  1. admin:

...

  1. adminz-password" 

...

  1. "http://

...

  1. 10.2.7.100:80/api/datasources"

...

...