Update offsite-power-check.sh

This commit is contained in:
2023-11-05 17:50:17 -06:00
parent 54af4c792c
commit b7c5ee4b80

View File

@@ -28,10 +28,10 @@ $(date)"
else else
PRIORITY=0 PRIORITY=0
fi fi
echo "SENDING MESSAGE!!!!!!"
curl -d "token=${PUSHOVER_APP_TOKEN}&user=${PUSHOVER_USER_TOKEN}&message=${MESSAGE}&title=${TITLE}&priority=${PRIORITY}&sound=${MSGSOUND}" https://api.pushover.net/1/messages.json curl -d "token=${PUSHOVER_APP_TOKEN}&user=${PUSHOVER_USER_TOKEN}&message=${MESSAGE}&title=${TITLE}&priority=${PRIORITY}&sound=${MSGSOUND}" https://api.pushover.net/1/messages.json
} }
START(){
while true; do while true; do
upsinfo=$(upsc CP1500PFCLCD) upsinfo=$(upsc CP1500PFCLCD)
if [ "${upsinfo}" != "" ]; then if [ "${upsinfo}" != "" ]; then
@@ -52,15 +52,14 @@ VOLTAGE: ${OFFSITE_VOLTIN}'Volts"
if [ ! -f ${PW_TMPFOLDER}/power.offsite.restored ]; then if [ ! -f ${PW_TMPFOLDER}/power.offsite.restored ]; then
touch ${PW_TMPFOLDER}/power.offsite.restored touch ${PW_TMPFOLDER}/power.offsite.restored
elif [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.restored)) -gt 60 ]; then elif [ $(expr `date +%s` - $(stat -f %m ${PW_TMPFOLDER}/power.offsite.restored)) -gt 30 ]; then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_BATT_CAP}% Battery - Powering Hosts Back on After Power Outage!" >> ${PW_LOGFILE}
SENDNOTICE2 "OFFSITE HOST POWER" "Powering offsite host(s) back on after power was restored" SENDNOTICE2 "OFFSITE HOST POWER" "Powering offsite host(s) back on after power was restored"
ipmitool -I lanplus -H 10.2.1.21 -U ${PW_ESXI_USER} -P "${PW_ESXI_PASS}" chassis power on 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.* rm -f ${PW_TMPFOLDER}/power.offsite.*
fi fi
else
[ $(expr `date +%s` - $(stat -f %m ${PW_LOGPOWER})) > 300 ] && echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - Offsite Normal Voltage" >> ${PW_LOGPOWER}
fi fi
[ $(expr `date +%s` - $(stat -f %m ${PW_LOGPOWER})) -gt 300 ] && echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - ${OFFSITE_BATT_CAP}% Batt - Normal" >> ${PW_LOGPOWER}
else else
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - OFFSITE POWER OFF/LOW POWER" >> ${PW_LOGPOWER} echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - OFFSITE POWER OFF/LOW POWER" >> ${PW_LOGPOWER}
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - OFFSITE POWER OFF/LOW POWER" >> ${PW_LOGFILE} echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - OFFSITE POWER OFF/LOW POWER" >> ${PW_LOGFILE}
@@ -72,11 +71,12 @@ BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins" 1
fi fi
if [ ${OFFSITE_BATT_CAP%.*} -lt 95 ] && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then if [ ${OFFSITE_BATT_CAP%.*} -lt 95 ] && [ ! -f ${PW_TMPFOLDER}/power.offsite.off ]; then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_BATT_CAP}% Battery - Powering Down Hosts!" >> ${PW_LOGFILE}
SENDNOTICE2 "OFFSITE HOST POWER" "Powering DOWN offsite host(s) due to power outage" 1 SENDNOTICE2 "OFFSITE HOST POWER" "Powering DOWN offsite host(s) due to power outage" 1
# SHUTDOWN_OFFSITE &
touch ${PW_TMPFOLDER}/power.offsite.off touch ${PW_TMPFOLDER}/power.offsite.off
echo "SHUTTING DOWN HOST" ssh root@10.2.1.11 /vmfs/volumes/652c94ef-ee49895b-365d-00109b3fea40/.SCRIPTS/esxi-shutdown2.sh &
fi fi
[ $(expr `date +%s` - $(stat -f %m ${PW_LOGPOWER})) -gt 300 ] && echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${OFFSITE_VOLTIN}'Volts - ${OFFSITE_BATT_CAP}% Batt - LOW POWER!!" >> ${PW_LOGPOWER}
fi fi
else else
@@ -86,6 +86,18 @@ BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins" 1
fi fi
sleep 10s sleep 10s
done done
}
STOP(){
}
case ${action} in
start) START;;
stop) STOP;;
esac
exit 0 exit 0