Fix UID sed to target root-level dashboard uid only
The top-level "uid" in Grafana dashboard JSON is at 2-space indent near the end of the file, not the first occurrence. Match on ^ "uid" to avoid clobbering nested datasource uid references. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
334fbbb9e3
commit
c92b949a20
1 changed files with 6 additions and 6 deletions
|
|
@ -80,12 +80,11 @@ spec:
|
||||||
; do
|
; do
|
||||||
wget -q -O "$DEST/$f" "$BASE_URL/$f"
|
wget -q -O "$DEST/$f" "$BASE_URL/$f"
|
||||||
done
|
done
|
||||||
# Stamp stable top-level UIDs so stars/bookmarks survive pod restarts
|
# Stamp stable top-level UIDs so stars/bookmarks survive pod restarts.
|
||||||
# Uses 0,/pattern/ to replace only the first "uid" (the dashboard UID),
|
# Match root-level uid (2-space indent) to avoid clobbering datasource refs.
|
||||||
# leaving datasource UIDs inside panels untouched.
|
|
||||||
for f in "$DEST"/*.json; do
|
for f in "$DEST"/*.json; do
|
||||||
uid="teslamate-$(basename "$f" .json)"
|
uid="teslamate-$(basename "$f" .json)"
|
||||||
sed -i "0,/\"uid\": *\"[^\"]*\"/{s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/}" "$f"
|
sed -i "s/^ \"uid\": *\"[^\"]*\"/ \"uid\": \"${uid}\"/" "$f"
|
||||||
done
|
done
|
||||||
echo "Fetched $(ls "$DEST" | wc -l) TeslaMate dashboards"
|
echo "Fetched $(ls "$DEST" | wc -l) TeslaMate dashboards"
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
@ -122,11 +121,12 @@ spec:
|
||||||
# Fix datasource UIDs to match our Prometheus instance
|
# Fix datasource UIDs to match our Prometheus instance
|
||||||
sed -i 's/"uid": *"bdkj55oguty4gd"/"uid": "prometheus"/g' "$DEST"/*.json
|
sed -i 's/"uid": *"bdkj55oguty4gd"/"uid": "prometheus"/g' "$DEST"/*.json
|
||||||
sed -i 's/"uid": *"\${DS_PROMETHEUS}"/"uid": "prometheus"/g' "$DEST"/*.json
|
sed -i 's/"uid": *"\${DS_PROMETHEUS}"/"uid": "prometheus"/g' "$DEST"/*.json
|
||||||
# Stamp stable top-level UIDs so stars/bookmarks survive pod restarts
|
# Stamp stable top-level UIDs so stars/bookmarks survive pod restarts.
|
||||||
|
# Match root-level uid (2-space indent) to avoid clobbering datasource refs.
|
||||||
for f in "$DEST"/*.json; do
|
for f in "$DEST"/*.json; do
|
||||||
slug=$(basename "$f" .json | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
slug=$(basename "$f" .json | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
||||||
uid="unpoller-${slug}"
|
uid="unpoller-${slug}"
|
||||||
sed -i "0,/\"uid\": *\"[^\"]*\"/{s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/}" "$f"
|
sed -i "s/^ \"uid\": *\"[^\"]*\"/ \"uid\": \"${uid}\"/" "$f"
|
||||||
done
|
done
|
||||||
echo "Fetched $(ls "$DEST" | wc -l) UnPoller dashboards"
|
echo "Fetched $(ls "$DEST" | wc -l) UnPoller dashboards"
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue