Update powerwall.sh
This commit is contained in:
256
powerwall.sh
256
powerwall.sh
@@ -94,16 +94,13 @@ CHECKTEMPSENSOR(){
|
|||||||
fi
|
fi
|
||||||
elif [ "${PW_SENSOR_TYPE[${1}]}" == "esxi" ]; then
|
elif [ "${PW_SENSOR_TYPE[${1}]}" == "esxi" ]; then
|
||||||
temp_c=${2}
|
temp_c=${2}
|
||||||
temp_f=$(bc <<< "scale=1; ${temp_c}*1.8+32")
|
|
||||||
# temp_warn=$(bc <<< "scale=2; (${3}*1.8+32)/1")
|
|
||||||
temp_warn=`echo $(bc <<< "scale=2; (${3}*1.8+32)/1") | awk '{print int($1+0.5)}'`
|
temp_warn=`echo $(bc <<< "scale=2; (${3}*1.8+32)/1") | awk '{print int($1+0.5)}'`
|
||||||
# temp_crit=$(bc <<< "scale=2; (${4}*1.8+32)/1")
|
|
||||||
temp_crit=`echo $(bc <<< "scale=2; (${4}*1.8+32)/1") | awk '{print int($1+0.5)}'`
|
temp_crit=`echo $(bc <<< "scale=2; (${4}*1.8+32)/1") | awk '{print int($1+0.5)}'`
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
|
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
|
||||||
temp_f=`echo "scale=1; ${temp_c}*1.8 + 32" | bc`
|
temp_f=$(bc <<< "scale=1; ${temp_c}*1.8+32")
|
||||||
#echo "$temp_c -> $temp_f"
|
#echo "$temp_c -> $temp_f"
|
||||||
c=0; spct=''; spc1=`expr 6 - ${#temp_f}`; until [ $c = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done
|
c=0; spct=''; spc1=`expr 6 - ${#temp_f}`; until [ $c = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done
|
||||||
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
|
||||||
@@ -154,149 +151,150 @@ CHECKTEMP_SERVICE(){
|
|||||||
for SENSOR in ${!PW_SENSOR_ID[@]}; do
|
for SENSOR in ${!PW_SENSOR_ID[@]}; do
|
||||||
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
|
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
|
||||||
[ ! -f ${logtemp} ] && touch ${logtemp}
|
[ ! -f ${logtemp} ] && touch ${logtemp}
|
||||||
errtime=$(expr `date +%s` - $(stat -c %Y ${logtemp}))
|
logtime=$(expr `date +%s` - $(stat -c %Y ${logtemp}))
|
||||||
[ $errtime -ge 3600 ] && relog=1 || relog=0
|
[ ${logtime} -ge 3600 ] && relog=1 || relog=0
|
||||||
|
|
||||||
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" != "esxi" ]; then
|
if [ "${PW_REMOTE_SENSORS[${SENSOR}]}" == "" ] || ([ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSOR}]})" != "false" ]); then
|
||||||
if [ "${PW_REMOTE_SENSORS[${SENSOR}]}" == "" ] || ([ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSOR}]})" != "false" ]); then
|
if [ -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
|
||||||
if [ -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
|
SENDNOTICE "${SENSOR} Online" "${SENSOR} Sensor is back online"
|
||||||
SENDNOTICE "${SENSOR} Online" "${SENSOR} Sensor is back online"
|
echo "($datetime) - ${SENSOR} - ${SENSOR} Sensor is back onlione" >> ${logtemp}
|
||||||
echo "($datetime) - ${SENSOR} - ${SENSOR} Sensor is back onlione" >> ${logtemp}
|
rm -f ${PW_TMPFOLDER}/${SENSOR}.down
|
||||||
rm -f ${PW_TMPFOLDER}/${SENSOR}.down
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
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=''
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
||||||
|
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
|
||||||
|
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}
|
||||||
|
rm -f ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
|
||||||
|
|
||||||
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "mqtt" ]; then
|
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
|
||||||
mqtt_message=`${mqtt_conn} -t tele/${SENSOR}/SENSOR -C 1`
|
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 2 | read temp_crit
|
||||||
echo $mqtt_message | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h
|
echo ${PW_TEMP_THRESHOLDS[${SENSOR}]} | cut -d',' -f 3 | read temp_crit_sys
|
||||||
echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
|
|
||||||
|
|
||||||
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ]; then
|
echo "HERE: ${SENSOR} - ${temp_f} - ${temp_warn} - ${temnp_crit}"
|
||||||
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=''
|
|
||||||
|
|
||||||
|
if [ "${last_temp[${SENSOR}]}" != "" ]; then
|
||||||
|
temp_diff=`expr ${last_temp[${SENSOR}]%.*} - ${temp_f%.*}`
|
||||||
|
[ $temp_diff -lt 0 ] && temp_diff=$(($temp_diff * -1))
|
||||||
|
else
|
||||||
|
last_temp[${SENSOR}]=0
|
||||||
|
temp_diff=0
|
||||||
fi
|
fi
|
||||||
datetime=`date +'%Y-%m-%d %H:%M:%S'`
|
|
||||||
|
|
||||||
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
|
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then
|
||||||
if [ -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ]; then
|
touch ${PW_TMPFOLDER}/temp.warn
|
||||||
SENDNOTICE "${SENSOR} Data" "${SENSOR} is reporting data again"
|
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||||
echo "($datetime) - ${SENSOR} - ${SENSOR} is reporting data again" >> ${logtemp}
|
SENDNOTICE "${SENSOR} TEMP WARNING" "($datetime) WARNING TEMP: ${temp_f}'F - (Difference of ${temp_diff}')" 1
|
||||||
rm -f ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
|
||||||
|
last_temp[${SENSOR}]=$temp_f
|
||||||
fi
|
echo "($datetime) - ${temp_f}'F - WARNING TEMP - (Difference of ${temp_diff}')" >> ${logtemp}
|
||||||
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 [ "${last_temp[${SENSOR}]}" != "" ]; then
|
|
||||||
temp_diff=`expr ${last_temp[${SENSOR}]%.*} - ${temp_f%.*}`
|
|
||||||
[ $temp_diff -lt 0 ] && temp_diff=$(($temp_diff * -1))
|
|
||||||
else
|
|
||||||
last_temp[${SENSOR}]=0
|
|
||||||
temp_diff=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -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.warn
|
touch ${PW_TMPFOLDER}/temp.crit
|
||||||
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
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
|
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')
|
||||||
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
|
Shutting down servers!!" 1
|
||||||
last_temp[${SENSOR}]=$temp_f
|
echo "($datetime) - ${temp_f}'F - CRITICAL - (Difference of ${temp_diff}'F)" >> ${logtemp}
|
||||||
echo "($datetime) - ${temp_f}'F - WARNING TEMP - (Difference of ${temp_diff}')" >> ${logtemp}
|
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
|
||||||
fi
|
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}
|
||||||
|
|
||||||
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}')
|
|
||||||
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}')" >> ${PW_LOGFILE}
|
|
||||||
last_temp[${SENSOR}]=$temp_f
|
|
||||||
SHUTDOWN_MAIN ${SENSOR} &
|
|
||||||
echo -e "($datetime) - ${temp_f}'F - Shutting down MAIN servers" >> ${logtemp}
|
|
||||||
|
|
||||||
fi
|
|
||||||
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}')
|
|
||||||
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}')" >> ${PW_LOGFILE}
|
|
||||||
last_temp[${SENSOR}]=$temp_f
|
|
||||||
SHUTDOWN_SYS ${SENSOR} TEMP &
|
|
||||||
SHUTDOWN_CRIT ${SENSOR} &
|
|
||||||
echo -e "($datetime) - ${temp_f}'F - Shutting down SYS servers" >> ${logtemp}
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[ ! -f ${PW_TMPFOLDER}/temp.* ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.${SENSOR}.sentdaily)) -gt 600 ] && [ $(date +%H)$(date +%M) -ge 0700 ] && [ $(date +%H)$(date +%M) -lt 0705 ] && touch ${PW_TMPFOLDER}/.${SENSOR}.sentdaily && SENDNOTICE "Daily Temp Readings" "$(DAILYTEMP)" &
|
|
||||||
|
|
||||||
if [ ${last_temp[${SENSOR}]} -gt 1 ]; then
|
|
||||||
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 "($datetime) - ${temp_f}'F - alert sent" >> ${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
|
|
||||||
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}
|
|
||||||
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
|
|
||||||
|
|
||||||
elif [ $relog -eq 1 ]; then
|
|
||||||
echo "($datetime) - ${temp_f}'F - Normal Temp" >> ${logtemp}
|
|
||||||
|
|
||||||
fi
|
|
||||||
rm -f ${PW_TMPFOLDER}/temp.*
|
|
||||||
last_temp[${SENSOR}]=1
|
|
||||||
fi
|
fi
|
||||||
|
elif [ $(bc -l <<< "$temp_f >= $temp_crit_sys") -eq 1 ]; then
|
||||||
[ -f ${PW_TMPFOLDER}/${SENSOR}.insert ] && lastinsert=$(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.insert)) || lastinsert=100000
|
touch ${PW_TMPFOLDER}/temp.critsys
|
||||||
if [ "$(compgen -G "${PW_TMPFOLDER}/temp.*")" != "" ] || [ "$(compgen -G "${PW_TMPFOLDER}/power.ac.*")" != "" ] || [ "$(compgen -G "${PW_TMPFOLDER}/power.dc.*")" != "" ]; then
|
if [ $temp_diff -gt 1 ] || [ "${last_temp[${SENSOR}]}" = "1" ]; then
|
||||||
wait=60
|
SENDNOTICE "${SENSOR} TEMP CRITICAL" "($datetime) SYSTEM CRITICAL TEMP: ${temp_f}'F - (Difference of ${temp_diff}')
|
||||||
else
|
Shutting down system servers!!" 1
|
||||||
wait=300
|
echo "($datetime) - ${temp_f}'F - SYSTEM CRITICAL - (Difference of ${temp_diff})" >> ${logtemp}
|
||||||
fi
|
echo "($datetime) - ${temp_f}'F - alert sent" >> ${logtemp}
|
||||||
if [ ${lastinsert} -ge ${wait} ]; then
|
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - CRITICAL TEMP SYSTEM - (Difference of ${temp_diff}')" >> ${PW_LOGFILE}
|
||||||
if [ "${temp_h}" != "" ]; then
|
last_temp[${SENSOR}]=$temp_f
|
||||||
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`, \`hum\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}','${temp_h}')"
|
SHUTDOWN_SYS ${SENSOR} TEMP &
|
||||||
else
|
SHUTDOWN_CRIT ${SENSOR} &
|
||||||
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}')"
|
echo -e "($datetime) - ${temp_f}'F - Shutting down SYS servers" >> ${logtemp}
|
||||||
fi
|
|
||||||
${mysql_conn} -e "${QRY}"
|
|
||||||
touch ${PW_TMPFOLDER}/${SENSOR}.insert
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 1800 ]; then
|
[ ! -f ${PW_TMPFOLDER}/temp.* ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.${SENSOR}.sentdaily)) -gt 600 ] && [ $(date +%H)$(date +%M) -ge 0700 ] && [ $(date +%H)$(date +%M) -lt 0705 ] && touch ${PW_TMPFOLDER}/.${SENSOR}.sentdaily && SENDNOTICE "Daily Temp Readings" "$(DAILYTEMP)" &
|
||||||
SENDNOTICE "${SENSOR} Sensor ERROR" "($datetime) ERROR reading sensor data" 1
|
|
||||||
echo "($datetime) - ${SENSOR} Sensor - ERROR reading sensor data" >> ${logtemp}
|
if [ ${last_temp[${SENSOR}]} -gt 1 ]; then
|
||||||
touch ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
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 "($datetime) - ${temp_f}'F - alert sent" >> ${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
|
||||||
|
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}
|
||||||
|
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
|
||||||
|
|
||||||
|
elif [ $relog -eq 1 ]; then
|
||||||
|
echo "($datetime) - ${temp_f}'F - Normal Temp" >> ${logtemp}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
rm -f ${PW_TMPFOLDER}/temp.*
|
||||||
|
last_temp[${SENSOR}]=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else #sensor down
|
[ -f ${PW_TMPFOLDER}/${SENSOR}.insert ] && lastinsert=$(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.insert)) || lastinsert=100000
|
||||||
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
|
if [ "$(compgen -G "${PW_TMPFOLDER}/temp.*")" != "" ] || [ "$(compgen -G "${PW_TMPFOLDER}/power.ac.*")" != "" ] || [ "$(compgen -G "${PW_TMPFOLDER}/power.dc.*")" != "" ]; then
|
||||||
SENDNOTICE "${SENSOR} ERROR" "${SENSOR} Sensor is down" 1
|
wait=60
|
||||||
echo "($datetime) - ${SENSOR} - ${SENSOR} Sensor is down" >> ${logtemp}
|
else
|
||||||
touch ${PW_TMPFOLDER}/${SENSOR}.down
|
wait=300
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
if [ ${lastinsert} -ge ${wait} ]; then
|
||||||
|
if [ "${temp_h}" != "" ]; then
|
||||||
|
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`, \`hum\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}','${temp_h}')"
|
||||||
|
else
|
||||||
|
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}')"
|
||||||
|
fi
|
||||||
|
${mysql_conn} -e "${QRY}"
|
||||||
|
touch ${PW_TMPFOLDER}/${SENSOR}.insert
|
||||||
|
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}
|
||||||
|
touch ${PW_TMPFOLDER}/${SENSOR}-error.reading
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user