This commit is contained in:
2023-08-12 10:22:00 -05:00
parent a4ab994219
commit 98a0613cd0
2 changed files with 138 additions and 102 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERS='2.161-08122023'
VERS='2.162-08122023'
noheader=' update service dailytemp '

View File

@@ -59,11 +59,14 @@ CHECKTEMPSENSOR(){
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
elif [ "${SENSOR_TYPE[${1}]}" == "remotesystem" ]; then
if [ "$(CHECK_HOST ${REMOTE_SENSORS[${1}]})" != "false" ]; then
temp_c=$(ssh root@${REMOTE_SENSORS[${1}]} vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
fi
fi
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
#echo "$temp_c -> $temp_f"
@@ -117,6 +120,14 @@ CHECKTEMP_SERVICE(){
errtime=$(expr `date +%s` - $(stat -c %Y ${logtemp}))
[ $errtime -ge 3600 ] && relog=1 || relog=0
if [ "$(CHECK_HOST ${REMOTE_SENSORS[${1}]})" != "false" ]; then
if [ -f ${TMPFOLDER}/${SENSOR}.down ]; then
SENDNOTICE "${SENSOR} Online" "${SENSOR} is back online"
echo "($datetime) - ${SENSOR} - ${SENSOR} is back onlione" >> ${logtemp}
rm -f ${TMPFOLDER}/${SENSOR}.down
fi
if [ "${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
@@ -126,10 +137,22 @@ CHECKTEMP_SERVICE(){
temp_c=$(vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
elif [ "${SENSOR_TYPE[${SENSOR}]}" == "remotesystem" ]; then
temp_c=$(ssh root@${REMOTE_SENSORS[${1}]} vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h=''
fi
datetime=`date +'%Y-%m-%d %H:%M:%S'`
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
if [ -f ${TMPFOLDER}/${SENSOR}-error.reading ]; then
SENDNOTICE "${SENSOR} Data" "${SENSOR} is reporting data again"
echo "($datetime) - ${SENSOR} - ${SENSOR} is reporting data again" >> ${logtemp}
rm -f ${TMPFOLDER}/${SENSOR}-error.reading
fi
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
echo ${TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
@@ -157,7 +180,7 @@ CHECKTEMP_SERVICE(){
touch ${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}')
Shutting down servers!!" 1
Shutting down servers!!" 1
echo "($datetime) - ${temp_f}'F - CRITICAL - (Difference of ${temp_diff}'F)" >> ${logtemp}
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
echo -e "($datetime) - ${SENSOR} - ${temp_f}'F - CRITICAL TEMP - (Difference of ${temp_diff}')" >> ${logfile}
@@ -170,7 +193,7 @@ Shutting down servers!!" 1
touch ${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}')
Shutting down system servers!!" 1
Shutting down system servers!!" 1
echo "($datetime) - ${temp_f}'F - SYSTEM CRITICAL - (Difference of ${temp_diff})" >> ${logtemp}
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - CRITICAL TEMP SYSTEM - (Difference of ${temp_diff}')" >> ${logfile}
@@ -184,7 +207,7 @@ Shutting down system servers!!" 1
if [ ${last_temp[${SENSOR}]} -gt 1 ]; then
SENDNOTICE "${SENSOR} BACK TO NORMAL" "($datetime) NORMAL TEMP: ${temp_f}'F
Previous Temp: ${last_temp[${SENSOR}]}'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 "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - Back to NORMAL TEMP" >> ${logfile}
@@ -192,7 +215,7 @@ Previous Temp: ${last_temp[${SENSOR}]}'F"
elif [ ${last_temp[${SENSOR}]} -eq 0 ]; then
SENDNOTICE "${SENSOR} TEMP NORMAL" "($datetime) Service Startup
NORMAL TEMP: ${temp_f}'F"
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" >> ${logfile}
[ "$(compgen -G "${FOLDER}/shutdown.*")" != "" ] && rm -f ${FOLDER}/shutdown.*
@@ -221,8 +244,21 @@ NORMAL TEMP: ${temp_f}'F"
touch ${TMPFOLDER}/${SENSOR}.insert
fi
else
SENDNOTICE "${SENSOR} ERROR" "($datetime) ERROR reading temperature" 1
echo "($datetime) - alert sent" >> ${logtemp}
if [ ! -f ${TMPFOLDER}/${SENSOR}-error.reading ] || [ $(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/${SENSOR}-error.reading)) -ge 1800 ]; then
SENDNOTICE "${SENSOR} ERROR" "($datetime) ERROR reading sensor data" 1
echo "($datetime) - ${SENSOR} - ERROR reading sensor data" >> ${logtemp}
touch ${TMPFOLDER}/${SENSOR}-error.reading
fi
fi
else
if [ ! -f ${TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
SENDNOTICE "${SENSOR} ERROR" "${SENSOR} is down" 1
echo "($datetime) - ${SENSOR} - ${SENSOR} is down" >> ${logtemp}
touch ${TMPFOLDER}/${SENSOR}.down
fi
fi
done