Last active
March 6, 2019 06:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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