|
|
|
@ -167,6 +167,8 @@ print_help() {
|
|
|
|
-s|--service service_description=<value>
|
|
|
|
-s|--service service_description=<value>
|
|
|
|
--start For things that have date selectors, this is a "show me after" selector: YYYYMMDDHHMMSS
|
|
|
|
--start For things that have date selectors, this is a "show me after" selector: YYYYMMDDHHMMSS
|
|
|
|
--end For things that have date selectors, this is a "show me before" selector: YYYYMMDDHHMMSS
|
|
|
|
--end For things that have date selectors, this is a "show me before" selector: YYYYMMDDHHMMSS
|
|
|
|
|
|
|
|
--status Quick select for showing similar things that you would see on main servicestatus page in the GUI
|
|
|
|
|
|
|
|
--bstatus Same as --status but only show things that are not in an OK state
|
|
|
|
--state 0, 1, or 2 (or other, I suppose)
|
|
|
|
--state 0, 1, or 2 (or other, I suppose)
|
|
|
|
--stype 0, 1 (SOFT or HARD)
|
|
|
|
--stype 0, 1 (SOFT or HARD)
|
|
|
|
--test Don't call the API, just show what would happen
|
|
|
|
--test Don't call the API, just show what would happen
|
|
|
|
@ -257,6 +259,7 @@ while [ -n "$1" ]; do
|
|
|
|
--end) myOptions[End]="$2"; shift 2;;
|
|
|
|
--end) myOptions[End]="$2"; shift 2;;
|
|
|
|
--start) myOptions[Start]="$2"; shift 2;;
|
|
|
|
--start) myOptions[Start]="$2"; shift 2;;
|
|
|
|
--status) myOptions[Status]="true"; shift 1;;
|
|
|
|
--status) myOptions[Status]="true"; shift 1;;
|
|
|
|
|
|
|
|
--bstatus) myOptions[Status]="true"; myOptions[BStatus]="true"; shift 1;;
|
|
|
|
--test) myOptions[TestMode]="true"; shift 1;;
|
|
|
|
--test) myOptions[TestMode]="true"; shift 1;;
|
|
|
|
*) shift 1;;
|
|
|
|
*) shift 1;;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
@ -272,7 +275,11 @@ if [ -n "${myOptions[Status]}" ]; then
|
|
|
|
myOptions[Apply]=""
|
|
|
|
myOptions[Apply]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
myOptions[Quick]="true"
|
|
|
|
myOptions[Quick]="true"
|
|
|
|
myOptions[Options]+="c,"
|
|
|
|
myOptions[Options]+="c,C,"
|
|
|
|
|
|
|
|
# If we did a bstatus, then we only want things that are bad
|
|
|
|
|
|
|
|
if [ -n "${myOptions[BStatus]}" ]; then
|
|
|
|
|
|
|
|
myDir[current_state]="[^0]"
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
|
|
|
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
|
|
|
@ -303,8 +310,8 @@ do_api() {
|
|
|
|
url+="&$colName=$colVal"
|
|
|
|
url+="&$colName=$colVal"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
do_debug 2 "start=$1 command=$2"
|
|
|
|
do_debug 2 "start=$1 command=$2"
|
|
|
|
do_debug 1 "Executing: $url"
|
|
|
|
do_debug 1 "Executing (tesmode=${myOptions[TestMode]}): $url"
|
|
|
|
$curl -XGET -k "$url"
|
|
|
|
[ -z "${myOptions[TestMode]}" ] && $curl -XGET -k "$url"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# curl -XPOST "http://192.168.1.128/nagiosxi/api/v1/config/hostgroup?apikey=fsZZ4pXaKaVjSG7IYcjMRYhK8NqcqN2NGPck8gPhFoZMJGKj4YUjZCF8qSqsK7Ln&pretty=1" -d "hostgroup_name=testapihostgroup&alias=HostGroup&applyconfig=1"
|
|
|
|
# curl -XPOST "http://192.168.1.128/nagiosxi/api/v1/config/hostgroup?apikey=fsZZ4pXaKaVjSG7IYcjMRYhK8NqcqN2NGPck8gPhFoZMJGKj4YUjZCF8qSqsK7Ln&pretty=1" -d "hostgroup_name=testapihostgroup&alias=HostGroup&applyconfig=1"
|
|
|
|
@ -357,26 +364,22 @@ fi
|
|
|
|
# Grab a copy of the JSON data so we don't have to keep making calls over and over
|
|
|
|
# Grab a copy of the JSON data 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 we're in test mode, then skip this part
|
|
|
|
# If we're in test mode, then skip this part
|
|
|
|
if [ -z "${myOptions[TestMode]}" ]; then
|
|
|
|
if [ -z "${myOptions[File]}" ]; then
|
|
|
|
if [ -z "${myOptions[File]}" ]; then
|
|
|
|
tmpJSON=`mktemp`
|
|
|
|
tmpJSON=`mktemp`
|
|
|
|
do_debug 1 "tmp file is $tmpJSON"
|
|
|
|
do_debug 1 "tmp file is $tmpJSON"
|
|
|
|
do_debug 2 " myAPI is ${myOptions[API]} and myAPIep is ${myOptions[APIep]}"
|
|
|
|
do_debug 2 " myAPI is ${myOptions[API]} and myAPIep is ${myOptions[APIep]}"
|
|
|
|
do_api "${myOptions[API]}" "${myOptions[APIep]}" > $tmpJSON
|
|
|
|
do_api "${myOptions[API]}" "${myOptions[APIep]}" > $tmpJSON
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
do_debug 1 "myFile=${myOptions[File]}"
|
|
|
|
|
|
|
|
tmpJSON="${myOptions[File]}"
|
|
|
|
|
|
|
|
do_debug 1 "tmpJSON=$tmpJSON"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if mySave is not empty, then we're just saving it into the file called ${myOptions[Save]}
|
|
|
|
|
|
|
|
if [ -n "${myOptions[Save]}" ]; then
|
|
|
|
|
|
|
|
mv $tmpJSON ${myOptions[Save]}
|
|
|
|
|
|
|
|
do_debug 1 "JSON data saved to ${myOptions[Save]}"
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
echo "### TEST MODE - Skipping API call (testMode=${myOptions[TestMode]}) ###"
|
|
|
|
do_debug 1 "myFile=${myOptions[File]}"
|
|
|
|
|
|
|
|
tmpJSON="${myOptions[File]}"
|
|
|
|
|
|
|
|
do_debug 1 "tmpJSON=$tmpJSON"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if mySave is not empty, then we're just saving it into the file called ${myOptions[Save]}
|
|
|
|
|
|
|
|
if [ -n "${myOptions[Save]}" ]; then
|
|
|
|
|
|
|
|
mv $tmpJSON ${myOptions[Save]}
|
|
|
|
|
|
|
|
do_debug 1 "JSON data saved to ${myOptions[Save]}"
|
|
|
|
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Helper functions for creating our jqString
|
|
|
|
# Helper functions for creating our jqString
|
|
|
|
@ -422,7 +425,7 @@ case "${myOptions[APIep]}" in
|
|
|
|
tmpQuick=".service_object_id,.host_name,.service_description"
|
|
|
|
tmpQuick=".service_object_id,.host_name,.service_description"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
hoststatus) tmpQuick=".host_name,.address,.current_state,.state_type,.last_check,.current_check_attempt,.normal_check_interval,.retry_check_interval,.max_check_attempts,.check_command";;
|
|
|
|
hoststatus) tmpQuick=".host_name,.address,.current_state,.state_type,.last_check,.current_check_attempt,.normal_check_interval,.retry_check_interval,.max_check_attempts,.check_command";;
|
|
|
|
servicestatus) tmpQuick=".service_description,.host_name,.current_state,.state_type,.last_check,.current_check_attempt,.normal_check_interval,.retry_check_interval,.max_check_attempts,.check_command";;
|
|
|
|
servicestatus) tmpQuick=".service_description,.host_name,.current_state,.state_type,.last_check,.current_check_attempt,.normal_check_interval,.retry_check_interval,.max_check_attempts,.output";;
|
|
|
|
contact) tmpQuick=".contact_name,.email_address,.host_notifications_enabled,.service_notifications_enabled,.is_active";;
|
|
|
|
contact) tmpQuick=".contact_name,.email_address,.host_notifications_enabled,.service_notifications_enabled,.is_active";;
|
|
|
|
command) ;;
|
|
|
|
command) ;;
|
|
|
|
statehistory) tmpQuick=".host_name,.service_description,.state_time,.state_change,.state,.state_type,.current_check_attempt,.max_check_attempts,.last_state,.last_hard_state,.output";;
|
|
|
|
statehistory) tmpQuick=".host_name,.service_description,.state_time,.state_change,.state,.state_type,.current_check_attempt,.max_check_attempts,.last_state,.last_hard_state,.output";;
|
|
|
|
@ -445,5 +448,5 @@ if [ -n "${myOptions[TestMode]}" ]; then
|
|
|
|
echo "cat <tmpfile> | jq -r \"$jqString\""
|
|
|
|
echo "cat <tmpfile> | jq -r \"$jqString\""
|
|
|
|
else
|
|
|
|
else
|
|
|
|
cat $tmpJSON | jq -r "$jqString"
|
|
|
|
cat $tmpJSON | jq -r "$jqString"
|
|
|
|
[ -z "${myOptions[File]}" ] && rm $tmpJSON
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -z "${myOptions[File]}" ] && rm $tmpJSON
|
|
|
|
|