Skip to content

Instantly share code, notes, and snippets.

@ycombinator
Last active October 26, 2020 02:39
Show Gist options
  • Save ycombinator/ff4cd5cd4c1fca6f1ae82a496c02e190 to your computer and use it in GitHub Desktop.
Save ycombinator/ff4cd5cd4c1fca6f1ae82a496c02e190 to your computer and use it in GitHub Desktop.
Prefix Kibana asset IDs with package names
#!/bin/bash
# Find dashboards to fix
to_fix=""
for p in packages/*; do
pkg=$(echo $p | cut -d"/" -f 2)
echo "Checking package $pkg..."
dashboard_filenames=$(find $p/kibana/dashboard -type f 2>/dev/null | cut -d "/" -f 5)
echo "Dashboards: "
for d in $dashboard_filenames; do
if [ "$d" == ${d#$pkg} ]; then
to_fix="$to_fix $pkg/$d"
echo -n " [FAIL] "
else
echo -n " [PASS] "
fi
echo $d
done
echo ""
done
# Fix dashboard filenames
echo "Fixing dashboards..."
for f in $to_fix; do
p=$(echo $f | cut -d "/" -f 1)
df=$(echo $f | cut -d "/" -f 2)
di=${df%.json}
old=packages/$p/kibana/dashboard/$df
new=packages/$p/kibana/dashboard/$p-$df
mv $old $new
git rm $old
git add $new
find packages/$p/kibana -type f | xargs -n1 sed -i.bak s/$di/$p-$di/g
find packages/$p/kibana -type f -iname *.bak -delete
done
# Commit the changes
mage format
git commit -m "Prefix dashboard IDs with package names"
#!/bin/bash
# Find visualizations to fix
to_fix=""
for p in packages/*; do
pkg=$(echo $p | cut -d"/" -f 2)
echo "Checking package $pkg..."
visualization_filenames=$(find $p/kibana/visualization -type f 2>/dev/null | cut -d "/" -f 5)
echo "Visualizations: "
for v in $visualization_filenames; do
if [ "$v" == ${v#$pkg} ]; then
to_fix="$to_fix $pkg/$v"
echo -n " [FAIL] "
else
echo -n " [PASS] "
fi
echo $v
done
echo ""
done
# Fix visualization filenames
echo "Fixing visualizations..."
for f in $to_fix; do
p=$(echo $f | cut -d "/" -f 1)
df=$(echo $f | cut -d "/" -f 2)
di=${df%.json}
old=packages/$p/kibana/visualization/$df
new=packages/$p/kibana/visualization/$p-$df
mv $old $new
git rm $old
git add $new
find packages/$p/kibana -type f | xargs -n1 sed -i.bak s/$di/$p-$di/g
find packages/$p/kibana -type f -iname *.bak -delete
done
# Commit the changes
mage format
git commit -m "Prefix visualization IDs with package names"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment