This commit is contained in:
2023-05-15 22:04:29 -05:00
parent ec1b91cc2b
commit 03407d44e2
2 changed files with 49 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERS='2.142-05152023'
VERS='2.143-05152023'
noheader=' update '
@@ -18,8 +18,8 @@ FOLDER='/opt/idssys/powerwall'
LOGFOLDER=${FOLDER}/logs
[ ! -d ${LOGFOLDER} ] && mkdir ${LOGFOLDER}
logfile=${LOGFOLDER}/logfile
logacv=${LOGFOLDER}/log-acv
[ ! -f ${logacv} ] && touch ${logacv}
logpower=${LOGFOLDER}/log-acv
[ ! -f ${logpower} ] && touch ${logpower}
declare -A TEMP_THRESHOLDS
@@ -37,8 +37,8 @@ SENSOR_ID['ServerRoomTH']='2'
SENSOR_ID['RaspberryPI-CPU']='6'
declare -A POWERWALL_SERVICES
POWERWALL_SERVICES['Temp']='monitor-temp'
POWERWALL_SERVICES['ACV']='monitor-acv'
POWERWALL_SERVICES['temp']='monitor-temp'
POWERWALL_SERVICES['power']='monitor-power'
POWERWALL_SERVICES['powerlogger']='monitor-powerlogger'
declare -A ESXI_HOST_NAMES

View File

@@ -209,7 +209,7 @@ CHECKPOWER(){
[ "${action}" != "" ] && echo
}
CHECKACV_SERVICE(){
CHECKPOWER_SERVICE(){
voltstatus=0
battstatus=0
while true; do
@@ -220,43 +220,43 @@ CHECKACV_SERVICE(){
datetime=`date +'%Y-%m-%d %H:%M:%S'`
if [ ${INPUTACV} -ge ${min_acvolt} ]; then
if [ $voltstatus -eq 3 ]; then
echo "($datetime) - ${INPUTACV}V - Back to Normal Voltage" >> ${logacv}
echo "($datetime) - ${INPUTACV}V - Back to Normal Voltage" >> ${logpower}
SENDNOTICE "POWER NOMINAL AGAIN" "($datetime) Normal voltage detected
VOLTAGE: ${INPUTACV}V"
echo "($datetime) alert sent" >> ${logacv}
echo "($datetime) alert sent" >> ${logpower}
echo -e "($datetime) - ${INPUTACV}V - POWER NOMINAL AGAIN" >> ${logfile}
battstatus=0
else
errtime=$(expr `date +%s` - $(stat -c %Y ${logacv}))
[ $errtime -ge 3600 ] && echo "($datetime) - ${INPUTACV}V - Normal Voltage" >> ${logacv}
errtime=$(expr `date +%s` - $(stat -c %Y ${logpower}))
[ $errtime -ge 3600 ] && echo "($datetime) - ${INPUTACV}V - Normal Voltage" >> ${logpower}
if [ $voltstatus -eq 0 ]; then
SENDNOTICE "Power Nominal" "($datetime) Service Startup
Normal voltage detected
VOLTAGE: ${INPUTACV}V
BATT VOLTAGE: ${BATTVOLT}V"
echo "($datetime) - Input: ${INPUTACV}V - Service Startup - Normal voltage detected" >> ${logacv}
echo "($datetime) - Input: ${INPUTACV}V - Service Startup - Normal voltage detected" >> ${logpower}
echo -e "($datetime) - ${INPUTACV}V / ${BATTVOLT}V - Service Startup - Normal Voltage" >> ${logfile}
fi
fi
voltstatus=1
else
echo "($datetime) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${logacv}
echo "($datetime) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${logpower}
echo -e "($datetime) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${logfile}
if [ $voltstatus -lt 3 ]; then
SENDNOTICE "POWER ALERT - POWER OFF/LOW POWER!!" "($datetime) Power off or low voltage detected
VOLTAGE: ${INPUTACV}V
BATT VOLTAGE: ${BATTVOLT}V" 1
echo "($datetime) alert sent" >> ${logacv}
echo "($datetime) alert sent" >> ${logpower}
last_battvolt=$BATTVOLT
fi
voltstatus=3
fi
if [ ${BATTVOLT%.*} -lt ${min_battvolt} ] && [ ${BATTVOLT%.*} -gt ${min_battvolt_sys} ]; then
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${logacv}
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${logpower}
echo -e "($datetime) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${logfile}
if [ $battstatus -lt 2 ] && [ ${INPUTACV} -lt ${min_acvolt} ]; then
echo "($datetime) - ${BATTVOLT}V - Shutting down main servers..." >> ${logacv}
echo "($datetime) - ${BATTVOLT}V - Shutting down main servers..." >> ${logpower}
SENDNOTICE "BATT-VOLT LOW: SHUTDOWN SERVERS" "($datetime) Battery Voltage LOW: ${BATTVOLT}V
Shutting down main servers" 1
SHUTDOWN_MAIN server
@@ -264,10 +264,10 @@ CHECKACV_SERVICE(){
fi
elif [ ${BATTVOLT%.*} -le ${min_battvolt_sys} ]; then
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${logacv}
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${logpower}
echo -e "($datetime) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${logfile}
if [ $battstatus -lt 3 ] && [ ${INPUTACV} -lt ${min_acvolt} ]; then
echo "($datetime) - ${BATTVOLT}V - Shutting down all remaining servers..." >> ${logacv}
echo "($datetime) - ${BATTVOLT}V - Shutting down all remaining servers..." >> ${logpower}
SENDNOTICE "BATT-VOLT REALLY LOW: SHUTDOWN SERVERS" "($datetime) Battery Voltage REALLY LOW: ${BATTVOLT}V
Shutting down all servers" 1
SHUTDOWN_SYS server
@@ -276,10 +276,10 @@ CHECKACV_SERVICE(){
fi
else
errtime=$(expr `date +%s` - $(stat -c %Y ${logacv}))
[ $errtime -ge 3600 ] && echo "($datetime) - ${BATTVOLT}V - Battery Voltage" >> ${logacv}
errtime=$(expr `date +%s` - $(stat -c %Y ${logpower}))
[ $errtime -ge 3600 ] && echo "($datetime) - ${BATTVOLT}V - Battery Voltage" >> ${logpower}
if [ $battstatus -eq 0 ]; then
echo "($datetime) - Battery: ${BATTVOLT}V - Service Startup - Normal voltage detected" >> ${logacv}
echo "($datetime) - Battery: ${BATTVOLT}V - Service Startup - Normal voltage detected" >> ${logpower}
fi
battstatus=1
@@ -290,7 +290,7 @@ CHECKACV_SERVICE(){
[ $volt_diff -lt 0 ] && temp_diff=$(($volt_diff * -1))
if [ $volt_diff -gt 0 ]; then
SENDNOTICE "BATTERY VOLTAGE CHANGE" "($datetime) Battery Voltage: ${BATTVOLT}V"
echo -e "($datetime) - ${BATTVOLT}V - Battery Voltage Change" >> ${logacv}
echo -e "($datetime) - ${BATTVOLT}V - Battery Voltage Change" >> ${logpower}
last_battvolt=$BATTVOLT
fi
else
@@ -564,25 +564,36 @@ fi
shutdownhost) SHUTDOWN_SERVER ${2};;
shutdown_servers) SHUTDOWN_SERVERS ${2};;
checktemp_service)
if [ "${2}" = "stop" ]; then
STOP_SERVICE Temp
for SENSOR in ${!SENSOR_ID[@]}; do
logtemp=${LOGFOLDER}/log-temp-${SENSOR}
echo "(`date +'%Y-%m-%d %H:%M:%S'`) - ${SENSOR} - Service Stopped" >> ${logtemp}
done
else
CHECKTEMP_SERVICE
fi
;;
checkacv_service)
if [ "${2}" = "stop" ]; then
STOP_SERVICE ACV
echo "(`date +'%Y-%m-%d %H:%M:%S'`) Service Stopped" >> ${logacv}
else
CHECKACV_SERVICE
service)
if [ "${3}" = "start" ] || [ "${3}" = "" ]; then
[ "${2}" = "temp"] CHECKTEMP_SERVICE
[ "${2}" = "power"] CHECKPOWER_SERVICE
[ "${2}" = "powerlogger"] CHECKTEMP_SERVICE
elif [ "${3}" = "stop" ]; then
if [ "${2}" = "temp"]; then
STOP_SERVICE temp
for SENSOR in ${!SENSOR_ID[@]}; do
logtemp=${LOGFOLDER}/log-temp-${SENSOR}
echo "(`date +'%Y-%m-%d %H:%M:%S'`) - ${SENSOR} - Service Stopped" >> ${logtemp}
done
elif [ "${2}" = "power"]; then
STOP_SERVICE ACV
echo "(`date +'%Y-%m-%d %H:%M:%S'`) Service Stopped" >> ${logpower}
elif [ "${2}" = "powerlogger"]; then
STOP_SERVICE powerlogger
fi
elif [ "${3}" = "restart" ]; then
/usr/local/bin/powerwall service ${2} stop
slep 2s
/usr/local/bin/powerwall service ${2} start
fi
;;
powerlogger_service)
if [ "${2}" = "stop" ]; then
STOP_SERVICE powerlogger