add some checks and error management
This commit is contained in:
+17
-2
@@ -7,13 +7,28 @@ GRAFANA_URL="https://grafana-test.psi.ch"
|
||||
EXPORT_DIR="./dashboards"
|
||||
# ---------------------
|
||||
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
if [ -z "$API_TOKEN" ];then
|
||||
echo "ERROR: API_TOKEN environment variable is not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting export from $GRAFANA_URL..."
|
||||
echo "Reading dashboard information from: $GRAFANA_URL..."
|
||||
|
||||
# Get list of dashboard UIDs
|
||||
dashboards=$(curl -s -H "Authorization: Bearer $API_TOKEN" \
|
||||
"$GRAFANA_URL/api/search?type=dash-db")
|
||||
if [ $? -ne 0 ];then
|
||||
echo "ERROR: curl call for reading dashboard list failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
status=$(echo "$dashboards" | jq '.statusCode')
|
||||
if [ -n "$status" ];then
|
||||
echo "ERROR: curl call for reading dashboard list failed (Status: $status)" >&2
|
||||
echo $dashboards
|
||||
exit 2
|
||||
fi
|
||||
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
|
||||
# Iterate over dashboards
|
||||
echo "$dashboards" | jq -c '.[]' | while read -r line; do
|
||||
|
||||
Reference in New Issue
Block a user