Skip to content

Instantly share code, notes, and snippets.

@aranair
Last active March 2, 2020 16:23
Show Gist options
  • Save aranair/bec788df5a9a292f42e088e481b856c6 to your computer and use it in GitHub Desktop.
Save aranair/bec788df5a9a292f42e088e481b856c6 to your computer and use it in GitHub Desktop.
Prepares exported Grafana JSON to be loaded by Prometheus Operator -> Grafana Watcher
# !/bin/bash
#
# Usage:
# 1. Copy the JSON from Grafana -> Export as JSON -> Clipboard
# 2. ./prepare_dashboard.sh new_dashboard_xxx
# - This will create new_dashboard_xxx-dashboard.json
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$#" -ne 1 ]; then
echo "Usage: ./prepare_dashboard.sh <name_of_dashboard>"
exit
fi
# Prepare json for Grafana Watcher
pbpaste | \
jq '.id = null | del(.__requires) | del(.uid) | { dashboard: . , inputs: .__inputs, overwrite: true }' | \
jq '.inputs[0].value=.inputs[0].pluginId' | \
tee "$DIR/$1-dashboard.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment