Skip to content

Instantly share code, notes, and snippets.

@ackbyte
Forked from kosuke-/grafana-dashboard-exporter
Created January 13, 2020 12:39
Show Gist options
  • Save ackbyte/ffb1be43066b8c55a66b67bc503ef47d to your computer and use it in GitHub Desktop.
Save ackbyte/ffb1be43066b8c55a66b67bc503ef47d to your computer and use it in GitHub Desktop.
Command to export all grafana 2 dashboard to JSON using curl
#!/usr/bin/env bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KEY=$(<~/.grafanakey)
HOST="https://mdmdev.cloudtrust.rocks"
if [ ! -d $SCRIPT_DIR/dashboards ] ; then
mkdir -p $SCRIPT_DIR/dashboards
fi
for dash in $(curl -k -H "Authorization: Bearer $KEY" $HOST/api/search\?query\=\& | jq -r '.[] | .uri'); do
curl -k -H "Authorization: Bearer $KEY" $HOST/api/dashboards/$dash | sed 's/"id":[0-9]\+,/"id":null,/' | sed 's/\(.*\)}/\1,"overwrite": true}/' | jq . > dashboards/$(echo ${dash} |cut -d\" -f 4 |cut -d\/ -f2).json
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment