Created
August 17, 2016 20:02
-
-
Save purplexa/e37f6953462f85050b7664a01ba976a0 to your computer and use it in GitHub Desktop.
Bash function for hitting the PuppetDB API, for when you want to use PQL but don't have the cli tool installed
This file contains hidden or 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
function pql { | |
tmpfile=$(mktemp) | |
status_code=$(curl --silent --output /dev/stderr --write-out "%{http_code}" -XGET localhost:8080/pdb/query/v4 -d "query=$1" 2>$tmpfile) | |
if [ "$status_code" = "200" ]; then | |
jq $3 "$2" $tmpfile | |
else | |
cat $tmpfile | |
fi | |
rm $tmpfile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment