This commit is contained in:
2023-08-14 23:18:43 -05:00
parent 6d6e691ecd
commit e9182855f1
2 changed files with 47 additions and 38 deletions

View File

@@ -148,47 +148,55 @@ CHECKTEMP_SERVICE(){
declare -A last_temp
# while true; do
for SENSOR in ${!PW_SENSOR_ID[@]}; do
echo $SENSOR
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
for SENSORa in ${!PW_SENSOR_ID[@]}; do
logtemp=${PW_LOGFOLDER}/log-temp-${SENSORa}
[ ! -f ${logtemp} ] && touch ${logtemp}
logtime=$(expr `date +%s` - $(stat -c %Y ${logtemp}))
[ ${logtime} -ge 3600 ] && relog=1 || relog=0
if [ "${PW_REMOTE_SENSORS[${SENSOR}]}" == "" ] || ([ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSOR}]})" != "false" ]); then
if [ -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
SENDNOTICE "${SENSOR} Online" "${SENSOR} Sensor is back online"
echo "($datetime) - ${SENSOR} - ${SENSOR} Sensor is back onlione" >> ${logtemp}
rm -f ${PW_TMPFOLDER}/${SENSOR}.down
if [ "${PW_REMOTE_SENSORS[${SENSORa}]}" == "" ] || ([ "${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}
rm -f ${PW_TMPFOLDER}/${SENSORa}.down
fi
SENSORS_CHECK=(${SENSOR})
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "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
SENSORS_CHECK=(${SENSOR})
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ]; then
temp_c=$(vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "remotesystem" ]; then
temp_c=$(ssh root@${PW_REMOTE_SENSORS[${SENSOR}]} vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
# elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "esxi" ]; then
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
vHOSTDATA=$(ssh root@${PW_RACADM_ACCESS} racadm -r ${PW_HOST_IDRACS[${SENSORa}]} -u ${PW_ESXI_USER} -p "'${PW_ESXI_PASS}'" getsensorinfo | grep " Temp" 2>&1)
IFS=$'\n' read -rd '' -a vHOSTDATA <<<"${vHOSTDATA}"; unset IFS
SENSORS_CHECK=${vHOSTDATA}
else
SENSORS_CHECK=(${SENSORa})
fi
for SENSOR2 in ${SENSORS_CHECK[@]}; do
for SENSOR in ${SENSORS_CHECK[@]}; do
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "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
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ]; then
temp_c=$(vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "remotesystem" ]; then
temp_c=$(ssh root@${PW_REMOTE_SENSORS[${SENSOR}]} vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "esxi" ]; then
temp_c=$(echo ${SENSOR} | cut -d'p' -f2 | awk '/ / {print $2}' | sed -e 's/C//g'); temp_c=${temp_c/ /}
temp_warn=$(echo ${SENSOR} | cut -d'p' -f2 | awk '/ / {print $7}' | sed -e 's/C//g'); temp_warn=${temp_warn/ /}
temp_crit=$(echo ${SENSOR} | cut -d'p' -f2 | awk '/ / {print $4}' | sed -e 's/C//g'); temp_crit=${temp_crit/ /}
temp_crit_sys=$(echo ${SENSOR} | cut -d'p' -f2 | awk '/ / {print $4}' | sed -e 's/C//g'); temp_crit=${temp_crit/ /}
vSENSOR=$(echo ${SENSOR} | cut -d'T' -f1 | xargs)
SENSOR="${SENSORa}-${vSENSOR/ /_}"
fi
datetime=`date +'%Y-%m-%d %H:%M:%S'`
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
@@ -199,10 +207,11 @@ CHECKTEMP_SERVICE(){
fi
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 2 | read temp_crit
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 3 | read temp_crit_sys
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" != "esxi" ]; then
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 2 | read temp_crit
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 3 | read temp_crit_sys
fi
echo "HERE: ${SENSOR} - ${temp_f} - ${temp_warn} - ${temp_crit}"
@@ -307,10 +316,10 @@ CHECKTEMP_SERVICE(){
done
else #sensor down
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
SENDNOTICE "${SENSOR} ERROR" "${SENSOR} Sensor is down" 1
echo "($datetime) - ${SENSOR} - ${SENSOR} Sensor is down" >> ${logtemp}
touch ${PW_TMPFOLDER}/${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}
touch ${PW_TMPFOLDER}/${SENSORa}.down
fi

2
run.sh
View File

@@ -46,7 +46,7 @@ if [ "${1}" == "update" ]; then
echo -en "\e[1A";
echo -e "\e[0K\r ${idsCL[Green]}Update to v${VERS} complete${idsCL[Default]}"
fi
echo -en "${idsCL[Yellow]}Restarting Powerwall services to apply update ${idsCL[White]}... "
# echo -en "${idsCL[Yellow]}Restarting Powerwall services to apply update ${idsCL[White]}... "
# /opt/idssys/powerwall/powerwall.sh service all restart >/dev/null 2>&1
echo -e "${idsCL[Green]}Done${idsCL[Default]}\n"