Skip to content

Commit

Permalink
Merge pull request #105 from orfeas0/master
Browse files Browse the repository at this point in the history
Add env vars to the grafana connection of post_start script.
  • Loading branch information
guggero committed Feb 6, 2024
2 parents 9d40b32 + c0ed111 commit a849499
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions post_start/script/set_default_graf_dash.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/sh

# Set your Grafana instance's connection configuration.
GRAFANA_USER=${GRAFANA_USER:-admin}
GRAFANA_PASS=${GRAFANA_PASS:-admin}
GRAFANA_HOST=${GRAFANA_HOST:-grafana}
GRAFANA_PORT=${GRAFANA_PORT:-3000}

echo "Setting Grafana default dashboard..."
DASH_UID="sJUFc-NWk"
DASH_ID=0
for i in 1 2 3 4 5; do
curl -H 'Content-Type: application/json' -X GET http://admin:admin@grafana:3000/api/dashboards/uid/$DASH_UID && RESP=$(curl -H 'Content-Type: application/json' -X GET http://admin:admin@grafana:3000/api/dashboards/uid/$DASH_UID) && DASH_ID=$( echo "$RESP" | jq '.dashboard.id' ) && break || sleep 15;
curl -H 'Content-Type: application/json' -u "${GRAFANA_USER}:${GRAFANA_PASS}" -X GET http://${GRAFANA_HOST}:${GRAFANA_PORT}/api/dashboards/uid/${DASH_UID} && RESP=$(curl -H 'Content-Type: application/json' -u "${GRAFANA_USER}:${GRAFANA_PASS}" -X GET http://${GRAFANA_HOST}:${GRAFANA_PORT}/api/dashboards/uid/${DASH_UID}) && DASH_ID=$( echo "$RESP" | jq '.dashboard.id' ) && break || sleep 15;
done

for i in 1 2 3 4 5; do
curl -d "{\"homeDashboardId\":$DASH_ID}" -H 'Content-Type: application/json' -X PUT http://admin:admin@grafana:3000/api/org/preferences && break || sleep 15;
curl -d "{\"homeDashboardId\":${DASH_ID}}" -H 'Content-Type: application/json' -u "${GRAFANA_USER}:${GRAFANA_PASS}" -X PUT http://${GRAFANA_HOST}:${GRAFANA_PORT}/api/org/preferences && break || sleep 15;
done

0 comments on commit a849499

Please sign in to comment.