Skip to content

Instantly share code, notes, and snippets.

@arunvelsriram
Last active March 6, 2019 06:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunvelsriram/a88ab4ce955b1508e056072f969504e6 to your computer and use it in GitHub Desktop.
Save arunvelsriram/a88ab4ce955b1508e056072f969504e6 to your computer and use it in GitHub Desktop.
Fuzzy search over Grafana dashboards (filtered by tag) and open them from the command-line
#!/usr/bin/env bash
## Tested on Grafana v5.1.3
function dashboards {
base_url="<BASE-URL>"
dashboards=$(curl -s -H "Authorization: Bearer <TOKEN>" \
$base_url/api/search?query=\&tag=<TAG> \
| jq -r '.[]')
titles=$(echo $dashboards | jq -r '.title' | fzf --height 10 --reverse --multi)
[ -z "$titles" ] && return
while read -r title; do
url=$(echo $dashboards | jq "select(.title==\"$title\")" | jq -r '.url')
urls=$(echo "$base_url/$url $urls")
done <<< "$titles"
open $urls
}
## Tested on Grafana v4.2.0
function dashboards {
base_url="<BASE-URL>"
dashboards=$(curl -s -H "Authorization: Bearer <TOKEN>" \
$base_url/api/search?query=\&tag=<TAG> \
| jq -r '.[]')
titles=$(echo $dashboards | jq -r '.title' | fzf --height 10 --reverse --multi)
[ -z "$titles" ] && return
while read -r title; do
uri=$(echo $dashboards | jq "select(.title==\"$title\")" | jq -r '.uri')
urls=$(echo "$base_url/dashboard/$uri $urls")
done <<< "$titles"
open $urls
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment