Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strophy/8a8fb20c5cdfde73395301c615b4d870 to your computer and use it in GitHub Desktop.
Save strophy/8a8fb20c5cdfde73395301c615b4d870 to your computer and use it in GitHub Desktop.
Export all public Graphana dashboards
#!/bin/bash
full_url="http://your_graphana_host_here"
name="dashboards"
create_slug () {
echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
}
process_db_json() {
db_title=$(echo "${db_json}" | jq -r .dashboard.title)
db_slug=$(create_slug "${db_title}")
filename="${folder}/${db_slug}.json"
echo "Exporting \"${db_title}\" to \"${filename}\"..."
# for recreating via REST API:
# echo "${db_json}" | jq '.dashboard.id = null' > "${filename}"
# for manual provisioning:
echo "${db_json}" | jq '.dashboard.id = null' | jq '.dashboard' > "${filename}"
}
base_url=$(echo "${full_url}" | cut -d@ -f 2)
timestamp=$(date -u +%s)
folder=$(create_slug "${name}-${base_url}-${timestamp}")
mkdir "${folder}"
for db_uid in $(curl -s "${full_url}/api/search" | jq -r .[].uid); do
db_json=$(curl -s "${full_url}/api/dashboards/uid/${db_uid}")
process_db_json $db_json
done
db_json=$(curl -s "${full_url}/api/dashboards/home")
process_db_json $db_json
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment