Fix bug where typo in rc file would cause zone owners to be incorrectly assigned

This commit is contained in:
Rob Pearce 2022-05-29 21:36:08 +10:00
parent df44244176
commit 3f3dbaa977
1 changed files with 35 additions and 7 deletions

View File

@ -134,6 +134,10 @@ function getzoneaction() { # populates zproblem[] and zaction[]
fi
fv=$(getforcevent ${zname[$idx]})
if [[ $robtest -eq 1 ]]; then
echo "canping zone ${zname[$idx]} is: $pingok"
fi
donearby=0
if [[ -n $fv && ${zstate[$idx]} == $(getoppositestate ${fv}) ]]; then
@ -274,11 +278,16 @@ function getzoneaction() { # populates zproblem[] and zaction[]
function getidxfromname() { # name
local x
#echo "==== getidxfromname($1)" >/dev/stderr
for x in ${!zname[@]}; do
if [[ ${zname[$x]} == $1 ]]; then
#echo "==== idx $x comparing zname ('${zname[$x]}') to \$1 ('$1')" >/dev/stderr
if [[ ${zname[$x]} == "$1" ]]; then
#echo " ==== matched. returning ${x}" >/dev/stderr
echo "${x}"
return
fi
done
echo "-1"
}
function getnamefromid() { # id
@ -802,6 +811,7 @@ function addperson() {
function addowner() { # zone "host1 host2 ..."
local z h local x idx db doset=0
local zidx
db=0
if [[ $1 == "-s" ]]; then
doset=1
@ -812,6 +822,13 @@ function addowner() { # zone "host1 host2 ..."
shift
h="$*"
zidx=$(getidxfromname "$z") # get the index into the zname[] etc arrays
if [[ $zidx -eq -1 ]]; then
error "Failed to set owner of zone '$z' to '$h' - zone doesn't exist. "
exit 1;
fi
[[ $db -eq 1 ]] && info "addowner() zone $z host(s) [$h]"
idx=$nowners
@ -830,9 +847,9 @@ function addowner() { # zone "host1 host2 ..."
[[ $idx == $nowners ]] && nowners=$((nowners + 1))
if [[ $doset -eq 1 ]]; then
local zidx
zidx=$(getidxfromname "$z")
zowner[$zidx]="${ownerhost[$idx]}";
[[ $db -eq 1 ]] && info " doing set of zowner[$zidx] (${zname[$zidx]}} to [${ownerhost[$idx]}]"
#zownerperson[$zidx]=$(getownerperson "$z"); # may be overwritten later
fi
}
@ -852,7 +869,7 @@ function addowner() { # zone "host1 host2 ..."
#}
# getowner zone_name
# returns devices associated woth zone
# returns devices associated with zone
function getowner() {
local x retval
retval=""
@ -1706,6 +1723,7 @@ profiler=0
csvfile="$DEFAULT_CSVFILE"
sanitycheck=0
RULEFORMAT=ansi
robtest=0
# check for config file option first
if [[ $* == *-f\ * ]]; then
@ -1723,7 +1741,7 @@ fi
ALLARGS="$ALLARGS $*"
optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wWx:y"
optstring="A:cD:f:hHi:I:k:l:Lo:pmRsSt:T:wWx:y"
while getopts "$optstring" i $ALLARGS; do
case "$i" in
h)
@ -1767,6 +1785,9 @@ while getopts "$optstring" i $ALLARGS; do
T)
tolerance_h=${OPTARG}
;;
R)
robtest=1
;;
c)
enable_cronmode
;;
@ -1862,6 +1883,13 @@ for x in ${devices}; do
done
wait
if [[ $robtest -eq 1 ]]; then
for x in ${!zname[@]}; do
echo "zone ${zname[$x]} owner is [${zowner[$x]}]"
done
exit 1
fi
if [[ $showwho -eq 1 ]]; then
# get max phone name length
maxlen=1