Created
August 17, 2017 12:52
-
-
Save DaffyDuke/dbbebf44eba50d0317cf54c3585ef087 to your computer and use it in GitHub Desktop.
Foreman tools
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
server=$(hostname) | |
user=foremanuser | |
pass=password |
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 | |
SEARCH=$1 | |
[ -f ~/.foremanapi ] && { | |
. ~/.foremanapi | |
} || { | |
echo "Missing ~/.foremanapi" | |
echo "" | |
echo "Write this to ~/.foremanapi:" | |
echo "user=<login>" | |
echo "pass=<password>" | |
exit 1 | |
} | |
IDS=`/usr/bin/curl -s -k -u ${user}:${pass} -H "Accept: version=2,application/json" https://$(hostname)/api/hosts?per_page=1500 | jq .results[].id` | |
for ID in $IDS | |
do | |
REPORTS=`/usr/bin/curl -s -k -u ${user}:${pass} -H "Accept: version=2,application/json" https://$(hostname)/api/hosts/${ID}/reports/last` | |
t=`echo "$REPORTS" | jq .logs[].message.message | grep "$SEARCH"` | |
if [ $? -eq 0 ] | |
then | |
echo $REPORTS | jq .host_name | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment