Last active
August 24, 2016 13:38
-
-
Save bbrks/18b5349421081e1fc8c0 to your computer and use it in GitHub Desktop.
Get a list of clickable consul services in BitBar
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
#!/bin/bash | |
# <bitbar.title>Consul Services</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>Ben Brooks</bitbar.author> | |
# <bitbar.author.github>bbrooks</bitbar.author.github> | |
# <bitbar.desc>Displays services in Consul, along with their port numbers</bitbar.desc> | |
# <bitbar.image>https://i.imgur.com/RB7z44c.png</bitbar.image> | |
# <bitbar.dependencies>jq,curl</bitbar.dependencies> | |
# <bitbar.abouturl>https://github.com/matryer/bitbar-plugins/blob/master/Dev/Consul/consul_services.5s.sh</bitbar.abouturl> | |
# | |
# Displays port numbers and names of services in Consul | |
# | |
# CONFIGURATION | |
CONSUL_HOST="argontopcatvbox" | |
CONSUL_API_PORT="8500" | |
JQ_PATH="/usr/local/bin/jq" | |
# END CONFIGURATION | |
echo "🌐" | |
echo "---" | |
echo "Consul Services on $CONSUL_HOST:$CONSUL_API_PORT | href=http://$CONSUL_HOST:$CONSUL_API_PORT/ui" | |
echo "---" | |
RESPONSE=`curl -s --header "Accept:application/json" "http://$CONSUL_HOST:$CONSUL_API_PORT/v1/catalog/node/sandbox"` | |
SERVICES=( $(echo $RESPONSE | $JQ_PATH -c '.Services[]') ) | |
for srv in "${SERVICES[@]}" | |
do | |
ID=$(echo $srv | $JQ_PATH -c --raw-output '.Service') | |
PORT=$(echo $srv | $JQ_PATH -c --raw-output '.Port') | |
printf "$ID -> $PORT|href=http://$CONSUL_HOST:$PORT\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment