Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] NodeGraph API plugin is unable to add datasource URL when using grafana api to add datasource #25

Open
aashishlodha25 opened this issue Jan 30, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@aashishlodha25
Copy link

Describe the bug
The Node Graph API plugin fails to correctly add the datasource URL when using the Grafana API to add the datasource. Although the datasource appears to be added successfully, the DATASOURCE_URL field does not show up in the Grafana UI, leading to a "Bad Gateway" error.

Steps to Reprodue

  1. Create a script using the provided code below.
    Run the script to add the Node Graph API datasource via the Grafana API.
    bash
    Copy
    #!/bin/bash
    GRAFANA_URL="https://$grafana_ingress"
    USERNAME="admin"
    PASSWORD="your_grafana_password"

DATASOURCE_NAME="NodeGraphAPI_DS"
DATASOURCE_TYPE="hamedkarbasi93-nodegraphapi-datasource"
DATASOURCE_URL="http://k8spacket.k8spacket.svc.cluster.local:8080/nodegraph"

Create the JSON payload

json_payload="{
"name": "$DATASOURCE_NAME",
"type": "$DATASOURCE_TYPE",
"access": "proxy",
"isDefault": false,
"url": "$DATASOURCE_URL",
"uid": "nodegraphapi_ds",
"jsonData": {}
}"

echo "JSON Payload:"
echo "$json_payload"

Add the NodeGraph API datasource

response=$(curl -k -s -w "%{http_code}" -o /tmp/curl_response_output -X POST "$GRAFANA_URL/api/datasources"
-u "$USERNAME:$PASSWORD"
-H "Content-Type: application/json"
-d "$json_payload")

Check the HTTP response code

if [ "$response" -eq 200 ]; then
echo "Datasource '$DATASOURCE_NAME' added successfully."
elif [ "$response" -eq 401 ]; then
echo "Authentication failed. Please check your Grafana username and password."
elif [ "$response" -eq 409 ]; then
echo "Datasource '$DATASOURCE_NAME' already exists."
else
echo "Failed to add datasource '$DATASOURCE_NAME'. HTTP response code: $response"
echo "Error details:"
cat /tmp/curl_response_output
fi

Expected Result
The datasource should be successfully added, and the DATASOURCE_URL field should appear in the Grafana UI.

Actual Result
The datasource is successfully added, but the DATASOURCE_URL field is missing in the Grafana UI.
A "Bad Gateway" error is displayed due to the absence of the DATASOURCE_URL.

Image Image
@aashishlodha25 aashishlodha25 added the bug Something isn't working label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant