From 820fcdf96b1f0d02fb4d49c526087f584be78ec6 Mon Sep 17 00:00:00 2001 From: Derek Feichtinger Date: Wed, 15 Apr 2026 13:39:16 +0200 Subject: [PATCH] add some checks and error management --- grafana-save-dashb.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/grafana-save-dashb.sh b/grafana-save-dashb.sh index ba5abb5..1fa44ba 100755 --- a/grafana-save-dashb.sh +++ b/grafana-save-dashb.sh @@ -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