Fixups, added lowercase to ENV and a few minor quick options to napi
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
[ "$1" = "set.txt" ] && . set.txt 2> /dev/null
|
||||||
|
|
||||||
varName="servicedesc"
|
varName="servicedesc"
|
||||||
varDefault=""
|
varDefault=""
|
||||||
myDelim="[ :-]"
|
myDelim="[ :-]"
|
||||||
@@ -7,6 +9,7 @@ myField=""
|
|||||||
myHost=""
|
myHost=""
|
||||||
myService=""
|
myService=""
|
||||||
myContact=""
|
myContact=""
|
||||||
|
doLower=""
|
||||||
doUpper=""
|
doUpper=""
|
||||||
doVerbose=""
|
doVerbose=""
|
||||||
doNCPA=""
|
doNCPA=""
|
||||||
@@ -26,6 +29,7 @@ Where:
|
|||||||
field an awk-compatible field number (potentially to use with <delim>)
|
field an awk-compatible field number (potentially to use with <delim>)
|
||||||
delim an awk-compatible field delimiter (defaults to space, dash, and colon)
|
delim an awk-compatible field delimiter (defaults to space, dash, and colon)
|
||||||
-u Convert the output to uppercase
|
-u Convert the output to uppercase
|
||||||
|
-l Convert the output to lowercase
|
||||||
suffix Take var result and use the it to get NAGIOS__[HOST|SERVICE|CONTACT]<result><suffix>
|
suffix Take var result and use the it to get NAGIOS__[HOST|SERVICE|CONTACT]<result><suffix>
|
||||||
-v Be verbose (only for debugging)
|
-v Be verbose (only for debugging)
|
||||||
-N Look for NAGIOS__HOSTNCPA<suffix> (defaults to TOKEN)
|
-N Look for NAGIOS__HOSTNCPA<suffix> (defaults to TOKEN)
|
||||||
@@ -68,6 +72,7 @@ while [ -n "$1" ]; do
|
|||||||
-C) myContact="$2"; shift 2;;
|
-C) myContact="$2"; shift 2;;
|
||||||
-N) doNCPA="true"; shift 1;;
|
-N) doNCPA="true"; shift 1;;
|
||||||
-u) doUpper="true"; shift 1;;
|
-u) doUpper="true"; shift 1;;
|
||||||
|
-l) doLower="true"; shift 1;;
|
||||||
-v) doVerbose="true"; shift 1;;
|
-v) doVerbose="true"; shift 1;;
|
||||||
*) shift 1;;
|
*) shift 1;;
|
||||||
esac
|
esac
|
||||||
@@ -99,6 +104,7 @@ varValue=`echo $varValue | sed -e "s/^[ \t]*//" -e "s/[ \t]*$//"`
|
|||||||
do_debug "After processing varValue=$varValue"
|
do_debug "After processing varValue=$varValue"
|
||||||
|
|
||||||
[ -n "$doUpper" ] && varValue=`echo "$varValue" | tr "a-z" "A-Z"`
|
[ -n "$doUpper" ] && varValue=`echo "$varValue" | tr "a-z" "A-Z"`
|
||||||
|
[ -n "$doLower" ] && varValue=`echo "$varValue" | tr "A-Z" "a-z"`
|
||||||
|
|
||||||
# Check for myHost
|
# Check for myHost
|
||||||
if [ -n "$myHost" ]; then
|
if [ -n "$myHost" ]; then
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
|
binFILES=napi.gz nlog.gz get_profile.sh.gz
|
||||||
|
libFILES=ENV
|
||||||
|
|
||||||
|
sync: $(binFILES)
|
||||||
|
rsync -avu $^ ssd:eloyd/
|
||||||
|
rsync -avu $^ root@192.168.1.19:/usr/local/bin/
|
||||||
|
rsync -avu $^ root@192.168.1.19:/usr/local/bin/
|
||||||
|
rsync -avu $(libFILES) root@192.168.1.19:/usr/local/nagios/libexec/
|
||||||
|
rsync -avu $(libFILES) root@192.168.1.15:/usr/local/nagios/libexec/
|
||||||
|
|
||||||
napi.gz: napi
|
napi.gz: napi
|
||||||
gzip -f -9 --keep $<
|
gzip -f -9 --keep $<
|
||||||
chmod 644 $@
|
chmod 644 $@
|
||||||
scp $@ ssd:eloyd/
|
|
||||||
|
|
||||||
nagios: napi
|
nlog.gz: nlog
|
||||||
gzip -f -9 --keep nlog
|
gzip -f -9 --keep $<
|
||||||
rsync -avu nlog napi root@192.168.1.19:/usr/local/bin/
|
chmod 644 $@
|
||||||
|
|
||||||
|
get_profile.sh.gz: get_profile.sh
|
||||||
|
gzip -f -9 --keep $<
|
||||||
|
chmod 644 $@
|
||||||
|
|
||||||
test: napi
|
test: napi
|
||||||
@echo "### Checking HGM:"
|
@echo "### Checking HGM:"
|
||||||
|
|||||||
@@ -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]}"
|
||||||
|
|||||||
Reference in New Issue
Block a user