Updated Makefile with ENV tests and updted ENV to pull SERVICE: NAME WARN CRIT values with -F

dev
Eric Loyd 1 year ago
parent 30cdc36241
commit 0f808db39a

16
ENV

@ -11,6 +11,7 @@ myService=""
myContact="" myContact=""
myString="" myString=""
doNumber="" doNumber=""
doPipe=""
doLower="" doLower=""
doUpper="" doUpper=""
doVerbose="" doVerbose=""
@ -20,22 +21,24 @@ do_help() {
cat << HELP_EOF cat << HELP_EOF
This utility is designed to be called by the ARGx parameters of a Nagios configuration as one of the following: This utility is designed to be called by the ARGx parameters of a Nagios configuration as one of the following:
\$\$(\$USER1\$/env [-n <var>] [-t <default>] [-f <field>] [-d <delim>] [-s <val>] [-u|-l] [-H|-S|-C <suffix>] [-v] \$\$(\$USER1\$/env [-n <var>] [-t <default>] [-f|-F <field>] [-d <delim>] [-s <val>] [-u|-l] [-H|-S|-C <suffix>] [-v]
\$\$(\$USER1\$/env -N [-H suffix] \$\$(\$USER1\$/env -N [-NP] [-H suffix]
Where: Where:
var the name of a case-insensitive NAGIOS_variable (defaults to "servicedesc") var the name of a case-insensitive NAGIOS_variable (defaults to "servicedesc")
default a default value if \$NAGIOS_var\$ is blank (case sensitive) default a default value if \$NAGIOS_var\$ is blank (case sensitive)
field an awk-compatible field number (potentially to use with <delim>) field an awk-compatible field number (potentially to use with <delim>) (see below)
delim an awk-compatible field delimiter (defaults to space and colon) delim an awk-compatible field delimiter (defaults to space and colon)
-u Convert the output to uppercase -u Convert the output to uppercase
-l Convert the output to lowercase -l Convert the output to lowercase
-p Convert / to | (mainly for disk names in NCPA checks)
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)
-s The result must match this value or else it will return blank -s The result must match this value or else it will return blank
--num The result will have all non-numbers stripped from it --num The result will have all non-numbers stripped from it
-NP Returns NAGIOS__HOSTNCPAPORT (implied default of 5693)
-N Look for NAGIOS__HOSTNCPA<suffix> (defaults to TOKEN) -N Look for NAGIOS__HOSTNCPA<suffix> (defaults to TOKEN)
Can do double lookup if -H is specified directly: -H TOKEN will find NAGIOS__HOSTNCPATOKEN=Level1 which then finds NAGIOS__HOSTLEVEL1TOKEN=Secret Can do double lookup if -H is specified directly: -H TOKEN will find NAGIOS__HOSTNCPATOKEN=Level1 which then finds NAGIOS__HOSTLEVEL1TOKEN=Secret
Or -H PASS will find NAGIOS__HOSTNCPAPASS=Level2 which will then find NAGIOS__HOSTLEVEL2PASS=SuperSecret Or -H PASS will find NAGIOS__HOSTNCPAPASS=Level2 which will then find NAGIOS__HOSTLEVEL2PASS=SuperSecret
@ -44,8 +47,9 @@ Where:
The value will always be trimmed of leading and/or trailing spaces/tabs. The value will always be trimmed of leading and/or trailing spaces/tabs.
If -f is used, then the result will be as if the request were as follows, unless the field starts with a negative, in which case it will read from the last word forward: If -f is used, then the result will be as if the request were as follows, unless the field starts with a negative, in which case it will read from the last word forward:
echo \$NAGIOS_var\$ | awk -F <delim> '{print $<field>}' echo \$NAGIOS_var\$ | awk -F <delim> '{print $<field>}'
If -F is used, -d is forced to " " and the field number reflects is the first, second, or third of the last three fields
Ex: Disk check on / 80 90 With -F 1=/, -F 2=80, -F 3=90
Examples (service_description is assumed to be "MySQL Check: myDatabase performance"): Examples (service_description is assumed to be "MySQL Check: myDatabase performance"):
@ -71,12 +75,15 @@ while [ -n "$1" ]; do
-t) varDefault="$2"; shift 2;; -t) varDefault="$2"; shift 2;;
-d) myDelim="$2"; shift 2;; -d) myDelim="$2"; shift 2;;
-f) myField="$2"; shift 2;; -f) myField="$2"; shift 2;;
-F) myDelim=" "; myField=$(($2-4)); shift 2;;
-H) myHost="$2"; shift 2;; -H) myHost="$2"; shift 2;;
-S) myService="$2"; shift 2;; -S) myService="$2"; shift 2;;
-C) myContact="$2"; shift 2;; -C) myContact="$2"; shift 2;;
-s) myString="$2"; shift 2;; -s) myString="$2"; shift 2;;
--num) doNumber="true"; shift 1;; --num) doNumber="true"; shift 1;;
-N) doNCPA="true"; shift 1;; -N) doNCPA="true"; shift 1;;
-NP) varName="NAGIOS__HOSTNCPAPORT"; varDefault="5693"; shift 1;;
-p) doPipe="true"; shift 1;;
-u) doUpper="true"; shift 1;; -u) doUpper="true"; shift 1;;
-l) doLower="true"; shift 1;; -l) doLower="true"; shift 1;;
-v) doVerbose="true"; shift 1;; -v) doVerbose="true"; shift 1;;
@ -135,6 +142,7 @@ fi
[ -n "$myString" -a "$myString" != "$varValue" ] && varValue="" [ -n "$myString" -a "$myString" != "$varValue" ] && varValue=""
[ -n "$doNumber" ] && varValue=`echo $varValue | tr -d -c "0-9"` [ -n "$doNumber" ] && varValue=`echo $varValue | tr -d -c "0-9"`
[ -n "$doPipe" ] && varValue=`echo $varValue | tr "/" "|"`
[ -z "$varValue" ] && varValue="$varDefault" [ -z "$varValue" ] && varValue="$varDefault"
echo "$varValue" echo "$varValue"

@ -43,3 +43,32 @@ test: napi
@echo "" @echo ""
@echo "Checking stats:" @echo "Checking stats:"
./napi --stats ./napi --stats
ENVtest1="MySQL Check: myDatabase performance"
ENVtest2="Disk Usage on / 80 90"
ENVtest3="One Two: Three - Four 5 6"
test-env: ENV
@echo "This should give $(ENVtest1)"
@NAGIOS_TEST=$(ENVtest1) ./ENV -n test
@echo ""
@echo "This should give / then 80 then 90 then |"
@NAGIOS_TEST=$(ENVtest2) ./ENV -n test -F 1
@NAGIOS_TEST=$(ENVtest2) ./ENV -n test -F 2
@NAGIOS_TEST=$(ENVtest2) ./ENV -n test -F 3
@NAGIOS_TEST=$(ENVtest2) ./ENV -n test -F 1 -p
@echo ""
@echo "This should give Check, then myDatabase, then myDatabase performance, then MySQL Check"
@NAGIOS_TEST=$(ENVtest1) ./ENV -n test -f 2
@NAGIOS_TEST=$(ENVtest1) ./ENV -n test -f 4
@NAGIOS_TEST=$(ENVtest1) ./ENV -n test -d : -f 2
@NAGIOS_TEST=$(ENVtest1) ./ENV -n test -d : -f -2
@echo ""
@echo "This should give Password"
@NAGIOS_TEST=$(ENVtest1) NAGIOS__HOSTMYDATABASEPASS=Password ./ENV -n test -f -2 -H pass
@echo ""
@echo "Test string is: $(ENVtest)"
@echo "The first test should be the full test line, then blank line, then number 5, then FourToken"
@NAGIOS_TEST=$(ENVtest3) ./ENV -n TeSt
@NAGIOS_TEST=$(ENVtest3) ./ENV -n TEST -F 2 -S 5
@NAGIOS_TEST=$(ENVtest3) ./ENV -n test -F 2 --num
@NAGIOS_TEST=$(ENVtest3) NAGIOS__HOSTFOURTOKEN="FourToken" ./ENV -n test -F 1 -H TOKEN

Loading…
Cancel
Save