From 46dd4d25f3cba0963c4607e8c688b2e23d51d42e Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 5 Nov 2023 21:54:28 -0600 Subject: [PATCH] Update offsite-power-check.sh --- offsite-power-check.sh | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/offsite-power-check.sh b/offsite-power-check.sh index ce6d1064..b33f38ff 100755 --- a/offsite-power-check.sh +++ b/offsite-power-check.sh @@ -26,6 +26,7 @@ fi PWO_START(){ startup=true while true; do + start=`date +%s` upsinfo=$(upsc CP1500PFCLCD) if [ "$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //')" != "" ]; then OFFSITE_VOLTIN=$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //') @@ -55,11 +56,7 @@ $(date)" if [ -f ${PW_TMPFOLDER}/power.offsite.ac.low ]; then if [ -f ${PW_TMPFOLDER}/power.offsite.off ]; then echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - ${OFFSITE_BATT_CAP}% Battery - Offsite Power Restored" >> ${PW_LOGPOWER} - SENDNOTICE "OFFSITE POWER" "Power restored! Will wait ${WAIT_TO_POWER_SERVERS}'Mins before turning host(s) back on. - -BATTERY CHARGE: ${OFFSITE_BATT_CAP}'(percent) -BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins -AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" + SENDNOTICE "OFFSITE POWER" "Power restored! Will wait ${WAIT_TO_POWER_SERVERS}'Mins before turning host(s) back on" fi rm -f ${PW_TMPFOLDER}/power.offsite.ac.* @@ -70,11 +67,7 @@ AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" elif [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.restored)) -gt $(echo "scale=2; ${WAIT_TO_POWER_SERVERS}*60" | bc) ]; then echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - ${OFFSITE_BATT_CAP}% Battery - Powering Hosts ON After Power Outage" >> ${PW_LOGFILE} - SENDNOTICE "OFFSITE HOST POWER" "Powering offsite host(s) back on after power outage - -BATTERY CHARGE: ${OFFSITE_BATT_CAP}'(percent) -BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins -AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" + SENDNOTICE "OFFSITE HOST POWER" "Powering offsite host(s) back on after power outage" ([ "$TEST" = "" ] || [ "$TEST" = "full" ]) && ipmitool -I lanplus -H 10.2.1.21 -U ${PW_ESXI_USER} -P "${PW_ESXI_PASS}" chassis power on & rm -f ${PW_TMPFOLDER}/power.offsite.* fi @@ -86,21 +79,13 @@ AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" else if [ ! -f ${PW_TMPFOLDER}/power.offsite.ac.low ] || [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.ac.low)) -gt 240 ]; 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 - -BATTERY CHARGE: ${OFFSITE_BATT_CAP}'(percent) -BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins -AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" 1 + SENDNOTICE "OFFSITE POWER - POWER OFF/LOW!!" "Power off or low voltage detected" 1 touch ${PW_TMPFOLDER}/power.offsite.ac.low fi if [ ${OFFSITE_BATT_CAP%.*} -lt ${SHUTDOWNSERVERS_AT_LOAD} ] && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - ${OFFSITE_BATT_CAP}% Battery - Powering Down Hosts!" >> ${PW_LOGFILE} - SENDNOTICE "OFFSITE HOST POWER" "Powering DOWN offsite host(s) due to power outage - -BATTERY CHARGE: ${OFFSITE_BATT_CAP}'(percent) -BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins -AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" 1 + SENDNOTICE "OFFSITE HOST POWER" "Powering DOWN offsite host(s) due to power outage" 1 touch ${PW_TMPFOLDER}/power.offsite.off ([ "$TEST" = "" ] || [ "$TEST" = "full" ]) && ssh root@10.2.1.11 /vmfs/volumes/652c94ef-ee49895b-365d-00109b3fea40/.SCRIPTS/esxi-shutdown2.sh & fi @@ -113,6 +98,7 @@ AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts" 1 /usr/local/etc/rc.d/nut.sh restart sleep 10s fi + end=`date +%s`; runtime=$((end-start)); echo -e "\nruntime: ${runtime}\nsleeping for 5secs ... " sleep 5s done }