Fixups, added lowercase to ENV and a few minor quick options to napi
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ "$1" = "set.txt" ] && . set.txt 2> /dev/null
|
||||
|
||||
varName="servicedesc"
|
||||
varDefault=""
|
||||
myDelim="[ :-]"
|
||||
@@ -7,6 +9,7 @@ myField=""
|
||||
myHost=""
|
||||
myService=""
|
||||
myContact=""
|
||||
doLower=""
|
||||
doUpper=""
|
||||
doVerbose=""
|
||||
doNCPA=""
|
||||
@@ -26,6 +29,7 @@ Where:
|
||||
field an awk-compatible field number (potentially to use with <delim>)
|
||||
delim an awk-compatible field delimiter (defaults to space, dash, and colon)
|
||||
-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>
|
||||
-v Be verbose (only for debugging)
|
||||
-N Look for NAGIOS__HOSTNCPA<suffix> (defaults to TOKEN)
|
||||
@@ -68,6 +72,7 @@ while [ -n "$1" ]; do
|
||||
-C) myContact="$2"; shift 2;;
|
||||
-N) doNCPA="true"; shift 1;;
|
||||
-u) doUpper="true"; shift 1;;
|
||||
-l) doLower="true"; shift 1;;
|
||||
-v) doVerbose="true"; shift 1;;
|
||||
*) shift 1;;
|
||||
esac
|
||||
@@ -99,6 +104,7 @@ varValue=`echo $varValue | sed -e "s/^[ \t]*//" -e "s/[ \t]*$//"`
|
||||
do_debug "After processing varValue=$varValue"
|
||||
|
||||
[ -n "$doUpper" ] && varValue=`echo "$varValue" | tr "a-z" "A-Z"`
|
||||
[ -n "$doLower" ] && varValue=`echo "$varValue" | tr "A-Z" "a-z"`
|
||||
|
||||
# Check for myHost
|
||||
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
|
||||
gzip -f -9 --keep $<
|
||||
chmod 644 $@
|
||||
scp $@ ssd:eloyd/
|
||||
|
||||
nagios: napi
|
||||
gzip -f -9 --keep nlog
|
||||
rsync -avu nlog napi root@192.168.1.19:/usr/local/bin/
|
||||
nlog.gz: nlog
|
||||
gzip -f -9 --keep $<
|
||||
chmod 644 $@
|
||||
|
||||
get_profile.sh.gz: get_profile.sh
|
||||
gzip -f -9 --keep $<
|
||||
chmod 644 $@
|
||||
|
||||
test: napi
|
||||
@echo "### Checking HGM:"
|
||||
|
||||
@@ -23,6 +23,7 @@ myOptions[Options]=""
|
||||
verbose="0"
|
||||
tmpJSON=""
|
||||
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
|
||||
declare -A APIinfo
|
||||
@@ -44,7 +45,7 @@ APIinfo["objects/downtime"]=""
|
||||
APIinfo["objects/contact"]=".contact[]"
|
||||
APIinfo["objects/host"]=".host[]"
|
||||
APIinfo["objects/service"]=".[]"
|
||||
APIinfo["objects/hostgroup"]=".[]"
|
||||
APIinfo["objects/hostgroup"]=".hostgroup[]"
|
||||
APIinfo["objects/servicegroup"]=""
|
||||
APIinfo["objects/contactgroup"]=".contactgroup[]"
|
||||
APIinfo["objects/timeperiod"]=""
|
||||
@@ -108,6 +109,7 @@ print_helpopt() {
|
||||
servicestatus|hoststatus:
|
||||
c Show fields selected by -f as quoted CSV
|
||||
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:
|
||||
h Only show hosts (not the complete JSON data)
|
||||
@@ -124,9 +126,12 @@ HELPOPT_EOF
|
||||
|
||||
print_help() {
|
||||
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>
|
||||
--ace active_checks_enabled=<0,1>
|
||||
--api < o*bjects | c*onfig | s*ystem >
|
||||
-c|--command check_command=<value>
|
||||
-cca current_check_attempt=<value>
|
||||
--col column name=<type>:<value>
|
||||
@@ -172,8 +177,6 @@ print_help() {
|
||||
--state 0, 1, or 2 (or other, I suppose)
|
||||
--stype 0, 1 (SOFT or HARD)
|
||||
--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))
|
||||
[...] [...]=<...> 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
|
||||
--helpopt) print_helpopt;;
|
||||
--help) print_help;;
|
||||
--key) apikey="$2"; shift 2;;
|
||||
--keyfile) apikeyfile="$2"; shift 2;;
|
||||
--url) xi_url="$2"; shift 2;;
|
||||
--key) APIKEY="$2"; shift 2;;
|
||||
--keyfile) APIkeyFile="$2"; shift 2;;
|
||||
--url) XI_URL="$2"; shift 2;;
|
||||
-v|--verbose) verbose=$(($verbose + 1)); shift 1;;
|
||||
--api) get_myAPI "$2"; shift 2;;
|
||||
-t|--object) get_myAPIep "$2"; shift 2;;
|
||||
@@ -265,6 +268,10 @@ while [ -n "$1" ]; do
|
||||
esac
|
||||
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[End]}" ] && myOptions[End]=`convert_time "${myOptions[End]}"`
|
||||
# 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[Options]=""
|
||||
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 [ -n "${myOptions[BStatus]}" ]; then
|
||||
myDir[current_state]="[^0]"
|
||||
@@ -283,6 +290,7 @@ if [ -n "${myOptions[Status]}" ]; then
|
||||
fi
|
||||
|
||||
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
||||
do_debug 1 "Looking for url=$url in $APIkeyFile"
|
||||
while read url key; do
|
||||
if [ -z "$XI_URL" ]; then
|
||||
XI_URL="$url"
|
||||
@@ -413,22 +421,24 @@ for thing in "${!myDir[@]}"; do
|
||||
done
|
||||
|
||||
# endpoint specific things
|
||||
case "${myOptions[APIep]}" in
|
||||
hostgroupmembers)
|
||||
case "${myOptions[API]}/${myOptions[APIep]}" in
|
||||
objects/hostgroupmembers)
|
||||
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
||||
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .host_object_id"
|
||||
;;
|
||||
servicegroupmembers)
|
||||
objects/servicegroupmembers)
|
||||
[[ ${myOptions[Options]} =~ "h," ]] && jqString+="| .members[] | .[] | .host_name"
|
||||
[[ ${myOptions[Options]} =~ "o," ]] && jqString+="| .members[] | .[] | .service_object_id"
|
||||
[[ ${myOptions[Options]} =~ "s," ]] && jqString+="| .members[] | .[] | .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";;
|
||||
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";;
|
||||
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";;
|
||||
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";
|
||||
tmpQuicker="Host,Address,State,Type,Last Check,Attempt,Normal,Retry,Max,Command";;
|
||||
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";
|
||||
tmpQuicker="Service,Host,State,Type,Last Check,Attempt,Normal,Retry,Max,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
|
||||
|
||||
do_debug 1 "myOptions[Options]=${myOptions[Options]}"
|
||||
@@ -438,6 +448,7 @@ elif [ -n "${myOptions[Quick]}" ]; then
|
||||
myOptions[Fields]="$tmpQuick"
|
||||
fi
|
||||
[[ ${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]}"
|
||||
[ -n "${myOptions[Fields]}" ] && jq_get_fields
|
||||
jqString+="${myOptions[MoreJQ]}"
|
||||
|
||||
Reference in New Issue
Block a user