Update temp.inc.sh

This commit is contained in:
2024-04-28 21:56:34 -05:00
parent 116b0e730f
commit 32a2a04ace

View File

@@ -127,30 +127,33 @@ CHECKTEMP(){
until [ ${c} = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done
reading="${lclr}${lmd}${spct}${temp_f_disp}${GAUGESH}"
if [ "${avgdays}" = "noavg" ] && [[ "${SENSOR}" != *"FAN"* ]] && [ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1)+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1)-${PW_TEMPIND_DIFF}" | bc) < ${temp_f}") -eq 1 ]; then
OLD1_temp_f=$(${mysql_conn} -e "SELECT temp FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL 30 MINUTE) ORDER BY date ASC LIMIT 1")
OLD2_temp_f=$(${mysql_conn} -e "SELECT temp FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL 60 MINUTE) ORDER BY date ASC LIMIT 1")
if [ "${avgdays}" = "noavg" ] && [[ "${SENSOR}" != *"FAN"* ]] && [ "${OLD1_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; ${OLD1_temp_f}+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD1_temp_f}-${PW_TEMPIND_DIFF}" | bc) < ${temp_f}") -eq 1 ]; then
reading="${reading} ${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1)+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD1_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
reading="${reading} ${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "$(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1) < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "${OLD1_temp_f} < ${temp_f}") -eq 1 ]; then
reading="${reading} ${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1)-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD1_temp_f}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
reading="${reading} ${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old | cut -d'~' -f 1)") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < ${OLD1_temp_f}") -eq 1 ]; then
reading="${reading} ${idsCL[LightCyan]}\u25BC "
else
reading="${reading} "
fi
if [ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1)+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1)-${PW_TEMPIND_DIFF}" | bc) < ${temp_f}") -eq 1 ]; then
if [ "${OLD2_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; ${OLD2_temp_f}+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD2_temp_f}-${PW_TEMPIND_DIFF}" | bc) < ${temp_f}") -eq 1 ]; then
reading="${reading}${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1)+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD2_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
reading="${reading}${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "$(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1) < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "${OLD2_temp_f} < ${temp_f}") -eq 1 ]; then
reading="${reading}${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1)-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD2_temp_f}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
reading="${reading}${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2 | cut -d'~' -f 1)") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < ${OLD2_temp_f}") -eq 1 ]; then
reading="${reading}${idsCL[LightCyan]}\u25BC "
else
reading="${reading} "
@@ -305,6 +308,10 @@ CHECKTEMP(){
c=0; spc=''; spc1=`expr ${cw} - ${#sensorname} - 1`; until [ ${c} = ${spc1} ]; do spc="${spc} "; c=`expr ${c} + 1`; done
IFS=: read -r temp_f temp_h <<< $(CHECKTEMPSENSOR ${SENSOR}); unset IFS
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${sensorname// /_}' AND sensorid='${PW_SENSOR_ID[${SENSOR}]}'"))
OLD1_temp_f=$(${mysql_conn} -e "SELECT temp FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND entity=${entityid[1]} AND date >= DATE_SUB(NOW(), INTERVAL 30 MINUTE) ORDER BY date ASC LIMIT 1")
OLD2_temp_f=$(${mysql_conn} -e "SELECT temp FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND entity=${entityid[1]} AND date >= DATE_SUB(NOW(), INTERVAL 60 MINUTE) ORDER BY date ASC LIMIT 1")
if [ $(bc -l <<< "${temp_f} >= ${temp_crit}") -eq 1 ] || ([ "${TTYPE}" == "fans" ] && [ $(bc -l <<< "${temp_f} > $(bc <<< "scale=2; ${GL_HIGH}+5")") -eq 1 ]); then
lclr="${idsCL[LightRed]}"
lmd="CRITICAL"
@@ -322,30 +329,30 @@ CHECKTEMP(){
reading="${lclr}${lmd}${spct}${temp_f}${GAUGESH}"
echo -en "${idsCL[LightCyan]} ${sensorname}${spc}${idsCL[Default]}: ${reading}"
if [ "${temp_f}" != "" ] && [ "${average}" = "" ] && [ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old ]; then
if [ $(bc -l <<< "${temp_f} <= $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1)+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "${temp_f} >= $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1)-${PW_TEMPIND_DIFF}" | bc)") -eq 1 ]; then
if [ "${temp_f}" != "" ] && [ "${average}" = "" ] && [ "${OLD1_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} <= $(echo "scale=2; ${OLD1_temp_f}+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "${temp_f} >= $(echo "scale=2; ${OLD1_temp_f}-${PW_TEMPIND_DIFF}" | bc)") -eq 1 ]; then
echo -en " ${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1)+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD1_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en " ${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "$(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1) < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "${OLD1_temp_f} < ${temp_f}") -eq 1 ]; then
echo -en " ${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1)-(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD1_temp_f}-(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en " ${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old | cut -d'~' -f 1)") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < ${OLD1_temp_f}") -eq 1 ]; then
echo -en " ${idsCL[LightCyan]}\u25BC "
else
echo -en " "
fi
if [ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 ]; then
if [ $(bc -l <<< "${temp_f} <= $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1)+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "${temp_f} >= $(echo "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1)-${PW_TEMPIND_DIFF}" | bc)") -eq 1 ]; then
if [ "${OLD2_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} <= $(echo "scale=2; ${OLD2_temp_f}+${PW_TEMPIND_DIFF}" | bc)") -eq 1 ] && [ $(bc -l <<< "${temp_f} >= $(echo "scale=2; ${OLD2_temp_f}-${PW_TEMPIND_DIFF}" | bc)") -eq 1 ]; then
echo -en "${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1)+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD2_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "$(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1) < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "${OLD2_temp_f} < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1)-(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD2_temp_f}-(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < $(cat ${PW_TMPFOLDER}/.lastinsert/${SENSOR}-${sensorname// /_}.old2 | cut -d'~' -f 1)") -eq 1 ]; then
elif [ $(bc -l <<< "${temp_f} < ${OLD2_temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightCyan]}\u25BC "
else
echo -en " "
@@ -1068,18 +1075,18 @@ Previous Temp: ${last_temp}${GAUGESH}"
# fi
fi
#### TRACKING TEMP CHANGES
if [ "${temp_f}" != "" ] && [[ "${SENSOR}" != *"CPU-Usage"* ]] && [[ "${SENSOR}" != *"FAN"* ]]; then
if [ ! -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre ]; then
echo "${temp_f}" > ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre
elif [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre)) -ge 1800 ]; then
[ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old ] && mv -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2
mv -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old
echo "${temp_f}" > ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre
fi
fi
# #### TRACKING TEMP CHANGES
# if [ "${temp_f}" != "" ] && [[ "${SENSOR}" != *"CPU-Usage"* ]] && [[ "${SENSOR}" != *"FAN"* ]]; then
# if [ ! -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre ]; then
# echo "${temp_f}" > ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre
#
# elif [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre)) -ge 1800 ]; then
# [ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old ] && mv -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old2
# mv -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.old
# echo "${temp_f}" > ${PW_TMPFOLDER}/.lastinsert/${SENSOR}.pre
#
# fi
# fi
#### LOGGING OF SERVERROOM SENSOR DIFFERENCE
if [ "${SENSOR}" == "ServerRoom-Rear" ]; then