Created
April 28, 2022 06:14
-
-
Save bauidch/f63931dc1f019e582646e6e3144d66a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export GRAFANA_API_TOKEN= | |
export GRAFANA_URL=https://grafana.local/api | |
mkdir -p dashboards | |
uids_out=$(curl -s -H "Authorization: Bearer $GRAFANA_API_TOKEN" -X GET "$GRAFANA_URL/search?query=&" | jq -r '.[] | select(.type == "dash-db") | .uid') | |
for uid in $(echo $uids_out); do | |
curl -H "Authorization: Bearer $GRAFANA_API_TOKEN" "$GRAFANA_URL/dashboards/uid/$uid" | jq -r > dashboards/${uid}.json | |
DASHBOARD_SLUG=$(cat dashboards/${uid}.json | jq -r '.meta.slug') | |
FOLDER_TITLE=$(cat dashboards/${uid}.json | jq -r '.meta.folderTitle') | |
test -d "dashboards/${FOLDER_TITLE}" || mkdir dashboards/${FOLDER_TITLE} | |
cat dashboards/${uid}.json | jq -r 'del(.meta)' | jq -r .dashboard > dashboards/${FOLDER_TITLE}/${DASHBOARD_SLUG}-${uid}.json | |
rm dashboards/${uid}.json | |
echo "DASHBOARD $uid EXPORTED" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment