Got rid of - as a default delim, added -s and --num options

dev
Eric Loyd 1 year ago
parent e834fff25d
commit 30cdc36241

15
ENV

@ -4,11 +4,13 @@
varName="servicedesc" varName="servicedesc"
varDefault="" varDefault=""
myDelim="[ :-]" myDelim="[ :]"
myField="" myField=""
myHost="" myHost=""
myService="" myService=""
myContact="" myContact=""
myString=""
doNumber=""
doLower="" doLower=""
doUpper="" doUpper=""
doVerbose="" doVerbose=""
@ -18,7 +20,7 @@ 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>] [-u] [-H|-S|-C <suffix>] [-v] \$\$(\$USER1\$/env [-n <var>] [-t <default>] [-f <field>] [-d <delim>] [-s <val>] [-u|-l] [-H|-S|-C <suffix>] [-v]
\$\$(\$USER1\$/env -N [-H suffix] \$\$(\$USER1\$/env -N [-H suffix]
@ -27,11 +29,13 @@ 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>)
delim an awk-compatible field delimiter (defaults to space, dash, 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
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
--num The result will have all non-numbers stripped from it
-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
@ -70,6 +74,8 @@ while [ -n "$1" ]; do
-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;;
--num) doNumber="true"; shift 1;;
-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;; -l) doLower="true"; shift 1;;
@ -127,6 +133,9 @@ if [ -n "$myContact" ]; then
varValue=${!myContact} varValue=${!myContact}
fi fi
[ -n "$myString" -a "$myString" != "$varValue" ] && varValue=""
[ -n "$doNumber" ] && varValue=`echo $varValue | tr -d -c "0-9"`
[ -z "$varValue" ] && varValue="$varDefault" [ -z "$varValue" ] && varValue="$varDefault"
echo "$varValue" echo "$varValue"

Loading…
Cancel
Save