Update powerwall.sh
This commit is contained in:
215
powerwall.sh
215
powerwall.sh
@@ -61,7 +61,7 @@ CHECKTEMP(){
|
||||
# echo "HERE: ${SENSOR} (${PW_SENSOR_ID[${SENSOR}]}) - ${vSENSOR// /_}"
|
||||
|
||||
reading=$(CHECKTEMPSENSOR ${SENSOR} ${temp_c} ${temp_warn} ${temp_crit} ${vSENSOR// /_} ${1})
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#vSENSOR} - 1`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#vSENSOR} - 1`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -e "${idsCL[LightCyan]} ${vSENSOR}${spc}${idsCL[Default]}: ${reading}"
|
||||
|
||||
done
|
||||
@@ -74,7 +74,7 @@ CHECKTEMP(){
|
||||
|
||||
# if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
|
||||
# SENDNOTICE "${vHOSTiDRACIP} ERROR" "${vHOSTNAME} Host is down" 1
|
||||
# echo "($datetime) - ${vHOSTiDRACIP} - ${vHOSTNAME} Host is down" >> ${logtemp}
|
||||
# echo "(${datetime}) - ${vHOSTiDRACIP} - ${vHOSTNAME} Host is down" >> ${logtemp}
|
||||
# touch ${PW_TMPFOLDER}/${EHOST}.down
|
||||
# fi
|
||||
fi
|
||||
@@ -82,7 +82,7 @@ CHECKTEMP(){
|
||||
else
|
||||
echo -en "${idsCL[Yellow]}Pulling data and calculating averages for '${SENSOR}' ..."
|
||||
reading=$(CHECKTEMPSENSOR ${SENSOR} . . . . ${1})
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -e "\r\033[K${idsCL[LightCyan]}${idsST[Bold]}${SENSOR}${idsST[Reset]}${spc}${idsCL[Default]}: ${reading}"
|
||||
fi
|
||||
echo
|
||||
@@ -108,7 +108,7 @@ CHECKTEMPSENSOR(){
|
||||
|
||||
if [ "${PW_SENSOR_TYPE[${1}]}" == "mqtt" ]; then
|
||||
mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1`
|
||||
echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
|
||||
echo ${mqtt_message} | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
|
||||
|
||||
elif [ "${PW_SENSOR_TYPE[${1}]}" == "system" ]; then
|
||||
temp_c=$(vcgencmd measure_temp)
|
||||
@@ -129,11 +129,11 @@ CHECKTEMPSENSOR(){
|
||||
|
||||
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
|
||||
temp_f=$(bc <<< "scale=1; ${temp_c}*1.8+32")
|
||||
#echo "$temp_c -> $temp_f"
|
||||
c=0; spct=''; spc1=`expr 6 - ${#temp_f}`; until [ $c = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done
|
||||
#echo "${temp_c} -> ${temp_f}"
|
||||
c=0; spct=''; spc1=`expr 6 - ${#temp_f}`; until [ ${c} = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done
|
||||
|
||||
if [ "${average}" != "" ]; then
|
||||
c=0; spca=''; spc1=`expr 6 - ${#average}`; until [ $c = ${spc1} ]; do spca="${spca} "; c=`expr ${c} + 1`; done
|
||||
c=0; spca=''; spc1=`expr 6 - ${#average}`; until [ ${c} = ${spc1} ]; do spca="${spca} "; c=`expr ${c} + 1`; done
|
||||
if [ "${average}" == "" ]; then
|
||||
averagedisp="${idsCL[Green]}"
|
||||
elif [ $(bc -l <<< "${average} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${average} < ${temp_crit}") -eq 1 ]; then
|
||||
@@ -147,15 +147,15 @@ CHECKTEMPSENSOR(){
|
||||
averagedisp=' '
|
||||
fi
|
||||
|
||||
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then
|
||||
if [ $(bc -l <<< "${temp_f} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}") -eq 1 ]; then
|
||||
echo -en "${idsCL[Yellow]}WARNING (${spct}${temp_f}'F / ${spca}${averagedisp}${idsCL[Yellow]})${idsCL[Default]}"
|
||||
elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then
|
||||
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit}") -eq 1 ]; then
|
||||
echo -en "${idsCL[Red]}CRITICAL (${spct}${temp_f}'F / ${spca}${averagedisp}${idsCL[Red]})${idsCL[Default]}"
|
||||
else
|
||||
echo -en "${idsCL[Green]}Normal (${spct}${temp_f}'F / ${spca}${averagedisp}${idsCL[Green]})${idsCL[Default]}"
|
||||
fi
|
||||
tmp="${spct}${temp_f}"
|
||||
c=0; spc=''; spc1=`expr 8 - ${#tmp}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr 8 - ${#tmp}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
[ ${#temp_warn} == 2 ] && spcw=' ' || spcw=' '
|
||||
[ ${#temp_crit} == 2 ] && spcc=' ' || spcc=' '
|
||||
echo -e "${spc}[${spcw}${idsCL[Yellow]}${temp_warn}'F${idsCL[Default]} /${spcc}${idsCL[Red]}${temp_crit}'F=>${idsCL[Default]} ]"
|
||||
@@ -208,7 +208,7 @@ CHECKTEMP_SERVICE(){
|
||||
# if ([ "${PW_REMOTE_SENSORS[${SENSORa}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSORa}]})" != "false" ]); then
|
||||
if [ -f ${PW_TMPFOLDER}/${SENSORa}.down ]; then
|
||||
SENDNOTICE "${SENSORa} Online" "${SENSORa} Sensor is back online"
|
||||
echo "($datetime) - ${SENSORa} - Sensor is back online" >> ${logtemp}
|
||||
echo "(${datetime}) - ${SENSORa} - Sensor is back online" >> ${logtemp}
|
||||
rm -f ${PW_TMPFOLDER}/${SENSORa}.down
|
||||
|
||||
fi
|
||||
@@ -241,8 +241,8 @@ CHECKTEMP_SERVICE(){
|
||||
|
||||
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "mqtt" ]; then
|
||||
mqtt_message=`${mqtt_conn} -t tele/${SENSOR}/SENSOR -C 1`
|
||||
echo $mqtt_message | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h
|
||||
echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
|
||||
echo ${mqtt_message} | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h
|
||||
echo ${mqtt_message} | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
|
||||
|
||||
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ]; then
|
||||
temp_c=$(vcgencmd measure_temp)
|
||||
@@ -273,14 +273,14 @@ CHECKTEMP_SERVICE(){
|
||||
|
||||
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
||||
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
|
||||
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
|
||||
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
|
||||
if [ -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ]; then
|
||||
SENDNOTICE "${SENSOR} Data" "${SENSOR} is reporting data again"
|
||||
echo "($datetime) - ${SENSOR} - Sensor is reporting data again" >> ${logtemp}
|
||||
echo "(${datetime}) - ${SENSOR} - Sensor is reporting data again" >> ${logtemp}
|
||||
rm -f ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
||||
|
||||
fi
|
||||
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
|
||||
temp_f=`echo "scale=2; ${temp_c}*1.8 + 32" | bc`
|
||||
# echo "HERE: ${SENSOR} - ${temp_f} - ${temp_warn} - ${temp_crit} - ${temp_crit_sys}"
|
||||
|
||||
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" != "esxi" ]; then
|
||||
@@ -290,19 +290,20 @@ CHECKTEMP_SERVICE(){
|
||||
fi
|
||||
|
||||
if [ "${last_temp[${SENSOR}]}" != "" ]; then
|
||||
temp_diff=`expr ${last_temp[${SENSOR}]%.*} - ${temp_f%.*}`
|
||||
[ $temp_diff -lt 0 ] && temp_diff=$(($temp_diff * -1))
|
||||
temp_diff=`echo "scale=2; ${last_temp[${SENSOR}]}-${temp_f}" | bc`
|
||||
[ $(bc -l <<< "${temp_diff} < 0") -eq 1 ] && temp_diff=`echo "scale=2; ${temp_diff}*-1" | bc`
|
||||
|
||||
else
|
||||
last_temp[${SENSOR}]=0
|
||||
temp_diff=0
|
||||
fi
|
||||
|
||||
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then
|
||||
if [ $(bc -l <<< "${temp_f} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}") -eq 1 ]; then
|
||||
touch ${PW_TMPFOLDER}/temp.warn
|
||||
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP WARNING" "($datetime) WARNING TEMP: ${temp_f}'F - (Difference of ${temp_diff}')" 1
|
||||
last_temp[${SENSOR}]=$temp_f
|
||||
echo "($datetime) - ${temp_f}'F - WARNING TEMP - (Difference of ${temp_diff}')" >> ${logtemp}
|
||||
if [ $(bc -l <<< "${temp_diff} > 1") -eq 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP WARNING" "(${datetime}) WARNING TEMP: ${temp_f}'F - (Difference of ${temp_diff}')" 1
|
||||
last_temp[${SENSOR}]=${temp_f}
|
||||
echo "(${datetime}) - ${temp_f}'F - WARNING TEMP - (Difference of ${temp_diff}')" >> ${logtemp}
|
||||
|
||||
# iDS-vMS-Offsite Fan Issue Workaround
|
||||
if [ "${PW_HOST_IDRACS[${SENSORa}]}" == "10.2.1.21" ] && [ ${FanSpeed} -ne 80 ]; then
|
||||
@@ -312,16 +313,16 @@ CHECKTEMP_SERVICE(){
|
||||
fi
|
||||
fi
|
||||
|
||||
elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit_sys") -eq 1 ]; then
|
||||
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}_sys") -eq 1 ]; then
|
||||
touch ${PW_TMPFOLDER}/temp.crit
|
||||
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')
|
||||
if [ ${temp_diff} -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "(${datetime}) CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')
|
||||
Shutting down servers!!" 1
|
||||
echo "($datetime) - ${temp_f}'F - CRITICAL - (Difference of ${temp_diff}'F)" >> ${logtemp}
|
||||
echo -e "($datetime) - ${SENSOR} - ${temp_f}'F - CRITICAL TEMP - (Difference of ${temp_diff}')" >> ${PW_LOGFILE}
|
||||
last_temp[${SENSOR}]=$temp_f
|
||||
echo "(${datetime}) - ${temp_f}'F - CRITICAL - (Difference of ${temp_diff}'F)" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${SENSOR} - ${temp_f}'F - CRITICAL TEMP - (Difference of ${temp_diff}')" >> ${PW_LOGFILE}
|
||||
last_temp[${SENSOR}]=${temp_f}
|
||||
SHUTDOWN_MAIN ${SENSOR} &
|
||||
echo -e "($datetime) - ${temp_f}'F - Shutting down MAIN servers" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - Shutting down MAIN servers" >> ${logtemp}
|
||||
|
||||
# iDS-vMS-Offsite Fan Issue Workaround
|
||||
if [ "${PW_HOST_IDRACS[${SENSORa}]}" == "10.2.1.21" ]; then
|
||||
@@ -342,35 +343,35 @@ Shutting down servers!!" 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
elif [ $(bc -l <<< "$temp_f >= $temp_crit_sys") -eq 1 ]; then
|
||||
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit}_sys") -eq 1 ]; then
|
||||
touch ${PW_TMPFOLDER}/temp.critsys
|
||||
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) SYSTEM CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')" 1
|
||||
echo "($datetime) - ${temp_f}'F - SYSTEM CRITICAL - (Difference of ${temp_diff})" >> ${logtemp}
|
||||
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - CRITICAL TEMP SYSTEM - (Difference of ${temp_diff}')" >> ${PW_LOGFILE}
|
||||
last_temp[${SENSOR}]=$temp_f
|
||||
if [ ${temp_diff} -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "(${datetime}) SYSTEM CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')" 1
|
||||
echo "(${datetime}) - ${temp_f}'F - SYSTEM CRITICAL - (Difference of ${temp_diff})" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - ${SENSOR} - CRITICAL TEMP SYSTEM - (Difference of ${temp_diff}')" >> ${PW_LOGFILE}
|
||||
last_temp[${SENSOR}]=${temp_f}
|
||||
SHUTDOWN_SYS ${SENSOR} TEMP &
|
||||
SHUTDOWN_CRIT ${SENSOR} &
|
||||
echo -e "($datetime) - ${temp_f}'F - Sending system shutdown signals, if applicable. Check main Powerwall Logs" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - Sending system shutdown signals, if applicable. Check main Powerwall Logs" >> ${logtemp}
|
||||
fi
|
||||
else
|
||||
|
||||
if [ ${last_temp[${SENSOR}]} -gt 1 ]; then
|
||||
SENDNOTICE "${SENSOR} BACK TO NORMAL" "($datetime) NORMAL TEMP: ${temp_f}'F
|
||||
SENDNOTICE "${SENSOR} BACK TO NORMAL" "(${datetime}) NORMAL TEMP: ${temp_f}'F
|
||||
Previous Temp: ${last_temp[${SENSOR}]}'F"
|
||||
echo -e "($datetime) - ${temp_f}'F - Back to NORMAL TEMP - Previous Temp: ${last_temp[${SENSOR}]}'F" >> ${logtemp}
|
||||
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - Back to NORMAL TEMP" >> ${PW_LOGFILE}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - Back to NORMAL TEMP - Previous Temp: ${last_temp[${SENSOR}]}'F" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - ${SENSOR} - Back to NORMAL TEMP" >> ${PW_LOGFILE}
|
||||
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
|
||||
|
||||
elif [ ${last_temp[${SENSOR}]} -eq 0 ]; then
|
||||
# SENDNOTICE "${SENSOR} TEMP NORMAL" "($datetime) Service Startup
|
||||
# SENDNOTICE "${SENSOR} TEMP NORMAL" "(${datetime}) Service Startup
|
||||
# NORMAL TEMP: ${temp_f}'F"
|
||||
echo -e "($datetime) - ${temp_f}'F - Service Startup - NORMAL TEMP" >> ${logtemp}
|
||||
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - Service Startup" >> ${PW_LOGFILE}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - Service Startup - NORMAL TEMP" >> ${logtemp}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - ${SENSOR} - Service Startup" >> ${PW_LOGFILE}
|
||||
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
|
||||
|
||||
elif [ $relog -eq 1 ]; then
|
||||
echo "($datetime) - ${temp_f}'F - Normal Temp" >> ${logtemp}
|
||||
elif [ ${relog} -eq 1 ]; then
|
||||
echo "(${datetime}) - ${temp_f}'F - Normal Temp" >> ${logtemp}
|
||||
|
||||
fi
|
||||
rm -f ${PW_TMPFOLDER}/temp.*
|
||||
@@ -414,8 +415,8 @@ Previous Temp: ${last_temp[${SENSOR}]}'F"
|
||||
fi
|
||||
else
|
||||
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 1800 ]; then
|
||||
SENDNOTICE "${SENSOR} Sensor ERROR" "($datetime) ERROR reading sensor data" 1
|
||||
echo "($datetime) - ${SENSOR} Sensor - ERROR reading sensor data" >> ${logtemp}
|
||||
SENDNOTICE "${SENSOR} Sensor ERROR" "(${datetime}) ERROR reading sensor data" 1
|
||||
echo "(${datetime}) - ${SENSOR} Sensor - ERROR reading sensor data" >> ${logtemp}
|
||||
touch ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
||||
fi
|
||||
|
||||
@@ -427,7 +428,7 @@ Previous Temp: ${last_temp[${SENSOR}]}'F"
|
||||
elif [ "${PW_HOST_ADDRESSES[${SENSORa}]}" == "" ]; then #sensor down
|
||||
if [ ! -f ${PW_TMPFOLDER}/${SENSORa}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSORa}.down)) -ge 1800 ]; then
|
||||
SENDNOTICE "${SENSORa} ERROR" "${SENSORa} Sensor is down" 1
|
||||
echo "($datetime) - ${SENSORa} - ${SENSORa} Sensor is down" >> ${logtemp}
|
||||
echo "(${datetime}) - ${SENSORa} - ${SENSORa} Sensor is down" >> ${logtemp}
|
||||
touch ${PW_TMPFOLDER}/${SENSORa}.down
|
||||
|
||||
fi
|
||||
@@ -462,7 +463,7 @@ DAILYTEMP(){
|
||||
|
||||
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "mqtt" ]; then
|
||||
mqtt_message=`${mqtt_conn} -t tele/${SENSOR}/SENSOR -C 1`
|
||||
temp_c=$(echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1)
|
||||
temp_c=$(echo ${mqtt_message} | cut -d':' -f 6 | cut -d',' -f 1)
|
||||
|
||||
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ]; then
|
||||
temp_c=$(vcgencmd measure_temp)
|
||||
@@ -490,9 +491,9 @@ DAILYTEMP(){
|
||||
average7=$(AVERAGETEMP ${PW_SENSOR_ID[${SENSORa}]} 7)
|
||||
fi
|
||||
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
|
||||
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
|
||||
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
|
||||
temp_f=`echo "scale=2; ${temp_c}*1.8 + 32" | bc`
|
||||
echo -e "${SENSOR}${spc}${temp_f}'F / ${average1}'F / ${average7}'F"
|
||||
|
||||
else
|
||||
@@ -500,7 +501,7 @@ DAILYTEMP(){
|
||||
|
||||
fi
|
||||
done
|
||||
[ "$temp_c" != "null" ] && [ "$temp_c" != "" ] && echo
|
||||
[ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ] && echo
|
||||
done
|
||||
}
|
||||
|
||||
@@ -693,31 +694,31 @@ CHECKPOWER_SERVICE(){
|
||||
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
||||
|
||||
if (( $(bc <<<"${INPUTACV} >= ${min_acvolt}") )); then
|
||||
if [ $voltstatus -eq 3 ]; then
|
||||
echo "($datetime) - ${INPUTACV}V - Back to Normal Voltage" >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "POWER NOMINAL AGAIN" "($datetime) Normal voltage detected
|
||||
if [ ${voltstatus} -eq 3 ]; then
|
||||
echo "(${datetime}) - ${INPUTACV}V - Back to Normal Voltage" >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "POWER NOMINAL AGAIN" "(${datetime}) Normal voltage detected
|
||||
VOLTAGE: ${INPUTACV}V"
|
||||
echo -e "($datetime) - ${INPUTACV}V - POWER NOMINAL AGAIN" >> ${PW_LOGFILE}
|
||||
echo -e "(${datetime}) - ${INPUTACV}V - POWER NOMINAL AGAIN" >> ${PW_LOGFILE}
|
||||
battstatus=0
|
||||
else
|
||||
errtime=$(expr `date +%s` - $(stat -c %Y ${PW_LOGPOWER}))
|
||||
[ $errtime -ge 3600 ] && echo "($datetime) - ${INPUTACV}V - Normal Voltage" >> ${PW_LOGPOWER}
|
||||
if [ $voltstatus -eq 0 ]; then
|
||||
SENDNOTICE "Power Nominal" "($datetime) Service Startup
|
||||
[ ${errtime} -ge 3600 ] && echo "(${datetime}) - ${INPUTACV}V - Normal Voltage" >> ${PW_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" >> ${PW_LOGPOWER}
|
||||
echo -e "($datetime) - ${INPUTACV}V / ${BATTVOLT}V - Service Startup - Normal Voltage" >> ${PW_LOGFILE}
|
||||
echo "(${datetime}) - Input: ${INPUTACV}V - Service Startup - Normal voltage detected" >> ${PW_LOGPOWER}
|
||||
echo -e "(${datetime}) - ${INPUTACV}V / ${BATTVOLT}V - Service Startup - Normal Voltage" >> ${PW_LOGFILE}
|
||||
fi
|
||||
fi
|
||||
voltstatus=1
|
||||
rm -f ${PW_TMPFOLDER}/power.ac.*
|
||||
else
|
||||
echo "($datetime) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${PW_LOGPOWER}
|
||||
echo -e "($datetime) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${PW_LOGFILE}
|
||||
if [ $voltstatus -lt 3 ]; then
|
||||
SENDNOTICE "POWER ALERT - POWER OFF/LOW POWER!!" "($datetime) Power off or low voltage detected
|
||||
echo "(${datetime}) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${PW_LOGPOWER}
|
||||
echo -e "(${datetime}) - ${INPUTACV}V - POWER OFF/LOW POWER" >> ${PW_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
|
||||
last_battvolt=$BATTVOLT
|
||||
@@ -727,24 +728,24 @@ BATT VOLTAGE: ${BATTVOLT}V" 1
|
||||
fi
|
||||
|
||||
if (( $(bc <<<"${BATTVOLT} < ${min_battvolt} && ${BATTVOLT} > ${min_battvolt_sys}") )); then
|
||||
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${PW_LOGPOWER}
|
||||
echo -e "($datetime) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${PW_LOGFILE}
|
||||
echo "(${datetime}) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${PW_LOGPOWER}
|
||||
echo -e "(${datetime}) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${PW_LOGFILE}
|
||||
touch ${PW_TMPFOLDER}/power.dc.low
|
||||
if (( $(bc <<<"${battstatus} < 2 && ${INPUTACV} < ${min_acvolt}") )); then
|
||||
echo "($datetime) - ${BATTVOLT}V - Shutting down main servers..." >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "BATT-VOLT LOW: SHUTDOWN MAIN SERVERS" "($datetime) Battery Voltage LOW: ${BATTVOLT}V
|
||||
echo "(${datetime}) - ${BATTVOLT}V - Shutting down main servers..." >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "BATT-VOLT LOW: SHUTDOWN MAIN SERVERS" "(${datetime}) Battery Voltage LOW: ${BATTVOLT}V
|
||||
Shutting down main servers" 1
|
||||
SHUTDOWN_MAIN POWER &
|
||||
battstatus=2
|
||||
fi
|
||||
|
||||
elif (( $(bc <<<"${BATTVOLT} <= ${min_battvolt_sys}") )); then
|
||||
echo "($datetime) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${PW_LOGPOWER}
|
||||
echo -e "($datetime) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${PW_LOGFILE}
|
||||
echo "(${datetime}) - ${BATTVOLT}V - LOW BATTERY Voltage" >> ${PW_LOGPOWER}
|
||||
echo -e "(${datetime}) - ${BATTVOLT}V - LOW BATTERY VOLTAGE" >> ${PW_LOGFILE}
|
||||
touch ${PW_TMPFOLDER}/power.dc.low
|
||||
if (( $(bc <<<"${battstatus} < 3 && ${INPUTACV} < ${min_acvolt}") )); then
|
||||
echo "($datetime) - ${BATTVOLT}V - Shutting down all remaining servers..." >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "BATT-VOLT REALLY LOW: SHUTDOWN SYS SERVERS" "($datetime) Battery Voltage REALLY LOW: ${BATTVOLT}V
|
||||
echo "(${datetime}) - ${BATTVOLT}V - Shutting down all remaining servers..." >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "BATT-VOLT REALLY LOW: SHUTDOWN SYS SERVERS" "(${datetime}) Battery Voltage REALLY LOW: ${BATTVOLT}V
|
||||
Shutting down all servers" 1
|
||||
SHUTDOWN_SYS POWER &
|
||||
|
||||
@@ -754,9 +755,9 @@ Shutting down all servers" 1
|
||||
|
||||
else
|
||||
errtime=$(expr `date +%s` - $(stat -c %Y ${PW_LOGPOWER}))
|
||||
[ $errtime -ge 3600 ] && echo "($datetime) - ${BATTVOLT}V - Battery Voltage" >> ${PW_LOGPOWER}
|
||||
if [ $battstatus -eq 0 ]; then
|
||||
echo "($datetime) - Battery: ${BATTVOLT}V - Service Startup - Normal voltage detected" >> ${PW_LOGPOWER}
|
||||
[ ${errtime} -ge 3600 ] && echo "(${datetime}) - ${BATTVOLT}V - Battery Voltage" >> ${PW_LOGPOWER}
|
||||
if [ ${battstatus} -eq 0 ]; then
|
||||
echo "(${datetime}) - Battery: ${BATTVOLT}V - Service Startup - Normal voltage detected" >> ${PW_LOGPOWER}
|
||||
fi
|
||||
rm -f ${PW_TMPFOLDER}/power.dc.*
|
||||
battstatus=1
|
||||
@@ -766,8 +767,8 @@ Shutting down all servers" 1
|
||||
volt_diff=`echo "scale=1; ${last_battvolt}-${BATTVOLT}" | bc`
|
||||
(( $(bc <<<"${volt_diff} < 0") )) && temp_diff=`echo "scale=1; ${volt_diff} * -1" | bc`
|
||||
if (( $(bc <<<"${volt_diff} > 0") )); then
|
||||
SENDNOTICE "BATTERY VOLTAGE CHANGE" "($datetime) Battery Voltage: ${BATTVOLT}V"
|
||||
echo -e "($datetime) - ${BATTVOLT}V - Battery Voltage Change" >> ${PW_LOGPOWER}
|
||||
SENDNOTICE "BATTERY VOLTAGE CHANGE" "(${datetime}) Battery Voltage: ${BATTVOLT}V"
|
||||
echo -e "(${datetime}) - ${BATTVOLT}V - Battery Voltage Change" >> ${PW_LOGPOWER}
|
||||
last_battvolt=${BATTVOLT}
|
||||
fi
|
||||
else
|
||||
@@ -911,7 +912,7 @@ CHECK_SERVICES(){
|
||||
DIVIDER . yellow 75
|
||||
|
||||
for srvc in "${PW_POWERWALL_SERVICES[@]}"; do
|
||||
c=0; spc=''; spc1=`expr 25 - ${#srvc}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr 25 - ${#srvc}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -en "${idsCL[LightCyan]}${srvc}${spc}: "
|
||||
[ "$(systemctl is-active ${srvc})" == "active" ] && echo -en "${idsCL[Green]}Running" || echo -en "${idsCL[Yellow]}Not Running"
|
||||
echo -e "${idsCL[Default]}"
|
||||
@@ -922,12 +923,12 @@ CHECK_SERVICES(){
|
||||
|
||||
SHUTDOWN_MAIN(){
|
||||
if [ "${1}" == "ServerRoomTH"] || [ "${1}" == "TEMP"]; then
|
||||
SHUTDOWN_SERVERS MAIN ${2}
|
||||
SHUTDOWN_SERVERS MAIN ${1}
|
||||
reason='Server Room Overheated!'
|
||||
sendnotice=true
|
||||
|
||||
elif [ "${1}" == "POWER"]; then
|
||||
SHUTDOWN_SERVERS MAIN ${2}
|
||||
SHUTDOWN_SERVERS MAIN ${1}
|
||||
reason='Low Power!'
|
||||
sendnotice=true
|
||||
|
||||
@@ -937,21 +938,21 @@ SHUTDOWN_MAIN(){
|
||||
|
||||
if [ "${sendnotice}" == "true"]; then
|
||||
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
||||
SENDNOTICE "MAIN SERVERS SHUTDOWN" "($datetime) MAIN servers have been shutdown
|
||||
SENDNOTICE "MAIN SERVERS SHUTDOWN" "(${datetime}) MAIN servers have been shutdown
|
||||
${reason}" 1
|
||||
echo -e "($datetime) - Main servers have been shutdown, ${reason}" >> ${PW_LOGFILE}
|
||||
echo -e "(${datetime}) - Main servers have been shutdown, ${reason}" >> ${PW_LOGFILE}
|
||||
fi
|
||||
|
||||
echo
|
||||
}
|
||||
SHUTDOWN_SYS(){
|
||||
if [ "${1}" == "ServerRoomTH"] || [ "${1}" == "TEMP"]; then
|
||||
SHUTDOWN_SERVERS SYS ${2}
|
||||
SHUTDOWN_SERVERS SYS ${1}
|
||||
reason='Server Room Overheated!'
|
||||
sendnotice=true
|
||||
|
||||
elif [ "${1}" == "POWER"]; then
|
||||
SHUTDOWN_SERVERS SYS ${2}
|
||||
SHUTDOWN_SERVERS SYS ${1}
|
||||
reason='Low Power!'
|
||||
sendnotice=true
|
||||
|
||||
@@ -961,10 +962,10 @@ SHUTDOWN_SYS(){
|
||||
|
||||
if [ "${sendnotice}" == "true"]; then
|
||||
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
||||
SENDNOTICE "SYS SERVERS SHUTDOWN" "($datetime) SYS servers have been shutdown
|
||||
SENDNOTICE "SYS SERVERS SHUTDOWN" "(${datetime}) SYS servers have been shutdown
|
||||
${reason}" 1
|
||||
echo -e "($datetime) - SYS servers have been shutdown, ${reason}" >> ${PW_LOGFILE}
|
||||
echo -e "($datetime) - ${temp_f}'F - Shutting down SYS servers" >> ${logtemp}
|
||||
echo -e "(${datetime}) - SYS servers have been shutdown, ${reason}" >> ${PW_LOGFILE}
|
||||
echo -e "(${datetime}) - ${temp_f}'F - Shutting down SYS servers" >> ${logtemp}
|
||||
fi
|
||||
|
||||
# curl --data "cmd=PWRoff" http://10.10.0.61/cmd
|
||||
@@ -972,16 +973,16 @@ SHUTDOWN_SYS(){
|
||||
}
|
||||
SHUTDOWN_CRIT(){
|
||||
if [ "${1}" == "Powerwall-CPU" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) Powerwall System shutting down" 1
|
||||
echo -e "($datetime) - CRITICAL TEMP - Powerwall System shutting down" >> ${PW_LOGFOLDER}/log-temp-${1}
|
||||
echo -e "($datetime) - ${SENSOR} TEMP CRITICAL - Powerwall System shutting down" >> ${PW_LOGFILE}
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "(${datetime}) Powerwall System shutting down" 1
|
||||
echo -e "(${datetime}) - CRITICAL TEMP - Powerwall System shutting down" >> ${PW_LOGFOLDER}/log-temp-${1}
|
||||
echo -e "(${datetime}) - ${SENSOR} TEMP CRITICAL - Powerwall System shutting down" >> ${PW_LOGFILE}
|
||||
sleep 1s
|
||||
/sbin/poweroff
|
||||
|
||||
elif [ "${1}" == "OctoPI-CPU" ]; then
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) OctoPI System shutting down" 1
|
||||
echo -e "($datetime) - CRITICAL TEMP - OctoPI System shutting down" >> ${PW_LOGFOLDER}/log-temp-${1}
|
||||
echo -e "($datetime) - ${SENSOR} TEMP CRITICAL - OctoPI System shutting down" >> ${PW_LOGFILE}
|
||||
SENDNOTICE "${SENSOR} TEMP CRITICAL" "(${datetime}) OctoPI System shutting down" 1
|
||||
echo -e "(${datetime}) - CRITICAL TEMP - OctoPI System shutting down" >> ${PW_LOGFOLDER}/log-temp-${1}
|
||||
echo -e "(${datetime}) - ${SENSOR} TEMP CRITICAL - OctoPI System shutting down" >> ${PW_LOGFILE}
|
||||
sleep 1s
|
||||
ssh root@${PW_REMOTE_SENSORS[${1}]} /sbin/poweroff
|
||||
|
||||
@@ -991,7 +992,7 @@ SHUTDOWN_CRIT(){
|
||||
SHUTDOWN_SERVERS(){
|
||||
TEST=true
|
||||
|
||||
echo "($datetime) - Shutting down ${1} servers" >> ${PW_LOGFILE}
|
||||
echo "(${datetime}) - Shutting down ${1} servers" >> ${PW_LOGFILE}
|
||||
[ "${TEST}" == "true" ] && echo "RUNNING IN TEST MODE">>${PW_LOGFILE}
|
||||
|
||||
if [ "${1^^}" == "MAIN" ] || [ "${1^^}" == "ALL" ]; then
|
||||
@@ -1131,15 +1132,15 @@ SHUTDOWN_SERVER(){
|
||||
|
||||
if [ "${hostip}" != "" ]; then
|
||||
host=${PW_ESXI_HOST_NAMES[${hostip}]}
|
||||
c=0; spcA=''; spc1=`expr 21 - ${#host} - 1`; until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
|
||||
c=0; spcB=''; spc1=`expr 18 - ${#hostip} - 1`; until [ $c = ${spc1} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
|
||||
c=0; spcA=''; spc1=`expr 21 - ${#host} - 1`; until [ ${c} = ${spc1} ]; do spcA="${spcA} "; c=`expr ${c} + 1`; done
|
||||
c=0; spcB=''; spc1=`expr 18 - ${#hostip} - 1`; until [ ${c} = ${spc1} ]; do spcB="${spcB} "; c=`expr ${c} + 1`; done
|
||||
echo -en "${idsCL[LightCyan]} Host: ${idsCL[Green]}${host}${spcA}"
|
||||
echo -en "${idsCL[LightCyan]}Host IP: ${idsCL[Green]}${hostip}${spcB}"
|
||||
echo -e "${idsCL[LightCyan]}iDrac IP: ${idsCL[Green]}${PW_HOST_IDRACS[${host}]}${idsCL[Default]}"
|
||||
DIVIDER . yellow 75
|
||||
echo
|
||||
|
||||
echo "($datetime) - Shutting down ${host} (${hostip})" >> ${PW_LOGFILE}
|
||||
echo "(${datetime}) - Shutting down ${host} (${hostip})" >> ${PW_LOGFILE}
|
||||
|
||||
echo -en "${idsCL[LightCyan]}Enabling maintenance mode & starting iSCSI VM migrations ... "
|
||||
[ "${TEST}" != "true" ] && run=$(${PW_FOLDER}/esxi-scripts/host-maintenance_mode.ps1 ${PW_VCENTER_HOST_NAMES[${hostip}]} & >/dev/null 2>&1)
|
||||
@@ -1223,8 +1224,8 @@ HOSTPOWER(){
|
||||
|
||||
if [ "${idracip}" != "" ]; then
|
||||
host=${PW_iDRACHOST_SHORTNAMES[${idracip}]}
|
||||
c=0; spcA=''; spc1=`expr 21 - ${#host} - 1`; until [ $c = ${spc1} ]; do spcA="${spcA} "; c=`expr $c + 1`; done
|
||||
c=0; spcB=''; spc1=`expr 18 - ${#PW_HOST_ADDRESSES[${host}]} - 1`; until [ $c = ${spc1} ]; do spcB="${spcB} "; c=`expr $c + 1`; done
|
||||
c=0; spcA=''; spc1=`expr 21 - ${#host} - 1`; until [ ${c} = ${spc1} ]; do spcA="${spcA} "; c=`expr ${c} + 1`; done
|
||||
c=0; spcB=''; spc1=`expr 18 - ${#PW_HOST_ADDRESSES[${host}]} - 1`; until [ ${c} = ${spc1} ]; do spcB="${spcB} "; c=`expr ${c} + 1`; done
|
||||
echo -en "${idsCL[LightCyan]} Host: ${idsCL[Green]}${host}${spcA}"
|
||||
echo -en "${idsCL[LightCyan]}Host IP: ${idsCL[Green]}${PW_HOST_ADDRESSES[${host}]}${spcB}"
|
||||
echo -e "${idsCL[LightCyan]}iDrac IP: ${idsCL[Green]}${idracip}${idsCL[Default]}"
|
||||
@@ -1245,7 +1246,7 @@ HOSTPOWER(){
|
||||
LOGROTATE(){
|
||||
# STOPALL_SERVICES
|
||||
lm=`expr $(date +'%m') - 1`
|
||||
if [ $lm = 0 ]; then
|
||||
if [ ${lm} = 0 ]; then
|
||||
lm=12
|
||||
ly=`expr $(date +'%Y') - 1`
|
||||
else
|
||||
@@ -1288,7 +1289,7 @@ GET_SNAPSHOTS(){
|
||||
# name=`echo ${snapshot} | base64 --decode | jq -r '.Name'`
|
||||
# created=`echo ${snapshot} | base64 --decode | jq -r '.Created'`
|
||||
# size=`echo ${snapshot} | base64 --decode | jq -r '.SizeGB'`
|
||||
# echo "$vm - $name - $created - $size"
|
||||
# echo "$vm - $name - ${c}reated - $size"
|
||||
# done
|
||||
|
||||
else
|
||||
@@ -1335,13 +1336,13 @@ if [[ "${1}" != *"_service" ]] && [[ "${noheader}" != *" ${1} "* ]] && [[ "${noh
|
||||
echo
|
||||
DIVIDER . lightGreen 70
|
||||
msg="| PowerWall Management ${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})"
|
||||
c=0; spc=''; spc1=`expr 81 - ${#msg}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr 81 - ${#msg}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -e "${idsCL[LightGreen]}${msg}${spc}${idsCL[LightGreen]}|${idsCL[Default]}"
|
||||
DIVIDER . lightGreen 70
|
||||
fi
|
||||
|
||||
# if [ ${action-x} ]; then
|
||||
case $action in
|
||||
case ${action} in
|
||||
services)
|
||||
[ "${2}" == "stop" ] && STOPALL_SERVICES
|
||||
[ "${2}" == "start" ] && STARTALL_SERVICES
|
||||
@@ -1362,7 +1363,7 @@ fi
|
||||
[ "${2^^}" == "SYS" ] && ISCSISYSVMSHUTDOWN || ISCSIVMSHUTDOWN
|
||||
;;
|
||||
shutdownhost) SHUTDOWN_SERVER ${2};;
|
||||
shutdown_servers) SHUTDOWN_SERVERS ${2};;
|
||||
shutdown_servers) SHUTDOWN_SERVERS ${2} ${3};;
|
||||
hostpower) HOSTPOWER ${2} ${3};;
|
||||
|
||||
get-snapshots) GET_SNAPSHOTS;;
|
||||
@@ -1413,7 +1414,7 @@ fi
|
||||
|
||||
elif [ "${3}" = "status" ]; then
|
||||
srvc=${PW_POWERWALL_SERVICES[${2}]}
|
||||
c=0; spc=''; spc1=`expr 25 - ${#srvc}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||
c=0; spc=''; spc1=`expr 25 - ${#srvc}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
|
||||
echo -en "${idsCL[LightCyan]}${srvc}${spc}: "
|
||||
[ "$(systemctl is-active ${srvc})" == "active" ] && echo -en "${idsCL[Green]}Running" || echo -en "${idsCL[Yellow]}Not Running"
|
||||
echo -e "${idsCL[Default]}"
|
||||
|
||||
Reference in New Issue
Block a user