Update offsite-power-check.sh
This commit is contained in:
@@ -26,6 +26,7 @@ fi
|
|||||||
PWO_START(){
|
PWO_START(){
|
||||||
startup=true
|
startup=true
|
||||||
while true; do
|
while true; do
|
||||||
|
start=`date +%s`
|
||||||
upsinfo=$(upsc CP1500PFCLCD)
|
upsinfo=$(upsc CP1500PFCLCD)
|
||||||
if [ "$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //')" != "" ]; then
|
if [ "$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //')" != "" ]; then
|
||||||
OFFSITE_VOLTIN=$(echo "${upsinfo}" | grep 'input.voltage:' | sed 's/.*: //')
|
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_RUNTIME=`echo "scale=2; ${OFFSITE_BATT_RUNTIME}/60" | bc`
|
||||||
OFFSITE_BATT_CAP=$(echo "${upsinfo}" | grep 'battery.charge:' | sed 's/.*: //')
|
OFFSITE_BATT_CAP=$(echo "${upsinfo}" | grep 'battery.charge:' | sed 's/.*: //')
|
||||||
SENDNOTICE(){
|
SENDNOTICE(){
|
||||||
TITLE=${1}
|
MESSAGE="${2}
|
||||||
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}
|
|
||||||
|
|
||||||
BATTERY CHARGE: ${OFFSITE_BATT_CAP}%25
|
BATTERY CHARGE: ${OFFSITE_BATT_CAP}%25
|
||||||
BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins
|
BATT RUNTIME: ${OFFSITE_BATT_RUNTIME}'Mins
|
||||||
AC VOLTAGE: ${OFFSITE_VOLTIN}'Volts
|
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
|
if [ "${startup}" == "true" ]; then
|
||||||
SENDNOTICE "OFFSITE POWER MONITOR" "Service starting"
|
SENDNOTICE "OFFSITE POWER MONITOR" "Service starting"
|
||||||
@@ -99,6 +95,7 @@ PWO_START(){
|
|||||||
/usr/local/etc/rc.d/nut.sh restart
|
/usr/local/etc/rc.d/nut.sh restart
|
||||||
sleep 10s
|
sleep 10s
|
||||||
fi
|
fi
|
||||||
|
end=`date +%s`; runtime=$((end-start)); echo -e "\nruntime: ${runtime}\nsleeping for 5secs ... "
|
||||||
sleep 5s
|
sleep 5s
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user