Update powerwall.sh
This commit is contained in:
37
powerwall.sh
37
powerwall.sh
@@ -18,7 +18,8 @@ VERBOSE=false
|
|||||||
CHECKTEMP(){
|
CHECKTEMP(){
|
||||||
cw=20;
|
cw=20;
|
||||||
echo
|
echo
|
||||||
echo -e "${idsCL[Yellow]}Sensor Temperature(s) ${idsCL[Green]}normal${idsCL[Default]} /${idsCL[Yellow]}warning${idsCL[Default]}/ ${idsCL[Red]}critical${idsCL[Default]}"
|
# echo -e "${idsCL[Yellow]}Sensor Temperature(s) ${idsCL[Green]}normal${idsCL[Default]} /${idsCL[Yellow]}warning${idsCL[Default]}/ ${idsCL[Red]}critical${idsCL[Default]}"
|
||||||
|
echo -e "${idsCL[Yellow]}Sensor Temperature(s) Current/7DayAVG ${idsCL[Green]}normal${idsCL[Default]} /${idsCL[Yellow]}warning${idsCL[Default]}/ ${idsCL[Red]}critical${idsCL[Default]}"
|
||||||
DIVIDER . yellow 75
|
DIVIDER . yellow 75
|
||||||
if [ "${1}" != "" ]; then
|
if [ "${1}" != "" ]; then
|
||||||
# reading=$(CHECKTEMPSENSOR ${1})
|
# reading=$(CHECKTEMPSENSOR ${1})
|
||||||
@@ -45,6 +46,7 @@ CHECKTEMP(){
|
|||||||
CHECKTEMPSENSOR(){
|
CHECKTEMPSENSOR(){
|
||||||
echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn
|
echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn
|
||||||
echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit
|
echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit
|
||||||
|
average=$(AVERAGETEMP ${SENSOR_ID[${1}]} 7)
|
||||||
|
|
||||||
if [ "${SENSOR_TYPE[${1}]}" == "mqtt" ]; then
|
if [ "${SENSOR_TYPE[${1}]}" == "mqtt" ]; then
|
||||||
mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1`
|
mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1`
|
||||||
@@ -61,11 +63,11 @@ CHECKTEMPSENSOR(){
|
|||||||
#echo "$temp_c -> $temp_f"
|
#echo "$temp_c -> $temp_f"
|
||||||
|
|
||||||
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 ($temp_f'F)${idsCL[Default]}"
|
echo -en "${idsCL[Yellow]}WARNING (${temp_f}'F/${average}'F)${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 ($temp_f'F)${idsCL[Default]}"
|
echo -en "${idsCL[Red]}CRITICAL (${temp_f}'F/${average}'F)${idsCL[Default]}"
|
||||||
else
|
else
|
||||||
echo -en "${idsCL[Green]}Normal ($temp_f'F)${idsCL[Default]}"
|
echo -en "${idsCL[Green]}Normal (${temp_f}'F/${average}'F)${idsCL[Default]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
c=0; spc=''; spc1=`expr 13 - ${#temp_f} - 2`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
c=0; spc=''; spc1=`expr 13 - ${#temp_f} - 2`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
|
||||||
@@ -74,6 +76,19 @@ CHECKTEMPSENSOR(){
|
|||||||
echo -e "${spc}[${spcw}${idsCL[Green]}<=$(expr ${temp_warn} - 1)'F${idsCL[Default]} /${spcw}${idsCL[Yellow]}${temp_warn}'F${idsCL[Default]} /${spcc}${idsCL[Red]}${temp_crit}'F${idsCL[Default]} ]"
|
echo -e "${spc}[${spcw}${idsCL[Green]}<=$(expr ${temp_warn} - 1)'F${idsCL[Default]} /${spcw}${idsCL[Yellow]}${temp_warn}'F${idsCL[Default]} /${spcc}${idsCL[Red]}${temp_crit}'F${idsCL[Default]} ]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
AVERAGETEMP(){
|
||||||
|
temptotal=0
|
||||||
|
daysback=${2}
|
||||||
|
sensorid=${1}
|
||||||
|
logsfound=0;
|
||||||
|
while IFS=$'\t' read date sensorid temp hum ;do
|
||||||
|
temptotal=$(bc <<< "scale=2; ${temptotal}+${temp}")
|
||||||
|
((logsfound++))
|
||||||
|
done < <(${mysql_conn} -se "USE servermonitor; SELECT date,sensorid,temp,hum from sensor_data WHERE sensorid=${sensorid} AND date BETWEEN
|
||||||
|
DATE_SUB(DATE(NOW()), INTERVAL ${daysback} DAY) AND NOW() ORDER BY id DESC;")
|
||||||
|
average=$(bc <<< "scale=2; ${temptotal}/${logsfound}")
|
||||||
|
echo ${average}
|
||||||
|
}
|
||||||
|
|
||||||
CHECKTEMP_SERVICE(){
|
CHECKTEMP_SERVICE(){
|
||||||
cw=20
|
cw=20
|
||||||
@@ -382,20 +397,6 @@ POWERLOGGER_SERVICE(){
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
AVERAGETEMP(){
|
|
||||||
temptotal=0
|
|
||||||
daysback=${2}
|
|
||||||
sensorid=${1}
|
|
||||||
logsfound=0;
|
|
||||||
while IFS=$'\t' read date sensorid temp hum ;do
|
|
||||||
temptotal=$(bc <<< "scale=2; ${temptotal}+${temp}")
|
|
||||||
((logsfound++))
|
|
||||||
done < <(${mysql_conn} -se "USE servermonitor; SELECT date,sensorid,temp,hum from sensor_data WHERE sensorid=${sensorid} AND date BETWEEN
|
|
||||||
DATE_SUB(DATE(NOW()), INTERVAL ${daysback} DAY) AND NOW() ORDER BY id DESC;")
|
|
||||||
average=$(bc <<< "scale=2; ${temptotal}/${logsfound}")
|
|
||||||
echo ${average}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user