From 656aef8003994c4888845a714d35b5210f618913 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Wed, 8 Nov 2023 19:13:04 -0600 Subject: [PATCH] Update offsite-power-check.sh --- offsite-power-check.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/offsite-power-check.sh b/offsite-power-check.sh index 37e6a745..e975a11d 100755 --- a/offsite-power-check.sh +++ b/offsite-power-check.sh @@ -20,6 +20,7 @@ WAIT_TO_POWER_SERVERS=5 #minutes LOG_INTERVAL_NORMAL=60 #minutes LOG_INTERVAL_ABNORMAL=30 #seconds LOG_INTERVAL_CHARGING=120 #seconds +RENOTIFY_LOWPOWER=10 #minutes PW_OFFSITEHOSTS="10.2.1.11" # PW_OFFSITEHOSTS="10.2.1.11 10.2.1.12" @@ -68,14 +69,12 @@ $(date)" fi if [ ${OFFSITE_VOLTIN%.*} -gt 105 ]; then - if [ "${charging}" == "true" ] && [ ${OFFSITE_BATT_CAP%.*} -eq 100 ]; then + if [ -f ${PW_TMPFOLDER}/power.offsite.charging ] && [ ${OFFSITE_BATT_CAP%.*} -eq 100 ]; then echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'volts - ${OFFSITE_BATT_CAP}% Battery - Charging Complete" >> ${PW_LOGFILE} SENDNOTICE "OFFSITE POWER" "Batteries are fully recharged" - charging=false - elif [ ${OFFSITE_BATT_CAP%.*} -lt 100 ]; then - charging=true - else - charging=false + rm -f ${PW_TMPFOLDER}/power.offsite.charging + elif [ ! -f ${PW_TMPFOLDER}/power.offsite.charging ]; then + touch ${PW_TMPFOLDER}/power.offsite.charging fi if [ -f ${PW_TMPFOLDER}/power.offsite.ac.low ]; then if [ -f ${PW_TMPFOLDER}/power.offsite.off ]; then @@ -107,10 +106,12 @@ $(date)" echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'volts - ${OFFSITE_WATTS}'watts - ${OFFSITE_BATT_CAP}% Battery - ${OFFSITE_BATT_RUNTIME}'mins - Normal" >> ${PW_LOGPOWER} fi else - if [ ! -f ${PW_TMPFOLDER}/power.offsite.ac.low ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low)) -gt 240 ]; then + [ ! -f ${PW_TMPFOLDER}/power.offsite.ac.low ] && touch ${PW_TMPFOLDER}/power.offsite.ac.low + + if [ ! -f ${PW_TMPFOLDER}/power.offsite.ac.low.notice ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low.notice)) -gt ${RENOTIFY_LOWPOWER} ]; then # echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'volts - ${OFFSITE_BATT_CAP}% Battery - Powering LOW/OFF!" >> ${PW_LOGFILE} SENDNOTICE "OFFSITE POWER - POWER OFF/LOW!!" "Power off or low voltage detected" 1 - touch ${PW_TMPFOLDER}/power.offsite.ac.low + touch ${PW_TMPFOLDER}/power.offsite.ac.low.notice fi if ([ ${OFFSITE_BATT_CAP%.*} -lt ${SHUTDOWNSERVERS_AT_LOAD} ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low)) -ge $(echo "scale=2; ${SHUTDOWNSERVERS_AFTER}*60" | bc) ]) && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then