|
|
|
@ -23,6 +23,7 @@ myOptions[Options]=""
|
|
|
|
verbose="0"
|
|
|
|
verbose="0"
|
|
|
|
tmpJSON=""
|
|
|
|
tmpJSON=""
|
|
|
|
tmpQuick=""
|
|
|
|
tmpQuick=""
|
|
|
|
|
|
|
|
tmpQuicker=""
|
|
|
|
|
|
|
|
|
|
|
|
# Different API commands return different JSON datasets. So let's make a lookup table that figures out where to start the data extracts
|
|
|
|
# Different API commands return different JSON datasets. So let's make a lookup table that figures out where to start the data extracts
|
|
|
|
declare -A APIinfo
|
|
|
|
declare -A APIinfo
|
|
|
|
@ -44,7 +45,7 @@ APIinfo["objects/downtime"]=""
|
|
|
|
APIinfo["objects/contact"]=".contact[]"
|
|
|
|
APIinfo["objects/contact"]=".contact[]"
|
|
|
|
APIinfo["objects/host"]=".host[]"
|
|
|
|
APIinfo["objects/host"]=".host[]"
|
|
|
|
APIinfo["objects/service"]=".[]"
|
|
|
|
APIinfo["objects/service"]=".[]"
|
|
|
|
APIinfo["objects/hostgroup"]=".[]"
|
|
|
|
APIinfo["objects/hostgroup"]=".hostgroup[]"
|
|
|
|
APIinfo["objects/servicegroup"]=""
|
|
|
|
APIinfo["objects/servicegroup"]=""
|
|
|
|
APIinfo["objects/contactgroup"]=".contactgroup[]"
|
|
|
|
APIinfo["objects/contactgroup"]=".contactgroup[]"
|
|
|
|
APIinfo["objects/timeperiod"]=""
|
|
|
|
APIinfo["objects/timeperiod"]=""
|
|
|
|
@ -108,6 +109,7 @@ print_helpopt() {
|
|
|
|
servicestatus|hoststatus:
|
|
|
|
servicestatus|hoststatus:
|
|
|
|
c Show fields selected by -f as quoted CSV
|
|
|
|
c Show fields selected by -f as quoted CSV
|
|
|
|
C Same as C but also include the fields
|
|
|
|
C Same as C but also include the fields
|
|
|
|
|
|
|
|
X Same as C but use a more human-friendly set of names for the fields when printed
|
|
|
|
|
|
|
|
|
|
|
|
hostgroupmembers:
|
|
|
|
hostgroupmembers:
|
|
|
|
h Only show hosts (not the complete JSON data)
|
|
|
|
h Only show hosts (not the complete JSON data)
|
|
|
|
@ -124,9 +126,12 @@ HELPOPT_EOF
|
|
|
|
|
|
|
|
|
|
|
|
print_help() {
|
|
|
|
print_help() {
|
|
|
|
cat << HELP_EOF
|
|
|
|
cat << HELP_EOF
|
|
|
|
|
|
|
|
--api < o*bjects | c*onfig | s*ystem >
|
|
|
|
|
|
|
|
-t|--object < hoststatus | servicestatus | logentries | statehistory | ...
|
|
|
|
|
|
|
|
--url XI_URL=<value>
|
|
|
|
|
|
|
|
|
|
|
|
--ack problem_has_been_acknowledged=<0,1>
|
|
|
|
--ack problem_has_been_acknowledged=<0,1>
|
|
|
|
--ace active_checks_enabled=<0,1>
|
|
|
|
--ace active_checks_enabled=<0,1>
|
|
|
|
--api < o*bjects | c*onfig | s*ystem >
|
|
|
|
|
|
|
|
-c|--command check_command=<value>
|
|
|
|
-c|--command check_command=<value>
|
|
|
|
-cca current_check_attempt=<value>
|
|
|
|
-cca current_check_attempt=<value>
|
|
|
|
--col column name=<type>:<value>
|
|
|
|
--col column name=<type>:<value>
|
|
|
|
@ -172,8 +177,6 @@ print_help() {
|
|
|
|
--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
|
|
|
|
-t|--object < hoststatus | servicestatus | logentries | statehistory | ...
|
|
|
|
|
|
|
|
--url XI_URL=<value>
|
|
|
|
|
|
|
|
-v|--verbose verbose=\$((\$verbose + 1))
|
|
|
|
-v|--verbose verbose=\$((\$verbose + 1))
|
|
|
|
[...] [...]=<...> NOTE: This will take anything listed as a Nagios configuration directive and search for it
|
|
|
|
[...] [...]=<...> NOTE: This will take anything listed as a Nagios configuration directive and search for it
|
|
|
|
|
|
|
|
|
|
|
|
@ -216,9 +219,9 @@ while [ -n "$1" ]; do
|
|
|
|
case "$1" in
|
|
|
|
case "$1" in
|
|
|
|
--helpopt) print_helpopt;;
|
|
|
|
--helpopt) print_helpopt;;
|
|
|
|
--help) print_help;;
|
|
|
|
--help) print_help;;
|
|
|
|
--key) apikey="$2"; shift 2;;
|
|
|
|
--key) APIKEY="$2"; shift 2;;
|
|
|
|
--keyfile) apikeyfile="$2"; shift 2;;
|
|
|
|
--keyfile) APIkeyFile="$2"; shift 2;;
|
|
|
|
--url) xi_url="$2"; shift 2;;
|
|
|
|
--url) XI_URL="$2"; shift 2;;
|
|
|
|
-v|--verbose) verbose=$(($verbose + 1)); shift 1;;
|
|
|
|
-v|--verbose) verbose=$(($verbose + 1)); shift 1;;
|
|
|
|
--api) get_myAPI "$2"; shift 2;;
|
|
|
|
--api) get_myAPI "$2"; shift 2;;
|
|
|
|
-t|--object) get_myAPIep "$2"; shift 2;;
|
|
|
|
-t|--object) get_myAPIep "$2"; shift 2;;
|
|
|
|
@ -265,6 +268,10 @@ while [ -n "$1" ]; do
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fix things that are impossible to call
|
|
|
|
|
|
|
|
[ "${myOptions[API]}" = "config" -a "${myOptions[APIep]}" = "servicestatus" ] && myOptions[APIep]="service"
|
|
|
|
|
|
|
|
[ "${myOptions[API]}" = "config" -a "${myOptions[APIep]}" = "hoststatus" ] && myOptions[APIep]="host"
|
|
|
|
|
|
|
|
|
|
|
|
[ -n "${myOptions[Start]}" ] && myOptions[Start]=`convert_time "${myOptions[Start]}"`
|
|
|
|
[ -n "${myOptions[Start]}" ] && myOptions[Start]=`convert_time "${myOptions[Start]}"`
|
|
|
|
[ -n "${myOptions[End]}" ] && myOptions[End]=`convert_time "${myOptions[End]}"`
|
|
|
|
[ -n "${myOptions[End]}" ] && myOptions[End]=`convert_time "${myOptions[End]}"`
|
|
|
|
# If we're doing status mode, then override a bunch of other options
|
|
|
|
# If we're doing status mode, then override a bunch of other options
|
|
|
|
@ -275,7 +282,7 @@ if [ -n "${myOptions[Status]}" ]; then
|
|
|
|
myOptions[Apply]=""
|
|
|
|
myOptions[Apply]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
myOptions[Quick]="true"
|
|
|
|
myOptions[Quick]="true"
|
|
|
|
myOptions[Options]+="c,C,"
|
|
|
|
myOptions[Options]+="c,X,"
|
|
|
|
# If we did a bstatus, then we only want things that are bad
|
|
|
|
# If we did a bstatus, then we only want things that are bad
|
|
|
|
if [ -n "${myOptions[BStatus]}" ]; then
|
|
|
|
if [ -n "${myOptions[BStatus]}" ]; then
|
|
|
|
myDir[current_state]="[^0]"
|
|
|
|
myDir[current_state]="[^0]"
|
|
|
|
@ -283,6 +290,7 @@ if [ -n "${myOptions[Status]}" ]; then
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
|
|
|
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
|
|
|
|
|
|
|
do_debug 1 "Looking for url=$url in $APIkeyFile"
|
|
|
|
while read url key; do
|
|
|
|
while read url key; do
|
|
|
|
if [ -z "$XI_URL" ]; then
|
|
|
|
if [ -z "$XI_URL" ]; then
|
|
|
|
XI_URL="$url"
|
|
|
|
XI_URL="$url"
|
|
|
|
@ -413,22 +421,24 @@ for thing in "${!myDir[@]}"; do
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# endpoint specific things
|
|
|
|
# endpoint specific things
|
|
|
|
case "${myOptions[APIep]}" in
|
|
|
|
case "${myOptions[API]}/${myOptions[APIep]}" in
|
|
|
|
hostgroupmembers)
|
|
|
|
objects/hostgroupmembers)
|
|
|
|
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
|
|
|
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
|
|
|
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .host_object_id"
|
|
|
|
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .host_object_id"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
servicegroupmembers)
|
|
|
|
objects/servicegroupmembers)
|
|
|
|
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
|
|
|
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
|
|
|
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .service_object_id"
|
|
|
|
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .service_object_id"
|
|
|
|
[[ ${myOptions[Options]} =~ "s," ]] && jqString+="| .members[] | .[] | .service_description"
|
|
|
|
[[ ${myOptions[Options]} =~ "s," ]] && jqString+="| .members[] | .[] | .service_description"
|
|
|
|
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";;
|
|
|
|
objects/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,.output";;
|
|
|
|
tmpQuicker="Host,Address,State,Type,Last Check,Attempt,Normal,Retry,Max,Command";;
|
|
|
|
contact) tmpQuick=".contact_name,.email_address,.host_notifications_enabled,.service_notifications_enabled,.is_active";;
|
|
|
|
objects/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";
|
|
|
|
command) ;;
|
|
|
|
tmpQuicker="Service,Host,State,Type,Last Check,Attempt,Normal,Retry,Max,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";;
|
|
|
|
objects/contact) tmpQuick=".contact_name,.email_address,.host_notifications_enabled,.service_notifications_enabled,.is_active";;
|
|
|
|
|
|
|
|
objects/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";;
|
|
|
|
|
|
|
|
config/host) tmpQuick=".host_name,.address,.check_command";;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
do_debug 1 "myOptions[Options]=${myOptions[Options]}"
|
|
|
|
do_debug 1 "myOptions[Options]=${myOptions[Options]}"
|
|
|
|
@ -438,6 +448,7 @@ elif [ -n "${myOptions[Quick]}" ]; then
|
|
|
|
myOptions[Fields]="$tmpQuick"
|
|
|
|
myOptions[Fields]="$tmpQuick"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
[[ ${myOptions[Options]} =~ "C," ]] && echo "${myOptions[Fields]}"
|
|
|
|
[[ ${myOptions[Options]} =~ "C," ]] && echo "${myOptions[Fields]}"
|
|
|
|
|
|
|
|
[[ ${myOptions[Options]} =~ "X," ]] && echo "$tmpQuicker" && printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
|
|
|
|
do_debug 1 "myOptions[Fields]=${myOptions[Fields]}"
|
|
|
|
do_debug 1 "myOptions[Fields]=${myOptions[Fields]}"
|
|
|
|
[ -n "${myOptions[Fields]}" ] && jq_get_fields
|
|
|
|
[ -n "${myOptions[Fields]}" ] && jq_get_fields
|
|
|
|
jqString+="${myOptions[MoreJQ]}"
|
|
|
|
jqString+="${myOptions[MoreJQ]}"
|
|
|
|
|