|
|
|
@ -1,7 +1,7 @@
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
|
|
APIKEY="2q2jXBDQ9nq40KEZWoJAUMefV9JvkpRF9Se6JQW9eGceHPtTtsJIeWWp6FeJk5Es"
|
|
|
|
APIKEY=""
|
|
|
|
XI_URL="https://192.168.1.19/nagiosxi"
|
|
|
|
XI_URL=""
|
|
|
|
curl="curl -k -s"
|
|
|
|
curl="curl -k -s"
|
|
|
|
# curl -XGET "https://192.168.1.19/nagiosxi/api/v1/objects/service?apikey=<key>"
|
|
|
|
# curl -XGET "https://192.168.1.19/nagiosxi/api/v1/objects/service?apikey=<key>"
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,35 +49,31 @@ if [ -n "$api_start" -a -n "$api_command" ]; then
|
|
|
|
exit
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Parse our string
|
|
|
|
# Grab a copy of the JSON data so we don't have to keep making calls over and over
|
|
|
|
jqString='.servicestatus[]'
|
|
|
|
|
|
|
|
[ -n "$myHost" ] && jqString="$jqString | select(.host_name | test(\"$myHost\"))"
|
|
|
|
|
|
|
|
[ -n "$myService" ] && jqString="$jqString | select(.service_description | test(\"$myService\"))"
|
|
|
|
|
|
|
|
[ -n "$myCommand" ] && jqString="$jqString | select(.check_command | test(\"$myCommand\"))"
|
|
|
|
|
|
|
|
[ -n "$myHG" ] && jqString="$jqString | select(.hostgroup_name==\"$myHG\")"
|
|
|
|
|
|
|
|
[ -n "$mySG" ] && jqString="$jqString | select(.servicegroup_name==\"$mySG\")"
|
|
|
|
|
|
|
|
[ -n "$myFields" ] && jqString="$jqString | $myFields"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Grab a copy of the hosts.json so we don't have to keep making calls over and over
|
|
|
|
|
|
|
|
# If we used an existing file, then just use that
|
|
|
|
# If we used an existing file, then just use that
|
|
|
|
if [ -z "$myFile" ]; then
|
|
|
|
if [ -z "$myFile" ]; then
|
|
|
|
tmpJSON=`mktemp`
|
|
|
|
tmpJSON=`mktemp`
|
|
|
|
|
|
|
|
do_api objects servicestatus > $tmpJSON
|
|
|
|
else
|
|
|
|
else
|
|
|
|
tmpJSON="$myFile"
|
|
|
|
tmpJSON="$myFile"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Let's pull everything that matches everything we were given
|
|
|
|
|
|
|
|
do_api objects servicestatus > $tmpJSON
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if mySave is not empty, then we're just saving it into the file called $mySave
|
|
|
|
# if mySave is not empty, then we're just saving it into the file called $mySave
|
|
|
|
if [ -n "$mySave" ]; then
|
|
|
|
if [ -n "$mySave" ]; then
|
|
|
|
cp $tmpJSON $mySave
|
|
|
|
mv $tmpJSON $mySave
|
|
|
|
[ -z "$myFile" ] && rm $tmpJSON
|
|
|
|
|
|
|
|
echo "JSON data saved to $mySave"
|
|
|
|
echo "JSON data saved to $mySave"
|
|
|
|
exit
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Otherwise, let's parse the JSON data here
|
|
|
|
# Otherwise, let's parse the JSON data here
|
|
|
|
cat $tmpJSON | jq -r "$jqString"
|
|
|
|
# Parse our string
|
|
|
|
|
|
|
|
jqString='.servicestatus[]'
|
|
|
|
|
|
|
|
[ -n "$myHost" ] && jqString="$jqString | select(.host_name | test(\"$myHost\"))"
|
|
|
|
|
|
|
|
[ -n "$myService" ] && jqString="$jqString | select(.service_description | test(\"$myService\"))"
|
|
|
|
|
|
|
|
[ -n "$myCommand" ] && jqString="$jqString | select(.check_command | test(\"$myCommand\"))"
|
|
|
|
|
|
|
|
[ -n "$myHG" ] && jqString="$jqString | select(.hostgroup_name==\"$myHG\")"
|
|
|
|
|
|
|
|
[ -n "$mySG" ] && jqString="$jqString | select(.servicegroup_name==\"$mySG\")"
|
|
|
|
|
|
|
|
[ -n "$myFields" ] && jqString="$jqString | $myFields"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cat $tmpJSON | jq -r "$jqString"
|
|
|
|
[ -z "$myFile" ] && rm $tmpJSON
|
|
|
|
[ -z "$myFile" ] && rm $tmpJSON
|
|
|
|
|