Update offsite-power-check.sh

This commit is contained in:
2023-11-05 21:54:28 -06:00
parent 7ee9c07e64
commit 46dd4d25f3

View File

@@ -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
}