Add -W option to check availablity of devices rather than 'people' (since a person can have multiple devices associated)

Delete ARP entries before availability check.
This commit is contained in:
Rob Pearce 2022-02-02 14:09:02 +11:00
parent c4c88988c9
commit 7a5452ddfa
1 changed files with 36 additions and 7 deletions

View File

@ -69,7 +69,8 @@ function usage() {
echo " -s Validate config file then exit."
echo " -S[H] Show configured rules in human-readable format"
echo " (HTML if -H given, otherwise ANSI)."
echo " -w List which zone owners' devices are available then exit."
echo " -w List which people are available then exit."
echo " -W List zone owners' devices are available then exit."
echo " -t num Specify degrees below min temperature before taking action."
echo " -T num Specify degrees above max temperature before taking action."
echo " -y Actually run commands/db inserts. By default, commands are just displayed."
@ -1173,9 +1174,9 @@ function canping() {
if [[ -z $ip ]]; then
thisrv=1
else
#arp -d $ip >/dev/null 2>&1
#ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &
#sleep 0.3
arp -d $ip >/dev/null 2>&1
ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &
sleep 0.3
mac=$(arp -n $ip)
mac=$(echo "$mac" | egrep -v "Host|xpired" | awk '{print $2}')
[[ $mac == *:* ]] && thisrv=0 || thisrv=1
@ -1550,7 +1551,7 @@ cronmode=0
logmode=0 #0=none, 1=csv_file, 2=local influxdb
influxdb=""
influxhost="127.0.0.1"
showwho=0
showwho=0 # 1 = show people, 2 = show owners
limit=$DEFAULTLIMIT
profiler=0
csvfile="$DEFAULT_CSVFILE"
@ -1574,7 +1575,7 @@ fi
ALLARGS="$ALLARGS $*"
optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wx:y"
optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wWx:y"
while getopts "$optstring" i $ALLARGS; do
case "$i" in
h)
@ -1640,6 +1641,9 @@ while getopts "$optstring" i $ALLARGS; do
w)
showwho=1
;;
W)
showwho=2
;;
x)
MYAIR="${OPTARG}"
;;
@ -1679,7 +1683,7 @@ else
exit 1
fi
if [[ $showwho -ne 1 ]]; then
if [[ $showwho -eq 0 ]]; then
if [[ -z $MYAIR ]]; then
MYAIR=$(which myair)
if [[ $? -ne 0 ]]; then
@ -1724,6 +1728,31 @@ if [[ $showwho -eq 1 ]]; then
done
echo
exit 0
elif [[ $showwho -eq 2 ]]; then
# get max device hostname length
maxlen=1
for x in ${ownerhost[@]}; do
[[ ${#x} -gt $maxlen ]] && maxlen=$((${#x} + 3))
done
# get a list of all devices
TFORMAT="${BOLD}${UNDERLINE}%-${maxlen}s%-16s${PLAIN}\n"
HFORMAT="%-${maxlen}s${GREEN}%-16s${PLAIN}\n"
AFORMAT="%-${maxlen}s${RED}%-16s${PLAIN}\n"
alldevs=$(echo "${ownerhost[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
echo
printf "$TFORMAT" "Devices" "Availability"
for x in $alldevs; do
if canping "${x}"; then
thisform="$HFORMAT"
str="Available"
else
thisform="$AFORMAT"
str="Unavailable"
fi
printf "$thisform" "${x}" "$str"
done
echo
exit 0
fi