Update offsite-power-check.sh

This commit is contained in:
2023-11-05 22:03:52 -06:00
parent 77707161e6
commit 0282040f98

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/.*: //')
@@ -33,20 +34,15 @@ PWO_START(){
OFFSITE_BATT_RUNTIME=`echo "scale=2; ${OFFSITE_BATT_RUNTIME}/60" | bc`
OFFSITE_BATT_CAP=$(echo "${upsinfo}" | grep 'battery.charge:' | sed 's/.*: //')
SENDNOTICE(){
TITLE=${1}
MESSAGE="${2}\n\nBATTERY CHARGE: ${OFFSITE_BATT_CAP}%25\nBATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins\nAC VOLTAGE: ${OFFSITE_VOLTIN}'Volts\n\n$(date)"
MSGSOUND=Cosmic
if [ "${3}" = "1" ]; then PRIORITY="${3}"; MSGSOUND=siren
elif [ "${3}" != "" ]; then PRIORITY=${3}; else PRIORITY=0; fi
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 >/dev/null 2>&1
curl -s --form-string "token=${PUSHOVER_APP_TOKEN}" --form-string "user=${PUSHOVER_USER_TOKEN}" \
--form-string "message=${2}
MESSAGE="${2}
BATTERY CHARGE: ${OFFSITE_BATT_CAP}%25
BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins
AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts
$(date)" https://api.pushover.net/1/messages.json
$(date)"
if [ "${3}" = "1" ]; then PRIORITY="${3}"; MSGSOUND=siren; elif [ "${3}" != "" ]; then PRIORITY=${3}; else PRIORITY=0; fi
curl -sd "token=${PUSHOVER_APP_TOKEN}&user=${PUSHOVER_USER_TOKEN}&message=${MESSAGE}&title=${1}&priority=${PRIORITY}&sound=cosmic" https://api.pushover.net/1/messages.json >/dev/null 2>&1
}
if [ "${startup}" == "true" ]; then
SENDNOTICE "OFFSITE POWER MONITOR" "Service starting"
@@ -99,6 +95,7 @@ PWO_START(){
/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
}