DaffyDuke
8/17/2017 - 12:52 PM

Foreman tools

Foreman tools

#!/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
server=$(hostname)
user=foremanuser
pass=password