-
Notifications
You must be signed in to change notification settings - Fork 62
/
exporter.sh
executable file
·34 lines (28 loc) · 1.33 KB
/
exporter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
. "$(dirname "$0")/config.sh"
fetch_fields() {
curl -sSL -f -k -H "Authorization: Bearer ${1}" "${HOST}/api/${2}" | jq -r "if type==\"array\" then .[] else . end| .${3}"
}
for row in "${ORGS[@]}" ; do
ORG=${row%%:*}
KEY=${row#*:}
DIR="$FILE_DIR/$ORG"
mkdir -p "$DIR/dashboards"
mkdir -p "$DIR/datasources"
mkdir -p "$DIR/alert-notifications"
for dash in $(fetch_fields $KEY 'search?query=&' 'uri'); do
DB=$(echo ${dash}|sed 's,db/,,g').json
echo $DB
curl -f -k -H "Authorization: Bearer ${KEY}" "${HOST}/api/dashboards/${dash}" | jq 'del(.overwrite,.dashboard.version,.meta.created,.meta.createdBy,.meta.updated,.meta.updatedBy,.meta.expires,.meta.version)' > "$DIR/dashboards/$DB"
done
for id in $(fetch_fields $KEY 'datasources' 'id'); do
DS=$(echo $(fetch_fields $KEY "datasources/${id}" 'name')|sed 's/ /-/g').json
echo $DS
curl -f -k -H "Authorization: Bearer ${KEY}" "${HOST}/api/datasources/${id}" | jq '' > "$DIR/datasources/${id}.json"
done
for id in $(fetch_fields $KEY 'alert-notifications' 'id'); do
FILENAME=${id}.json
echo $FILENAME
curl -f -k -H "Authorization: Bearer ${KEY}" "${HOST}/api/alert-notifications/${id}" | jq 'del(.created,.updated)' > "$DIR/alert-notifications/$FILENAME"
done
done