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,11 +28,11 @@ $(date)"
else
PRIORITY=0
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
}
while true; do
START(){
while true; do
upsinfo=$(upsc CP1500PFCLCD)
if [ "${upsinfo}" != "" ]; then
OFFSITE_VOLTIN=$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //')
@@ -52,15 +52,14 @@ VOLTAGE: ${OFFSITE_VOLTIN}'Volts"
if [ ! -f ${PW_TMPFOLDER}/power.offsite.restored ]; then
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"
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
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
[ $(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
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}
@@ -72,11 +71,12 @@ BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins" 1
fi
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
# SHUTDOWN_OFFSITE &
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
[ $(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
else
@@ -85,7 +85,19 @@ BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins" 1
sleep 10s
fi
sleep 10s
done
done
}
STOP(){
}
case ${action} in
start) START;;
stop) STOP;;
esac
exit 0