Fix -A option

Add -b option to help debug time-based rule processing
This commit is contained in:
Rob Pearce 2023-04-10 19:52:05 +10:00
parent 3f31ede396
commit c41c57e228
1 changed files with 18 additions and 6 deletions

View File

@ -34,6 +34,7 @@ GREY="\033[2;37m"
WHITE="\033[37m"
LINK="$BLUE$UNDERLINE"
RULEDB=1
function enable_cronmode() {
cronmode=1
@ -56,6 +57,7 @@ function usage() {
echo " Modifies aircon based on configured parameters in $DEFAULT_CONFIGFILE."
echo
echo " -a file Specify location of arping binary (default: $ARPING_DEF)."
echo " -b Rule debug mode. Show processing of time rules."
echo " -A db Log actions to given influxdb database."
echo " -c Cron mode. Only show output if actions were taken."
echo " -D dbhost Specify influxdb hostname for -I and -A options (default: localhost)"
@ -1024,6 +1026,10 @@ function processtimeconditions() {
local ok=0
local nonmatches=0
local rv
local db=0
if [[ $RULEDB -eq 1 ]]; then
db=1
fi
if [[ $1 == "-c" ]]; then
keepgoing=1
shift 1
@ -1031,11 +1037,12 @@ function processtimeconditions() {
line="$*"
timestr_human=""
timestr=${line%% *}
timestr=${timestr:1}
timestr=${line%% *} # only process first word
timestr=${timestr:1} # strip leading @
[[ $db -eq 1 ]] && info "${BOLD}Processing line: '$line'"
IFS=';' read -ra allconds <<< "$timestr"
for cond in ${allconds[@]} ; do
[[ $db -eq 1 ]] && info "Processing condition: '$cond'"
[[ $db -eq 1 ]] && info " processing condition: '$cond'"
IFS='-' read -ra ttok <<< "$cond"
if [[ ${#ttok[@]} == 1 ]]; then
stype[0]=$(getstrtype ${ttok[0]})
@ -1098,10 +1105,12 @@ function processtimeconditions() {
[[ $db -eq 1 ]] && info " check if $nowh is between $starth and $endh"
ok=0
if [[ $(echo "$starth < $endh" | bc) == "1" ]]; then
[[ $db -eq 1 ]] && info " time period does NOT span midnight"
if [[ $(echo "$nowh >= $starth" | bc) == "1" && $(echo "$nowh <= $endh" | bc) == "1" ]]; then
ok=1
fi
elif [[ $(echo "$starth > $endh" | bc) == "1" ]]; then
[[ $db -eq 1 ]] && info " time period spans midnight"
if [[ $(echo "$nowh <= $endh" | bc) == "1" || $(echo "$nowh >= $starth" | bc) == "1" ]]; then
ok=1
fi
@ -1324,7 +1333,7 @@ function canping() {
local n hname ip db host success=0 mac
local os arprv arpres
os=$(uname -s)
db=1
db=0
if [[ $db -eq 1 ]]; then
info "canping() for:"
for host in $*; do
@ -1809,12 +1818,15 @@ fi
ALLARGS="$ALLARGS $*"
optstring="A:cD:f:hHi:I:k:l:Lo:pmRsSt:T:wWx:y"
optstring="A:bcD:f:hHi:I:k:l:Lo:pmRsSt:T:wWx:y"
while getopts "$optstring" i $ALLARGS; do
case "$i" in
a)
A)
ARPING=${OPTARG}
;;
b)
ruledb=1
;;
h)
usage;
exit 1;