Skip to content

Instantly share code, notes, and snippets.

@DaffyDuke
Created August 17, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaffyDuke/dbbebf44eba50d0317cf54c3585ef087 to your computer and use it in GitHub Desktop.
Save DaffyDuke/dbbebf44eba50d0317cf54c3585ef087 to your computer and use it in GitHub Desktop.
Foreman tools
server=$(hostname)
user=foremanuser
pass=password
#!/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