Skip to content

Instantly share code, notes, and snippets.

@UdjinM6
Last active January 13, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save UdjinM6/d83fe4f0be238887d7dcf18b9ce06e91 to your computer and use it in GitHub Desktop.
Save UdjinM6/d83fe4f0be238887d7dcf18b9ce06e91 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