Files
powerwall/inc/temp.inc.sh
2025-08-31 11:10:27 -05:00

1917 lines
106 KiB
Bash

GET_HOST_FANSPEED(){
if [ -f ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]} ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]})) -lt 600 ] && ([ ! -f ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]}.set ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]})) -lt $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]}.set)) ]); then
FanSpeed=$(cat ${PW_TMPFOLDER}/.lastfancheck/${PW_ESXI_HOST_NAMES[${1}]})
else
[[ "${PW_HOST_IDRACS[${PW_ESXI_HOST_NAMES[${1}]}]}" = "10.6."* ]] && ESXI_PASS=${PW_ESXI_PASS_KP} || ESXI_PASS=${PW_ESXI_PASS}
if [ "${IP}" = "10.2.1.5" ]; then
vHOSTFAN=$(${SSHCMD} root@${PW_RACADM_ACCESS} racadm -r ${PW_HOST_IDRACS[${PW_ESXI_HOST_NAMES[${1}]}]} -u ${PW_ESXI_USER} -p "'${ESXI_PASS}'" getsensorinfo | grep "System Board Fan3" 2>&1)
else
vHOSTFAN=$(racadm -r ${PW_HOST_IDRACS[${PW_ESXI_HOST_NAMES[${1}]}]} -u ${PW_ESXI_USER} -p "${ESXI_PASS}" getsensorinfo | grep "System Board Fan3" 2>&1)
fi
if [ "$(echo ${vHOSTFAN} | awk '/ / {print $4}' | sed -e 's/%//g')" == "RPM" ]; then
FanSpeed=$(echo ${vHOSTFAN} | awk '/ / {print $9}' | sed -e 's/%//g')
else
FanSpeed=$(echo ${vHOSTFAN} | awk '/ / {print $8}' | sed -e 's/%//g')
fi
fi
echo ${FanSpeed} > ${PW_TMPFOLDER}/.local.fanspeed.${PW_ESXI_HOST_NAMES[${1}]}.${2}
}
START_POWERWALL_FAN(){
PWCMD="${SSHCMD} root@${PW_REMOTE_SENSORS['Powerwall-FAN']}"
${PWCMD} pwmconfig &
sleep 4s
${PWCMD} killall pwmconfig >/dev/null 2>&1
if ${PWCMD} [ -f ${PW_FANINPUT} ]; then
temp_c=$(${PWCMD} cat ${PW_FANINPUT})
if [ ${temp_c} -gt 0 ]; then
fs=$(IDS_NUMBER_FORMAT ${temp_c})
SENDNOTICE "Starting up the ${SENSOR}" "Startup confirmed, the fan is now reading: ${fs}'RPM"
else
SENDNOTICE "FAILED to start ${SENSOR}" "Cannot start the fan, ERROR WILL ROBINSON!!!" 1
fi
else
SENDNOTICE "FAILED to start ${SENSOR}" "Cannot find hardware, ERROR ERROR ERROR... DOES NOT COMPUTE... YOU SUCK" 1
fi
}
CHECKTEMP(){
start=`date +%s`
cw=25
cdt=$(date +%Y-%m-%d-%H-%M-%S)
REPORT=0; DETAILS=0; exclude=''; drives=0
while [ $# -gt 0 ]; do
case "$1" in
-a|-avg) avgdays=${2};;
-S|-sensors) TTYPE="sensors";;
-o|-offsite) STYPE=offsite;;
-m|-mainsite) STYPE=mainsite;;
-k|-kyle) STYPE=kyle;;
-e|-esxi) TTYPE="esxi";;
-D|-drives) drives=1;;
-f|-fans) TTYPE="fans";;
-s|-search) search=${2};;
-x|-exclude) exclude=${2};;
-d|-detail) DETAILS=1;;
-md|-minidetail) DETAILS=2;;
-r|-report)
REPORT=1
unset idsCL idsBG idsST
idsCL=('')
idsBG=('')
idsST=('')
;;
esac
shift 1
done
if [ "${TTYPE}" != "sensors" ]; then
for ESXIHOST in "${PW_ALLHOSTS[@]}"; do
if [ ! -f ${PW_TMPFOLDER}/${PW_ESXI_HOST_NAMES[${ESXIHOST}]}.down ] && ([ "${search}" == "" ] || ([[ "${PW_ESXI_HOST_NAMES[${ESXIHOST}],,}" = *"${search,,}"* ]] && ([ "${exclude}" == "" ] || [[ ! "${PW_ESXI_HOST_NAMES[${ESXIHOST}],,}" = *"${exclude,,}"* ]]))); then
[[ " ${PW_SENSOR_ORD[*]} " =~ "${PW_ESXI_HOST_NAMES[${ESXIHOST}]}" ]] && GET_HOST_FANSPEED ${ESXIHOST} ${cdt} &
fi
done
[ "${PW_ESXI_DEF_FANSPEED}" != "" ] && ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED} || ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED}
[ "${PW_ESXI_FANSPEED_GL_ZONE}" != "" ] && ESXI_FANSPEED_GL_ZONE=${PW_ESXI_FANSPEED_GL_ZONE} || ESXI_FANSPEED_GL_ZONE=2.5
fi
echo
if [ "${avgdays}" != "" ]; then
if [[ "${avgdays^^}" = *"M"* ]]; then
avgdays_disp="${avgdays::-1}Min"
elif [[ "${avgdays^^}" = *"H"* ]]; then
avgdays_disp="${avgdays::-1}Hr"
elif [[ "${avgdays^^}" = *"D"* ]]; then
avgdays_disp="${avgdays::-1}Day"
elif [[ "${avgdays}" =~ ^[0-9]+$ ]]; then
avgdays_disp="${avgdays}Day"
fi
c=0; spchdr=''; spc1=`expr 7 - ${#avgdays_disp}`; until [ ${c} = ${spc1} ]; do spchdr="${spchdr} "; ((c++)); done
else
avgdays=noavg
fi
if [ "${TTYPE}" != "esxi" ] && [ "${TTYPE}" != "fans" ]; then
DIVIDER . yellow ${PRI_WIDTH}
if [ "${avgdays}" != "noavg" ]; then
echo -e "${idsCL[LightYellow]}SENSOR TEMPERATURE(S) Current / ${idsCL[LightYellow]}${avgdays_disp}AVG${spchdr}${idsCL[Yellow]}warning${idsCL[Default]} / ${idsCL[LightRed]}critical${idsCL[Default]}"
else
echo -e "${idsCL[LightYellow]}SENSOR TEMPERATURE(S) Current ${idsCL[Yellow]}warning${idsCL[Default]} / ${idsCL[LightRed]}critical${idsCL[Default]}"
fi
DIVIDER . yellow ${PRI_WIDTH}
for SENSOR in ${PW_SENSOR_ORD[@]}; do
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" != "esxi" ] && ([ "${exclude}" == "" ] || [[ ! "${SENSOR,,}" = *"${exclude,,}"* ]]) && ([ "${search}" == "" ] || ([[ "${SENSOR,,}" = *"${search,,}"* ]] && [ "${PW_DESC_TEMP[${SENSOR}]}" == "" ]) || [[ "${PW_DESC_TEMP[${SENSOR}],,}" = *"${search,,}"* ]]) && ([ "${STYPE}" = "" ] || ([ "${STYPE}" = "mainsite" ] && ([ "${PW_REMOTE_SENSORS[${SENSOR}]}" = "" ] || [ "${PW_REMOTE_SENSORS[${SENSOR}]}" = "127.0.0.1" ] || [[ "${PW_REMOTE_SENSORS[${SENSOR}]}" = *"10.10."* ]])) || ([ "${STYPE}" = "offsite" ] && [ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [[ "${PW_REMOTE_SENSORS[${SENSOR}]}" = *"10.2.1."* ]]) || ([ "${STYPE}" = "kyle" ] && [ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [[ "${PW_REMOTE_SENSORS[${SENSOR}]}" = *"10.6.1."* ]])) && ([ "${TTYPE}" != "fans" ] || ([ "${TTYPE}" == "fans" ] && (([[ "${SENSOR}" = *"Room"* ]] && [ "${PW_DESC_TEMP[${SENSOR}]}" == "" ]) || [[ "${PW_DESC_TEMP[${SENSOR}]}" = *"Room" ]])) && ([ "${PW_SENSOR_DEVICEID[${SENSOR}]}" != "" ] || ([ "${PW_SENSOR_DEVICEID[${SENSOR}]}" == "" ] && [ "${TTYPE}" != "sensors" ]))); then
[ "${PW_DESC_TEMP[${SENSOR}]}" != "" ] && SENSOR_DESC=${PW_DESC_TEMP[${SENSOR}]} || SENSOR_DESC=${SENSOR}
if [ "${PW_THRESHOLDS[${SENSOR}]}" != "" ]; then
echo ${PW_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
echo ${PW_THRESHOLDS[${SENSOR}]} | cut -d',' -f 2 | read temp_crit
fi
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
# temp_f_disp=$(IDS_NUMBER_FORMAT ${temp_f} 0)
temp_warn_disp=$(IDS_NUMBER_FORMAT ${temp_warn} 0)
temp_crit_disp=$(IDS_NUMBER_FORMAT ${temp_crit} 0)
else
# temp_f_disp=${temp_f}
temp_warn_disp=${temp_warn}
temp_crit_disp=${temp_crit}
fi
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "cpu" ]; then
GAUGESH="'%"
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
GAUGESH="'R"
else
GAUGESH="°F"
fi
[ ${REPORT} -eq 0 ] && [ ${DETAILS} -eq 0 ] && ([ "${last_sensor%%-*}" == "${SENSOR_DESC%%-*}" ] && [ "${SENSOR_DESC%%-*}" != "ServerRoomXXXX" ]) && [ "${last_sensor}" != "Offsite-ServerRoom" ] && echo -en "\033[1A"
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR_DESC}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
[ ${REPORT} -eq 0 ] && echo -en "\r\033[K${idsCL[White]}${idsST[Bold]}${SENSOR_DESC}${idsST[Reset]}${spc}${idsCL[Default]}: ${idsCL[Yellow]}Pulling data ... "
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
IFS=: read -r temp_f temp_h <<< $(CHECKTEMPSENSOR ${SENSOR}); unset IFS
if [ "${temp_f}" != "timeout" ] && [ "${temp_f}" != "offline" ]; then
[ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]] && temp_f_disp=$(IDS_NUMBER_FORMAT ${temp_f} 0) || temp_f_disp=${temp_f}
if [ $(bc -l <<< "${temp_f} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}") -eq 1 ]; then
lclr="${idsCL[Yellow]}"
lmd="WARNING "
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit}") -eq 1 ]; then
lclr="${idsCL[LightRed]}"
lmd="CRITICAL"
else
lclr="${idsCL[Green]}"
lmd="Normal "
fi
c=0; spct=''; [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]] && spc1=`expr 4 - ${#temp_f}` || spc1=`expr 7 - ${#temp_f}`
until [ ${c} = ${spc1} ]; do spct="${spct} "; ((c++)); done
if [[ "${SENSOR}" = *"FAN"* ]]; then
if [ ${#temp_f} -eq 5 ]; then
reading="${lclr}${lmd}${spct}${temp_f:0:2},${temp_f:2:3}${GAUGESH}"
elif [ ${#temp_f} -eq 4 ]; then
reading="${lclr}${lmd}${spct}${temp_f:0:1},${temp_f:1:3}${GAUGESH}"
else
reading="${lclr}${lmd}${spct}${temp_f}${GAUGESH}"
fi
else
reading="${lclr}${lmd}${spct}"$(IDS_NUMBER_FORMAT ${temp_f} 2 yes)"${GAUGESH}"
fi
[ ${REPORT} -eq 0 ] && echo -en "\r\033[K"
echo -en "${idsCL[White]}${idsST[Bold]}${SENSOR_DESC}${idsST[Reset]}${spc}${idsCL[Default]}: ${reading} "
if [ ${DETAILS} -eq 2 ] && [ "${avgdays}" = "noavg" ] && [[ "${SENSOR}" != *"FAN"* ]]; then
for R in ${PW_TEMPIND_RANGE[@]}; do
[ "${mysql_conn}" != "" ] && OLD_temp_f=($(${mysql_conn} -e "SELECT temp FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${R} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${R} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
if [ "${OLD_temp_f[1]}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; (${OLD_temp_f[1]}+${PW_TEMPIND_DIFF})/1" | tr -d $'\r' | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD_temp_f[1]}-${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc) < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD_temp_f[1]}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "${OLD_temp_f[1]} < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD_temp_f[1]}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
echo -en "${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < ${OLD_temp_f[1]}") -eq 1 ]; then
echo -en "${idsCL[LightCyan]}\u25BC "
else
echo -en " "
fi
else
echo -en "${idsCL[Default]}\u22C5 "
fi
done
elif [ "${avgdays}" = "noavg" ]; then
c=0; spca=''; until [ ${c} = ${#PW_TEMPIND_RANGE[@]} ]; do spca="${spca} "; ((c++)); done
echo -en "${spca}"
fi
else
temp_f_disp=" "
lclr="${idsCL[Yellow]}"
lmd=""
echo -en "${idsCL[Yellow]}Sensor ${temp_f^} "
temp_f=""
fi
else
temp_f=""
temp_f_disp=" "
lclr="${idsCL[Yellow]}"
lmd=""
echo -en "\r\033[K${idsCL[White]}${idsST[Bold]}${SENSOR_DESC}${idsST[Reset]}${spc}${idsCL[Default]}: ${idsCL[Yellow]}Sensor Offline "
fi
[ ${REPORT} -eq 0 ] && echo -en "${idsCL[Default]}"
if [ "${avgdays}" != "noavg" ]; then
echo -en " / ${idsCL[Yellow]}Calculating ${avgdays_disp} average ... "
average=$(AVERAGETEMP ${SENSOR} ${avgdays})
([ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]) && average_disp=$(IDS_NUMBER_FORMAT ${average}) || average_disp=${average}
c=0; spca=''; spc1=`expr 6 - ${#average_disp}`; until [ ${c} = ${spc1} ]; do spca="${spca} "; ((c++)); done
if [ "${average_disp}" == "" ]; then
averagedisp="${idsCL[Green]}"
elif [ $(bc -l <<< "${average} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${average} < ${temp_crit}") -eq 1 ]; then
averagedisp="${idsCL[Yellow]}${average}"
elif [ $(bc -l <<< "${average} >= ${temp_crit}") -eq 1 ]; then
averagedisp="${idsCL[LightRed]}${average_disp}"
else
averagedisp="${idsCL[Green]}${average_disp}"
fi
echo -en "\r\033[K${idsCL[White]}${idsST[Bold]}${SENSOR_DESC}${idsST[Reset]}${spc}${idsCL[Default]}: ${reading} ${idsCL[Default]}/${spca}${averagedisp}${GAUGESH}"
fi
if ([ "${average}" != "" ] || [ "${temp_f}" != "" ]) && [[ "${SENSOR}" != *"FAN"* ]]; then
if [ "${average}" != "" ]; then
fws=10
tmp="${spca}${average_disp}${GAUGESH}"
else
fws=$(expr 20 - $(expr ${#PW_TEMPIND_RANGE[@]} \* 2))
tmp="${spct}${temp_f_disp}${GAUGESH}"
fi
c=0; spc=''; spc1=`expr ${fws} - ${#tmp}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
[ ${#temp_warn} == 2 ] && spcw=' ' || spcw=' '
[ ${#temp_crit} == 2 ] && spcc=' ' || spcc=' '
echo -en
echo -en "${idsCL[Default]}${spc}[${spcw}${idsCL[Yellow]}${temp_warn_disp}${GAUGESH}${idsCL[Default]} /${spcc}${idsCL[LightRed]}${temp_crit_disp}${GAUGESH}=>${idsCL[Default]} ]"
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "lacrosse" ] && [[ "${SENSOR}" != *"-ProbeXXX" ]]; then
INFO=$(curl -m 8 -s --get -d "deviceid=${PW_SENSOR_DEVICEID[${SENSOR}]}" -d "limit=1" -d "metric=1" -d "timezone=2" https://decent-destiny-704.appspot.com/laxservices/device_info.php)
infDT=$(echo ${INFO} | jq -r '.device0 .obs[].timestamp')
echo -e " - ${infDT/\/2025/}"
else
echo
fi
else
echo -e "${idsCL[Default]}"
fi
### DETAILS VIEW
if [ ${DETAILS} -eq 1 ] && [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && [ "${temp_f}" != "timeout" ] && [ "${temp_f}" != "offline" ]; then
DIVIDER . white ${PRI_WIDTH}
for M in 5 15 30 60 120; do
lico=" "
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
spc_cnt=6
[ "${mysql_conn}" != "" ] && OLD_temp_f=($(${mysql_conn} -e "SELECT speed,date FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${M} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${M} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
else
spc_cnt=7
[ "${mysql_conn}" != "" ] && OLD_temp_f=($(${mysql_conn} -e "SELECT temp,date FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${M} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${M} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
fi
OLD_temp_f=${OLD_temp_f[2]}
OLD_date=${OLD_temp_f[3]}
OLD_time=${OLD_temp_f[4]}
if [ "${OLD_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; ${OLD_temp_f}+${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD_temp_f}-${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc) < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[White]}"
lico="\u23F9"
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[LightRed]}"
lico="\u25B2"
elif [ $(bc -l <<< "${OLD_temp_f} < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[Magenta]}"
lico="\u25B2"
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD_temp_f}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
lclr="${idsCL[LightGreen]}"
lico="\u25BC"
elif [ $(bc -l <<< "${temp_f} < ${OLD_temp_f}") -eq 1 ]; then
lclr="${idsCL[LightCyan]}"
lico="\u25BC"
else
lclr="${idsCL[Default]}"
fi
else
lclr="${idsCL[Default]}"
lico="\u22C5"
fi
([ "${temp_h}" != "" ] && [ "${temp_h}" != "0" ]) && echo -en "${idsCL[White]}| " || echo -n " "
echo -en "${idsCL[Default]} "
if [ ${#M} -eq 1 ]; then
echo -n " "
elif [ ${#M} -lt 3 ]; then
c=0; spc1=`expr ${#M} - 1`
until [ ${c} = ${spc1} ]; do
echo -n " "
((c++))
done
fi
if [ "${OLD_temp_f}" != "" ]; then
c=0; spc=''; spc1=`expr ${spc_cnt} - ${#OLD_temp_f}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
echo -en "~${M}m ago - ${lclr}${lico}${spc}"
[ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]] && echo -en "$(IDS_NUMBER_FORMAT ${OLD_temp_f})${GAUGESH}" || echo -en "${OLD_temp_f}${GAUGESH}"
else
echo -en "${lclr}~${M}m ago - ${lclr}${lico}"
fi
echo -e "${idsCL[Default]} -- ${OLD_date} @ ${OLD_time}"
done
fi
if [ "${temp_h}" != "" ] && [ "${temp_h}" != "0" ]; then
[ ${DETAILS} -eq 1 ] && [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && echo -e "${idsCL[White]}|"
echo -en "${idsCL[White]}|-- ${idsCL[Cyan]}Humidity ${idsCL[LightCyan]}$(ROUND_NUMBER ${temp_h} 2)'%"
if [ "${avgdays}" != "noavg" ]; then
echo -en " ${idsCL[Default]} / ${idsCL[Yellow]}Calculating ${avgdays_disp} average ... "
average=$(AVERAGETEMP ${SENSOR} ${avgdays} hum)
echo -en "\r\033[K${idsCL[White]}|-- ${idsCL[Cyan]}Humidity ${idsCL[LightCyan]}$(ROUND_NUMBER ${temp_h} 2)'%${idsCL[Default]} / ${idsCL[LightCyan]}$(ROUND_NUMBER ${average} 2)'%"
fi
echo -e "${idsCL[Default]}"
if [ ${DETAILS} -eq 1 ] && [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
DIVIDER . lightCyan 50
for M in 5 15 30 60 120; do
lico=" "
[ "${mysql_conn}" != "" ] && OLD_temp_h=($(${mysql_conn} -e "SELECT hum,date FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${M} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${M} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
OLD_temp_h=${OLD_temp_h[2]}
OLD_date=${OLD_temp_h[3]}
OLD_time=${OLD_temp_h[4]}
if [ "${OLD_temp_h}" != "" ]; then
if [ $(bc -l <<< "${temp_h} < $(echo "scale=2; ${OLD_temp_h}+${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD_temp_h}-${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc) < ${temp_h}") -eq 1 ]; then
lclr="${idsCL[White]}"
lico="\u23F9"
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD_temp_h}+(${PW_TEMPIND_DIFF}*2)") < ${temp_h}") -eq 1 ]; then
lclr="${idsCL[LightRed]}"
lico="\u25B2"
elif [ $(bc -l <<< "${OLD_temp_h} < ${temp_h}") -eq 1 ]; then
lclr="${idsCL[Magenta]}"
lico="\u25B2"
elif [ $(bc -l <<< "${temp_h} < $(bc <<< "scale=2; ${OLD_temp_h}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
lclr="${idsCL[LightGreen]}"
lico="\u25BC"
elif [ $(bc -l <<< "${temp_h} < ${OLD_temp_h}") -eq 1 ]; then
lclr="${idsCL[LightCyan]}"
lico="\u25BC"
else
lclr="${idsCL[Default]}"
fi
else
lclr="${idsCL[Default]}"
lico="\u22C5"
fi
echo -en "${idsCL[Default]} "
if [ ${#M} -eq 1 ]; then
echo -n " "
elif [ ${#M} -lt 3 ]; then
c=0; spc1=`expr ${#M} - 1`
until [ ${c} = ${spc1} ]; do
echo -n " "
((c++))
done
fi
if [ "${OLD_temp_h}" != "" ]; then
c=0; spc=''; spc1=`expr 7 - ${#OLD_temp_h}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
echo -en "~${M}m ago - ${lclr}${lico}${spc}${OLD_temp_h}'%"
else
echo -en "~${M}m ago - ${lclr}${lico}"
fi
echo -e "${idsCL[Default]} -- ${OLD_date} @ ${OLD_time}"
done
fi
fi
[ ${REPORT} -eq 0 ] && echo
last_sensor=${SENSOR_DESC}
fi
done
# DIVIDER . yellow ${PRI_WIDTH}
fi
if [ "${TTYPE}" != "sensors" ]; then
GAUGESH="°F"
DIVIDER . yellow ${PRI_WIDTH}
if [ "${avgdays}" != "noavg" ]; then
echo -e "${idsCL[LightYellow]}ESXI HOST TEMPERATURE(S) Current / ${idsCL[LightYellow]}${avgdays_disp}AVG${spchdr}${idsCL[Yellow]}warning${idsCL[Default]} / ${idsCL[LightRed]}critical${idsCL[Default]}"
else
echo -e "${idsCL[LightYellow]}ESXI HOST TEMPERATURE(S) Current ${idsCL[Yellow]}warning${idsCL[Default]} / ${idsCL[LightRed]}critical${idsCL[Default]}"
fi
DIVIDER . yellow ${PRI_WIDTH}
for SENSOR in ${PW_SENSOR_ORD[@]}; do
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "esxi" ] && ([ "${exclude}" == "" ] || [[ ! "${SENSOR,,}" = *"${exclude,,}"* ]]) && ([ "${search}" == "" ] || ([[ "${SENSOR,,}" = *"${search,,}"* ]] && [ "${PW_DESC_TEMP[${SENSOR}]}" == "" ]) || [[ "${PW_DESC_TEMP[${SENSOR}],,}" = *"${search,,}"* ]]) && ([ "${STYPE}" = "" ] || ([ "${STYPE}" = "mainsite" ] && [[ "${PW_HOST_ADDRESSES[${SENSOR}]}" = *"10.10."* ]]) || ([ "${STYPE}" = "offsite" ] && [[ "${PW_HOST_ADDRESSES[${SENSOR}]}" = *"10.2.1."* ]]) || ([ "${STYPE}" = "kyle" ] && [[ "${PW_HOST_ADDRESSES[${SENSOR}]}" = *"10.6.1."* ]]) ); then
vHOSTiDRACIP=${PW_HOST_IDRACS[${SENSOR}]}
vHOSTIP=${PW_HOST_ADDRESSES[${SENSOR}]}
vHOSTNAME=${PW_ESXI_HOST_NAMES[${vHOSTiDRACIP}]}
[ "${PW_ESXI_DEF_EXHAUST_MIN}" != "" ] && ESXI_DEFAULT_EXHAUST_MIN=${PW_ESXI_DEF_EXHAUST_MIN}
[ "${SENSOR}" == "iDS-vMS-Host7" ] && ESXI_DEFAULT_EXHAUST_MIN=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}+${PW_ESXI_HOST7_FAN_DIFF}")
GL_HIGH=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}+${ESXI_FANSPEED_GL_ZONE}")
GL_LOW=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}-${ESXI_FANSPEED_GL_ZONE}")
echo -en "\r\033[K${idsCL[White]}${idsST[Bold]}${SENSOR} Host Sensors ${idsST[Reset]}${idsCL[White]}[${vHOSTiDRACIP}]"
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
if [ "${avgdays}" != "noavg" ]; then
echo -en "${idsCL[LightCyan]} Getting FanSpeed and calculating ${avgdays_disp} average..."
else
echo -en "${idsCL[LightCyan]} Getting FanSpeed..."
fi
[ ! -f ${PW_TMPFOLDER}/.local.fanspeed.${SENSOR}.${cdt} ] && until [ -f ${PW_TMPFOLDER}/.local.fanspeed.${SENSOR}.${cdt} ]; do tmp=tmp; done
RPMs=($(snmpwalk -v 1 -c public -t 2 ${vHOSTiDRACIP} .1.3.6.1.4.1.674.10892.5.4.700.12.1.6.1 -O vq))
# RPMs=($(snmpwalk -v 1 -c public -t 2 10.10.2.27 .1.3.6.1.4.1.674.10892.5.4.700.12.1.6.1 -O vq))
RPM_tot=0
for RPMn in "${RPMs[@]}"; do
RPM_tot=$(expr ${RPM_tot} + ${RPMn})
done
RPM=$(ROUND_NUMBER $(bc <<< "scale=0; ${RPM_tot}/${#RPMs[@]}"))
[ "${avgdays}" != "noavg" ] && fan_average=$(bc <<< "scale=0; $(ROUNDHALVES $(bc <<< "scale=3; $(AVERAGETEMP ${SENSOR} ${avgdays} FanSpeed)/10"))*10/1")
echo -en "\r\033[K${idsCL[White]}${idsST[Bold]}${SENSOR} Host Sensors ${idsST[Reset]}${idsCL[White]}[${vHOSTiDRACIP}]"
[ "${SENSOR}" == "iDS-vMS-Host6" ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[iDS-vMS-Host6]}"* ]] && cSENSOR="iDS-vMS-Host7" || cSENSOR=${SENSOR}
if [ -f ${PW_TMPFOLDER}/.lastfancheck/${cSENSOR}.gl ]; then
FSC="${idsCL[LightGreen]}${idsST[Bold]}"
elif [ -f ${PW_TMPFOLDER}/.lastfancheck/${cSENSOR}.set ]; then
FSC="${idsCL[LightGreen]}"
else
FSC="${idsCL[LightYellow]}"
fi
echo -en "${idsCL[LightCyan]} [FanSpeed=${FSC}$(cat ${PW_TMPFOLDER}/.local.fanspeed.${SENSOR}.${cdt})${idsST[Reset]}${idsCL[LightCyan]}'% "
if [ "${avgdays}" != "noavg" ]; then
echo -e "${idsCL[LightYellow]} AVG=${fan_average}'%${idsCL[LightCyan]}]${idsCL[Default]}"
else
echo -e "($(IDS_NUMBER_FORMAT ${RPM})'RPM)]${idsCL[Default]}"
fi
else
echo -e "${idsCL[Default]}"
fi
# if [ "${TTYPE}" != "fans" ]; then
DIVIDER . lightCyan ${PRI_WIDTH}
[ ${REPORT} -eq 0 ] && echo -en "${idsCL[Yellow]}Pulling data for '${SENSOR}' ... "
# if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && [ "$(CHECK_HOST ${vHOSTIP})" != "false" ]; then
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
vHOST_TEMPNAMES=$(snmpwalk -v 1 -c public -t 2 ${vHOSTiDRACIP} .1.3.6.1.4.1.674.10892.5.4.700.20.1.8 -O vq | sed -e 's/"//g' | sed -e 's/ Temp//g')
IFS=$'\n'
read -rd '' -a vHOST_TEMPNAMES <<<"${vHOST_TEMPNAMES}"
unset IFS
echo -en "\r\033[K"
if [ ${#vHOST_TEMPNAMES[@]} -gt 1 ]; then
t=1
for sensorname in "${vHOST_TEMPNAMES[@]}"; do
# if [ "${TTYPE}" != "fans" ] || ([ "${TTYPE}" == "fans" ] && ([[ "${sensorname}" = *"Exhaust"* ]] || ([ "${SENSOR}" == "iDS-vMS-Host6" ] && [[ "${sensorname}" = *"Inlet"* ]]))); then
if [ "${TTYPE}" != "fans" ] || ([ "${TTYPE}" == "fans" ] && ([[ "${sensorname}" = *"Exhaust"* ]] || [[ "${sensorname}" = *"Inlet"* ]])); then
temp_warn=$(snmpwalk -v 1 -c public -t 2 ${vHOSTiDRACIP} .1.3.6.1.4.1.674.10892.5.4.700.20.1.11.1.${t} -O vq | sed -e 's/"//g')
temp_warn=`echo "scale=1; ${temp_warn}/10" | tr -d $'\r' | bc`; temp_warn=`echo $(bc <<< "scale=2; ((${temp_warn}*(9/5))+32)/1") | awk '{print int($1+0.5)}'`
temp_crit=$(snmpwalk -v 1 -c public -t 2 ${vHOSTiDRACIP} .1.3.6.1.4.1.674.10892.5.4.700.20.1.10.1.${t} -O vq | sed -e 's/"//g')
temp_crit=`echo "scale=1; ${temp_crit}/10" | tr -d $'\r' | bc`; temp_crit=`echo $(bc <<< "scale=2; ((${temp_crit}*(9/5))+32)/1") | awk '{print int($1+0.5)}'`
c=0; spc=''; spc1=`expr ${cw} - ${#sensorname} - 1`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
IFS=: read -r temp_f temp_h <<< $(CHECKTEMPSENSOR ${SENSOR}); unset IFS
if [ "${TTYPE}" != "fans" ] || ([ "${TTYPE}" == "fans" ] && [[ "${sensorname}" = *"Exhaust"* ]]); then
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"
elif ([ $(bc -l <<< "${temp_f} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}") -eq 1 ]) || ([ "${TTYPE}" == "fans" ] && [ $(bc -l <<< "${temp_f} > $(bc <<< "scale=2; ${GL_HIGH}")") -eq 1 ]); then
lclr="${idsCL[Yellow]}"
lmd="WARNING "
elif [ "${TTYPE}" == "fans" ] && [ $(bc -l <<< "${temp_f} < ${GL_LOW}") -eq 1 ]; then
lclr="${idsCL[LightCyan]}"
lmd="COOL "
else
lclr="${idsCL[Green]}"
lmd="Normal "
fi
else
lclr="${idsCL[LightCyan]}"
lmd=" "
fi
c=0; spct=''; spc1=`expr 7 - ${#temp_f}`; until [ ${c} = ${spc1} ]; do spct="${spct} "; ((c++)); done
reading="${lclr}${lmd}${spct}${temp_f}${GAUGESH}"
echo -en "${idsCL[LightCyan]} ${sensorname}${spc}${idsCL[Default]}: ${reading} "
if [ ${DETAILS} -eq 2 ] && [ "${temp_f}" != "" ] && [ "${avgdays}" = "noavg" ] && [[ "${SENSOR}" != *"FAN"* ]]; then
for R in ${PW_TEMPIND_RANGE[@]}; do
[ "${mysql_conn}" != "" ] && entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${sensorname// /_}' AND sensorid='${PW_SENSOR_ID[${SENSOR}]}'"))
[ "${mysql_conn}" != "" ] && OLD_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 $(expr ${R} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${R} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
[[ "${IP}" == "10.6.1"* ]] && OLD_temp_f=${OLD_temp_f[0]} || OLD_temp_f=${OLD_temp_f[1]}
if [ "${OLD_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; ${OLD_temp_f}+${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD_temp_f}-${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc) < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[White]}\u23F9 "
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightRed]}\u25B2 "
elif [ $(bc -l <<< "${OLD_temp_f} < ${temp_f}") -eq 1 ]; then
echo -en "${idsCL[Magenta]}\u25B2 "
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD_temp_f}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
echo -en "${idsCL[LightGreen]}\u25BC "
elif [ $(bc -l <<< "${temp_f} < ${OLD_temp_f}") -eq 1 ]; then
echo -en "${idsCL[LightCyan]}\u25BC "
else
echo -en " "
fi
else
echo -en "${idsCL[Default]}\u22C5 "
fi
done
elif [ "${avgdays}" = "noavg" ]; then
echo -en " "
fi
if [ "${avgdays}" != "noavg" ]; then
echo -en " / ${idsCL[Yellow]}Calculating ${avgdays_disp} average ... "
average=$(AVERAGETEMP ${SENSOR} ${avgdays} ${sensorname// /_})
([ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]) && average_disp=$(IDS_NUMBER_FORMAT ${average}) || average_disp=${average}
c=0; spca=''; spc1=`expr 6 - ${#average_disp}`; until [ ${c} = ${spc1} ]; do spca="${spca} "; ((c++)); done
if [ "${average_disp}" == "" ]; then
averagedisp="${idsCL[Green]}"
elif [ $(bc -l <<< "${average} >= ${temp_crit}") -eq 1 ] || ([ "${TTYPE}" == "fans" ] && [ $(bc -l <<< "${average} > $(bc <<< "scale=2; ${GL_HIGH}+5")") -eq 1 ]); then
averagedisp="${idsCL[LightRed]}${average_disp}"
elif ([ $(bc -l <<< "${average} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${average} < ${temp_crit}") -eq 1 ]) || ([ "${TTYPE}" == "fans" ] && ([ $(bc -l <<< "${average} < ${GL_LOW}") -eq 1 ] || [ $(bc -l <<< "${GL_HIGH} < ${average}") -eq 1 ])); then
averagedisp="${idsCL[Yellow]}${average}"
else
averagedisp="${idsCL[Green]}${average_disp}"
fi
echo -en "\r\033[K${idsCL[LightCyan]} ${sensorname}${spc}${idsCL[Default]}: ${reading} ${idsCL[Default]}/${spca}${averagedisp}${GAUGESH}"
fi
if [ "${average}" != "" ] || [ "${temp_f}" != "" ]; then
[ "${average}" != "" ] && fws=11 || fws=$(expr 20 - $(expr ${#PW_TEMPIND_RANGE[@]} \* 2))
[ ${#temp_warn} == 2 ] && spcw=' ' || spcw=' '
[ ${#temp_crit} == 2 ] && spcc=' ' || spcc=' '
if [ "${TTYPE}" == "fans" ]; then
if [[ "${sensorname}" = *"Exhaust"* ]]; then
tmp="${lmd}${spct}${temp_f}${GAUGESH}"
c=0; spc=''; spc1=`expr ${fws} - ${#tmp} + 5`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
echo -e "${spc}${idsCL[Default]}[ ${idsCL[Green]}${GL_LOW}°F${idsCL[Default]} <--> ${idsCL[LightYellow]}${GL_HIGH}°F${idsCL[Default]} ]"
else
echo -e ""
fi
else
tmp="${spct}${temp_f}${GAUGESH}"
[ "${avgdays}" != "noavg" ] && spc1=`expr ${fws} - ${#tmp} + 1` || spc1=`expr ${fws} - ${#tmp} + 5`
c=0; spc=''; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
echo -e "${spc}${idsCL[Default]}[${spcw}${idsCL[Yellow]}${temp_warn}${GAUGESH}${idsCL[Default]} /${spcc}${idsCL[LightRed]}${temp_crit}${GAUGESH}=>${idsCL[Default]} ]"
fi
else
echo -e "${idsCL[Default]}"
fi
if [ ${DETAILS} -eq 1 ] && [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && [ "${temp_f}" != "timeout" ] && [ "${temp_f}" != "offline" ]; then
DIVIDER . white ${PRI_WIDTH}
for M in 5 15 30 60 120; do
lico=" "
if [ "${mysql_conn}" != "" ]; then
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${sensorname// /_}' AND sensorid='${PW_SENSOR_ID[${SENSOR}]}'"))
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
spc_cnt=6
[ "${mysql_conn}" != "" ] && OLD_temp_f=($(${mysql_conn} -e "SELECT speed,date FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND entity=${entityid[1]} AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${M} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${M} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
else
spc_cnt=7
[ "${mysql_conn}" != "" ] && OLD_temp_f=($(${mysql_conn} -e "SELECT temp,date FROM servermonitor.sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSOR}]}' AND entity=${entityid[1]} AND date >= DATE_SUB(NOW(), INTERVAL $(expr ${M} + 1) MINUTE) AND date <= DATE_SUB(NOW(), INTERVAL $(expr ${M} - 6) MINUTE) ORDER BY date ASC LIMIT 1"))
# echo "${OLD_temp_f[0]} - ${OLD_temp_f[1]} - ${OLD_temp_f[2]} - ${OLD_temp_f[3]}"
fi
if [[ "${IP}" == "10.6.1"* ]]; then
OLD_date=${OLD_temp_f[1]}
OLD_time=${OLD_temp_f[2]}
OLD_temp_f=${OLD_temp_f[0]}
else
OLD_date=${OLD_temp_f[3]}
OLD_time=${OLD_temp_f[4]}
OLD_temp_f=${OLD_temp_f[2]}
fi
fi
if [ "${OLD_temp_f}" != "" ]; then
if [ $(bc -l <<< "${temp_f} < $(echo "scale=2; ${OLD_temp_f}+${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc)") -eq 1 ] && [ $(bc -l <<< "$(echo "scale=2; ${OLD_temp_f}-${PW_TEMPIND_DIFF}" | tr -d $'\r' | bc) < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[White]}"
lico="\u23F9"
elif [ $(bc -l <<< "$(bc <<< "scale=2; ${OLD_temp_f}+(${PW_TEMPIND_DIFF}*2)") < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[LightRed]}"
lico="\u25B2"
elif [ $(bc -l <<< "${OLD_temp_f} < ${temp_f}") -eq 1 ]; then
lclr="${idsCL[Magenta]}"
lico="\u25B2"
elif [ $(bc -l <<< "${temp_f} < $(bc <<< "scale=2; ${OLD_temp_f}-(${PW_TEMPIND_DIFF}*2)")") -eq 1 ]; then
lclr="${idsCL[LightGreen]}"
lico="\u25BC"
elif [ $(bc -l <<< "${temp_f} < ${OLD_temp_f}") -eq 1 ]; then
lclr="${idsCL[LightCyan]}"
lico="\u25BC"
else
lclr="${idsCL[Default]}"
fi
else
lclr="${idsCL[Default]}"
lico="\u22C5"
fi
([ "${temp_h}" != "" ] && [ "${temp_h}" != "0" ]) && echo -en "${idsCL[White]}| " || echo -n " "
echo -en "${idsCL[Default]} "
if [ ${#M} -eq 1 ]; then
echo -n " "
elif [ ${#M} -lt 3 ]; then
c=0; spc1=`expr ${#M} - 1`
until [ ${c} = ${spc1} ]; do
echo -n " "
((c++))
done
fi
if [ "${OLD_temp_f}" != "" ]; then
c=0; spc=''; spc1=`expr ${spc_cnt} - ${#OLD_temp_f}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
echo -en "~${M}m ago - ${lclr}${lico}${spc}"
[ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]] && echo -en "$(IDS_NUMBER_FORMAT ${OLD_temp_f})${GAUGESH}" || echo -en "${OLD_temp_f}${GAUGESH}"
else
echo -en "${lclr}~${M}m ago - ${lclr}${lico}"
fi
echo -e "${idsCL[Default]} -- ${OLD_date} @ ${OLD_time}"
done
DIVIDER . white ${PRI_WIDTH}
fi
if [ "${TTYPE}" == "fans" ]; then
if [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[${SENSOR}]}"* ]] && [[ "${sensorname}" = *"Exhaust"* ]]; then
if [ -f ${PW_TMPFOLDER}/.lastfancheck/${cSENSOR}.gl ]; then
FSC="${idsCL[LightGreen]}"
elif [ -f ${PW_TMPFOLDER}/.lastfancheck/${cSENSOR}.set ]; then
FSC="${idsCL[Green]}"
else
FSC="${idsCL[LightYellow]}"
fi
# echo -e " Goldilock Zone : ${idsCL[LightGreen]}${ESXI_DEFAULT_EXHAUST_MIN}°F (±${ESXI_FANSPEED_GL_ZONE}°F) ${idsCL[Default]}[ ${idsCL[Green]}${GL_LOW}°F${idsCL[Default]} <--> ${idsCL[LightYellow]}${GL_HIGH}°F${idsCL[Default]} ]"
echo -e " Goldilock Zone : ${idsCL[LightGreen]}${ESXI_DEFAULT_EXHAUST_MIN}°F (±${ESXI_FANSPEED_GL_ZONE}°F)"
echo -e " Last checked : ${idsCL[LightCyan]}$(date -r ${PW_TMPFOLDER}/.lastfancheck/${SENSOR} "+%m/%d @ %l:%M%p")${idsCL[Default]}"
echo -en " Last set : ${FSC}$(date -r ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set "+%m/%d @ %l:%M%p") "
if [ "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set | cut -d'~' -f 2)" == "uu" ]; then
echo -e "${idsCL[LightRed]}\u25B2 ${idsCL[Default]}"
elif [ "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set | cut -d'~' -f 2)" == "u" ]; then
echo -e "${idsCL[Magenta]}\u25B2 ${idsCL[Default]}"
elif [ "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set | cut -d'~' -f 2)" == "dd" ]; then
echo -e "${idsCL[LightGreen]}\u25BC ${idsCL[Default]}"
elif [ "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set | cut -d'~' -f 2)" == "d" ]; then
echo -e "${idsCL[LightCyan]}\u25BC ${idsCL[Default]}"
elif [ "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSOR}.set | cut -d'~' -f 2)" == "m" ]; then
echo -e "${idsCL[LightCyan]}\u2720 ${idsCL[Default]}"
else
echo -e "${idsCL[Default]}"
fi
fi
fi
fi
((t++))
done
if [ "${TTYPE}" == "fans" ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" != *"${PW_HOST_IDRACS[${SENSOR}]}"* ]]; then
[ "${SENSOR}" == "iDS-vMS-Host6" ] && echo -e "${idsCL[LightCyan]} System Board Exhaust ${idsCL[Default]}: ${idsCL[LightYellow]}PSU is not compatible${idsCL[Default]}"
echo -e " Fans are not managed for this host"
fi
else
echo -e "${idsCL[LightCyan]} ${vHOSTNAME}${spc}${idsCL[Default]}: No Data"
fi
else #host down
echo -e "\r\033[K${idsCL[LightRed]}${SENSOR} Host is down${idsCL[Default]}"
# if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
# SENDNOTICE "${vHOSTiDRACIP} ERROR" "${vHOSTNAME} Host is down" 1
# echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${vHOSTiDRACIP} - ${vHOSTNAME} Host is down" >> ${logtemp}
# touch ${PW_TMPFOLDER}/${EHOST}.down
# fi
fi
# fi
if [ "${TTYPE}" == "fans" ] && [ "${SENSOR}" == "iDS-vMS-Host6" ] && [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[iDS-vMS-Host6]}"* ]]; then
echo -e "${idsCL[LightYellow]}${SENSOR} PSU is not compatible, Fans are instead synced with 'iDS-vMS-Host7'${idsCL[Default]}"
fi
# ([ "${TTYPE}" != "fans" ] || ([ "${TTYPE}" == "fans" ] && [ "${SENSOR}" != "iDS-vMS-Host6" ])) && echo
if [ ${drives} -eq 1 ]; then
${SSHCMD} root@${vHOSTIP} 'wget -qO- https://git.schroedercity.com/voltron/Misc-Scripts/raw/branch/master/ESXi-GetPercDriveTemps.sh | sh'
fi
echo
fi
done
fi
rm -f ${PW_TMPFOLDER}/.local.fanspeed.*
if [ ${REPORT} -eq 0 ]; then
end=`date +%s`; runtime=$((end-start)); echo -e "${idsCL[Default]}script runtime: ${runtime}s"
[ "${PW_ACTION}" != "" ] && echo -e "${idsCL[Default]}"
fi
}
CHECKTEMPSENSOR(){
TIMEOUT=0
temp_h=0
temp_f=''
if [ "${mqtt_conn}" != "" ] && [ "${PW_SENSOR_TYPE[${1}]}" == "mqtt" ]; then
if ! mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` ; then TIMEOUT=1; fi
echo ${mqtt_message} | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
echo ${mqtt_message} | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h
elif [ "${PW_SENSOR_TYPE[${1}]}" == "esphome" ]; then
if ! temp_c=$(curl -m 8 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${1}]}_temperature | jq -r '.state') ; then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_f=`IDS_NUMBER_FORMAT ${temp_c} 2 yes`
temp_h=`IDS_NUMBER_FORMAT $(curl -m 8 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${1}]}_humidity | jq -r '.state') 2 yes`
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "espdev" ]; then
if ! temp_c=$(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${1}]}:8090/sensor/${PW_SENSOR_DEVICEID[${1}]} | jq '.value'); then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_h=`IDS_NUMBER_FORMAT $(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${1}]}:8090/sensor/${PW_SENSOR_DEVICEID[${1}]/temperature/humidity} | jq '.value') 2 yes`
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "tuya" ]; then
IFS=: read -r temp_c temp_h <<< $(GET_TUYA_TEMP ${1}); unset IFS
elif [ "${PW_SENSOR_TYPE[${1}]}" == "midea" ]; then
IFS='~' read -r token key <<< ${PW_SENSOR_DEVICEID[${1}]}; unset IFS
info=$(midea-beautiful-air-cli status --ip ${PW_REMOTE_SENSORS[${1}]} --token ${token} --key ${key})
temp_c=$(echo "${info}" | grep indoor | awk ' {print $3}')
target=$(echo "${info}" | grep target | awk ' {print $3}')
elif [ "${PW_SENSOR_TYPE[${1}]}" == "lacrosse" ]; then
if ! INFO=$(curl -m 8 -s --get -d "deviceid=${PW_SENSOR_DEVICEID[${SENSOR}]}" -d "limit=1" -d "metric=1" -d "timezone=2" https://decent-destiny-704.appspot.com/laxservices/device_info.php) ; then TIMEOUT=1; fi
if [ "${INFO}" != "" ]; then
if [[ "${1}" = *"-Probe" ]]; then
temp_c=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].probe_temp') 2 yes`
else
temp_c=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].ambient_temp') 2 yes`
temp_h=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].humidity') 2 yes`
fi
else
temp_c=''
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "system" ] || [ "${PW_SENSOR_TYPE[${1}]}" == "remotesystem" ]; then
if [[ "${1}" = *"CPU"* ]]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${1}]} vcgencmd measure_temp) ; then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
fi
elif [[ "${1}" = *"FAN"* ]]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${1}]} cat ${PW_FANINPUT}) ; then TIMEOUT=1; fi
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "esxi" ]; then
temp_c=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${1}]} .1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.${t} -O vq | sed -e 's/"//g')
temp_c=`echo "scale=1; ${temp_c}/10" | tr -d $'\r' | bc`
elif [ "${PW_SENSOR_TYPE[${1}]}" == "cpu" ]; then
if [ "${1}" == "Powerwall-CPU-Usage" ]; then
if ! temp_c=$(awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat) | sed -e 's/%//g') ; then
TIMEOUT=1
fi
else
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${1}]} "/opt/idssys/defaults/get-data.sh cpu-usage") ; then
TIMEOUT=1
fi
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "ds18b20" ]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${1}]} cat /sys/devices/w1_bus_master1/${PW_SENSOR_DEVICEID[${1}]}/w1_slave | tail -n1 | cut -d "=" -f2) ; then TIMEOUT=1; fi
[ "${temp_c}" != "" ] && temp_c=$(echo "scale=2; ${temp_c}/1000" | tr -d $'\r' | bc)
fi
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
if [ "${1}" == "ServerRoomTH" ]; then
temp_f=`echo "scale=2; ((${temp_c}*(9/5))+32+${PW_ServerRoomTH_Dev})/1" | tr -d $'\r' | bc`
else
if [ "${PW_SENSOR_TYPE[${1}]}" == "cpu" ]; then
temp_f=$(echo "scale=2; $temp_c/1" | tr -d $'\r' | bc -l)
elif [ "${PW_SENSOR_TYPE[${1}]}" == "system" ] && [[ "${1}" = *"FAN"* ]]; then
temp_f=${temp_c}
elif [ "${temp_f}" == "" ]; then
temp_f=$(bc <<< "scale=2; ((${temp_c}*(9/5))+32)/1")
fi
(( $(bc <<<"${temp_f} < 1") )) && [[ "${temp_f}" = *"."* ]] && temp_f="0${temp_f}"
fi
echo "${temp_f}:${temp_h}"
elif [ ${TIMEOUT} -eq 1 ]; then
# echo -en "${idsCL[Yellow]}Sensor Timeout${idsCL[Default]}"
echo timeout
else
# echo -en "${idsCL[Yellow]}Sensor Offline${idsCL[Default]}"
echo offline
fi
}
AVERAGETEMP(){
temptotal=0
lookback=${2}
interval=0
sensor=${1}
sensorid=${PW_SENSOR_ID[${sensor}]}
logsfound=0;
if [ "${3}" != "" ] && [ "${3}" != "hum" ]; then
[ "${mysql_conn}" != "" ] && entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${3}' AND sensorid='${sensorid}'"))
entityid=${entityid[1]}
WHERE="sensorid=${sensorid} AND entity=${entityid}"
else
WHERE="sensorid=${sensorid}"
fi
if [[ "${lookback^^}" = *"M"* ]]; then
interval="${lookback::-1} MINUTE"
elif [[ "${lookback^^}" = *"H"* ]]; then
interval="${lookback::-1} HOUR"
elif [[ "${lookback^^}" = *"D"* ]]; then
interval="${lookback::-1} DAY"
elif [[ "${lookback}" =~ ^[0-9]+$ ]]; then
interval="${lookback} DAY"
fi
if [ "${mysql_conn}" != "" ] && [ "${interval}" != "0" ]; then
while IFS=$'\t' read date temp hum speed ;do
if ([ "${3}" == "FanSpeed" ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[${sensor}]}"* ]]) || [ "${sensorid}" == "19" ]; then
val=${speed}
elif [ "${3}" == "hum" ]; then
val=${hum}
else
val=${temp}
fi
if [ "${val}" != "" ] && [ "${val}" != "0" ] && [[ "${val}" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
temptotal=$(bc <<< "scale=2; ${temptotal}+${val}")
((logsfound++))
fi
done < <(${mysql_conn} -se "USE servermonitor; SELECT date,temp,hum,speed from sensor_data WHERE ${WHERE} AND date >= DATE_SUB(NOW(), INTERVAL ${interval}) ORDER BY id DESC;")
fi
if [ "${interval}" != "0" ] && [ ${logsfound} -gt 0 ]; then
if [ "${3}" == "FanSpeed" ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[${sensor}]}"* ]]; then
average=$(ROUND_NUMBER $(bc <<< "scale=2; ${temptotal}/${logsfound}") 2)
elif [ "${sensorid}" == "19" ]; then
# average=$(bc <<< "scale=0; ${temptotal}/${logsfound}")
average=$(ROUND_NUMBER $(bc <<< "scale=2; ${temptotal}/${logsfound}") 0)
else
average=$(bc <<< "scale=2; ${temptotal}/${logsfound}")
fi
(( $(bc <<<"${average} < 1") )) && [[ "${average}" = *"."* ]] && average="0${average}"
echo ${average}
else
echo 0
fi
}
CHECKTEMP_SERVICE(){
cw=20
([ ! -f ${PW_TMPFOLDER}/.nosend_update ] && [[ "${IP}" != "10.6."* ]]) && SENDTEMPS "TEMP Service Startup" &
[ ! -d ${PW_TMPFOLDER}/.lastfancheck ] && mkdir ${PW_TMPFOLDER}/.lastfancheck
[ ! -d ${PW_TMPFOLDER}/.lastinsert ] && mkdir ${PW_TMPFOLDER}/.lastinsert
[ -d ${PW_TMPFOLDER}/.lasttemp ] && rm -Rf ${PW_TMPFOLDER}/.lasttemp
mkdir ${PW_TMPFOLDER}/.lasttemp
rm -f ${PW_TMPFOLDER}/ztemprun.*
while true; do
start=$(date +%s)
log_start=$(date "+%Y-%m-%d %H:%M:%S")
source ${PW_FOLDER}/defaults.inc
[ "${PW_SERVICE_TEMP_SCANRATE}" != "" ] && runEvery=${PW_SERVICE_TEMP_SCANRATE} || runEvery=1
[ "${PW_SCAN_THREADS}" != "" ] && SCAN_THREADS=${PW_SCAN_THREADS} || SCAN_THREADS=4
SENSORS_CHECKED=()
for SENSORa in ${PW_SENSOR_ORD[@]}; do
until [ $(ls ${PW_TMPFOLDER}/ztemprun.*.running 2>/dev/null | wc -l) -lt ${SCAN_THREADS} ]; do
tmp=tmp
done
# echo "sensor: ${SENSORa}"
CHECKTEMP_SERVICE_RUNSENSOR ${SENSORa} &
SENSORS_CHECKED+=(${SENSORa})
done
s_count=0; completed=false; scanstart=$(date +%s)
until [ "${completed}" == "true" ]; do
for sensor in ${PW_TMPFOLDER}/ztemprun.*.done; do
tsensor=$(grep -oP '(?<=ztemprun.).*?(?=.done)' <<< "${sensor}")
if [ "${tsensor}" != "*" ]; then
# echo "sensor: ${tsensor}"
rm -f ${sensor}
((s_count++))
if [ -f ${PW_TMPFOLDER}/${tsensor}.down ] && [ -f ${PW_TMPFOLDER}/.lastfancheck/${tsensor}.set ] && [ "${PW_SENSOR_TYPE[${tsensor}]}" == "esxi" ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${tsensor}.set)) -ge 900 ]; then
rm -f ${PW_TMPFOLDER}/.lastfancheck/${tsensor}*
fi
fi
done
[ ${s_count} -eq ${#SENSORS_CHECKED[@]} ] && completed=true
if [ $(($(date +%s)-scanstart)) -gt 300 ]; then
SENDNOTICE "PW Scan Stuck" "PW Temp scan has been running for 5mins, try breaking...." 1
break
fi
done
end=`date +%s`; runtime=$((end-start))
# echo -e "script runtime: ${runtime}s"; [ ${runtime} -lt $((runEvery*60)) ] && echo "Sleeping for $(((runEvery*60)-runtime))s"
echo "${log_start}~${runtime}~temp" >> ${PW_LOGFOLDER}/service.scantimes
[ ${runtime} -lt $((runEvery*60)) ] && sleep $(((runEvery*60)-runtime))s
done # &
}
CHECKTEMP_SERVICE_RUNSENSOR(){
SENSORa=${1}
[ "${PW_DESC_TEMP[${SENSORa}]}" != "" ] && SENSOR_DESC=${PW_DESC_TEMP[${SENSORa}]} || SENSOR_DESC=${SENSORa}
logtemp=${PW_LOGFOLDER}/log-temp-${SENSORa}
touch ${PW_TMPFOLDER}/ztemprun.${SENSORa}.running
# source ${PW_FOLDER}/defaults.inc
[ "${PW_ESXI_DEF_FANSPEED}" != "" ] && ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED} || ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED}
[ "${PW_ESXI_FANSPEED_GL_ZONE}" != "" ] && ESXI_FANSPEED_GL_ZONE=${PW_ESXI_FANSPEED_GL_ZONE} || ESXI_FANSPEED_GL_ZONE=2.5
[ ! -f ${logtemp} ] && touch ${logtemp}
[ -f ${PW_TMPFOLDER}/ztemprun.${SENSORa}.done ] && rm -f ${PW_TMPFOLDER}/ztemprun.${SENSORa}.done
[ $(expr `date +%s` - $(stat -c %Y ${logtemp})) -ge $(echo "scale=0; ${PW_LOG_INTERVAL_NORMAL}*60" | tr -d $'\r' | bc) ] && relog=1 || relog=0
if ([ "${PW_SENSOR_TYPE[${SENSORa}]}" == "lacrosse" ] || [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esphome" ] || ([ "${PW_REMOTE_SENSORS[${SENSORa}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSORa}]})" != "false" ]) || ([ "${PW_HOST_ADDRESSES[${SENSORa}]}" != "" ] && [ "$(CHECK_HOST ${PW_HOST_ADDRESSES[${SENSORa}]})" != "false" ])); then
# if ([ "${PW_REMOTE_SENSORS[${SENSORa}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSORa}]})" != "false" ]); then
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
[[ "${PW_HOST_IDRACS[${SENSORa}]}" = "10.6."* ]] && ESXI_PASS=${PW_ESXI_PASS_KP} || ESXI_PASS=${PW_ESXI_PASS}
if [ -f ${PW_TMPFOLDER}/${SENSORa}-error.sent ]; then
SENDNOTICE "${SENSOR_DESC} Data" "${SENSORa} is reporting data again"
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSORa} - Sensor is reporting data again" >> ${logtemp}
elif [ -f ${PW_TMPFOLDER}/${SENSORa}.shutdown ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSORa}.shutdown)) -ge 300 ]; then
SENDNOTICE "${SENSOR_DESC} Data" "${SENSORa} has been powered up"
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSORa} has been powered up" >> ${logtemp}
fi
rm -f ${PW_TMPFOLDER}/${SENSORa}*
[ "${PW_ESXI_DEF_EXHAUST_MIN}" != "" ] && ESXI_DEFAULT_EXHAUST_MIN=${PW_ESXI_DEF_EXHAUST_MIN}
[ "${SENSOR}" == "iDS-vMS-Host7" ] && ESXI_DEFAULT_EXHAUST_MIN=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}+${PW_ESXI_HOST7_FAN_DIFF}")
GL_HIGH=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}+${ESXI_FANSPEED_GL_ZONE}")
GL_LOW=$(bc <<< "scale=2; ${ESXI_DEFAULT_EXHAUST_MIN}-${ESXI_FANSPEED_GL_ZONE}")
vHOST_TEMPNAMES=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.20.1.8 -O vq | sed -e 's/"//g' | sed -e 's/ Temp//g')
IFS=$'\n'
read -rd '' -a SENSORS_CHECK <<<"${vHOST_TEMPNAMES}"
unset IFS
[ -f ${PW_TMPFOLDER}/power.${SENSORa}.off ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/power.${SENSORa}.off)) -ge 300 ] && rm-f ${PW_TMPFOLDER}/power.${SENSORa}.off
t=1
####### Grab Fan Speeds #######
# if [ ! -f ${PW_TMPFOLDER}/${SENSORa}.down ] && ([ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa} ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa})) -ge 60 ]); then
if [ ! -f ${PW_TMPFOLDER}/${SENSORa}.down ]; then
# vHOSTFAN=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.12.1.6.1.3 -O vq)
if [ "${IP}" = "10.2.1.5" ]; then
vHOSTFAN=$(${SSHCMD} root@${PW_RACADM_ACCESS} racadm -r ${PW_HOST_IDRACS[${SENSORa}]} -u ${PW_ESXI_USER} -p "'${ESXI_PASS}'" getsensorinfo | grep "System Board Fan3" 2>&1)
else
vHOSTFAN=$(racadm -r ${PW_HOST_IDRACS[${SENSORa}]} -u ${PW_ESXI_USER} -p "${ESXI_PASS}" getsensorinfo | grep "System Board Fan3" 2>&1)
fi
if [ "${vHOSTFAN}" = "" ]; then
if [ "${IP}" = "10.2.1.5" ]; then
vHOSTFAN=$(${SSHCMD} root@${PW_RACADM_ACCESS} racadm -r ${PW_HOST_IDRACS[${SENSORa}]} -u ${PW_ESXI_USER} -p "'${ESXI_PASS}'" getsensorinfo | grep "System Board Fan1" 2>&1)
else
vHOSTFAN=$(racadm -r ${PW_HOST_IDRACS[${SENSORa}]} -u ${PW_ESXI_USER} -p "${ESXI_PASS}" getsensorinfo | grep "System Board Fan1" 2>&1)
fi
fi
if [ "${vHOSTFAN}" != "" ]; then
# FanSpeed=`echo "scale=2; ${vHOSTFAN}/21200" | tr -d $'\r' | bc`; FanSpeed=$(ROUND_NUMBER `echo "scale=0; ${FanSpeed}*100" | tr -d $'\r' | bc | sed -e 's/.00//g'` 0)
if [ "$(echo ${vHOSTFAN} | awk '/ / {print $4}' | sed -e 's/%//g')" == "RPM" ]; then
FanSpeed=$(echo ${vHOSTFAN} | awk '/ / {print $9}' | sed -e 's/%//g')
else
FanSpeed=$(echo ${vHOSTFAN} | awk '/ / {print $8}' | sed -e 's/%//g')
fi
echo "${FanSpeed}" >| ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}
else
FanSpeed=''
fi
else
FanSpeed=''
fi
else
SENSORS_CHECK=(${SENSORa})
fi
if [ "${SENSORS_CHECK}" != "" ]; then
for SENSOR in "${SENSORS_CHECK[@]}"; do
# echo "HERE: ${SENSORa} - ${SENSOR}"
if [ "${PW_THRESHOLDS[${SENSORa}]}" != "" ]; then
echo ${PW_THRESHOLDS[${SENSORa}]} | cut -d',' -f 1 | read temp_warn
echo ${PW_THRESHOLDS[${SENSORa}]} | cut -d',' -f 2 | read temp_crit
[ "$(echo ${PW_THRESHOLDS[${SENSORa}]} | cut -d',' -f 3)" != "" ] && echo ${PW_THRESHOLDS[${SENSORa}]} | cut -d',' -f 3 | read temp_crit_sys || temp_crit_sys=${temp_crit}
fi
temp_f=''
if [ "${mqtt_conn}" != "" ] && [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "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[${SENSORa}]}" == "esphome" ]; then
if ! temp_c=$(curl -m 5 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${SENSORa}]}_temperature | jq -r '.state') ; then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_f=`IDS_NUMBER_FORMAT ${temp_c} 2 yes`
temp_h=`IDS_NUMBER_FORMAT $(curl -m 5 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${SENSORa}]}_humidity | jq -r '.state') 2 yes`
else
temp_c=''
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "espdev" ]; then
if ! temp_c=$(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${SENSORa}]}:8090/sensor/${PW_SENSOR_DEVICEID[${SENSORa}]} | jq '.value'); then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_h=`IDS_NUMBER_FORMAT $(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${SENSORa}]}:8090/sensor/${PW_SENSOR_DEVICEID[${SENSORa}]/temperature/humidity} | jq '.value') 2 yes`
fi
elif [ "${PW_SENSOR_TYPE[${1}]}" == "tuya" ]; then
IFS=: read -r temp_c temp_h <<< $(GET_TUYA_TEMP ${1}); unset IFS
elif [ "${PW_SENSOR_TYPE[${1}]}" == "midea" ]; then
IFS='~' read -r token key <<< ${PW_SENSOR_DEVICEID[${1}]}; unset IFS
info=$(midea-beautiful-air-cli status --ip ${PW_REMOTE_SENSORS[${1}]} --token ${token} --key ${key})
temp_c=$(echo "${info}" | grep indoor | awk ' {print $3}')
target=$(bc <<< "scale=2; ($(echo "${info}" | grep target | awk ' {print $3}')*(9/5))+32")
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "lacrosse" ]; then
INFO=$(curl -m 5 -s --get -d "deviceid=${PW_SENSOR_DEVICEID[${SENSOR}]}" -d "limit=1" -d "metric=1" -d "timezone=2" https://decent-destiny-704.appspot.com/laxservices/device_info.php | jq)
if [[ "${SENSOR}" = *"-Probe" ]]; then
temp_c=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].probe_temp') 2 yes`
else
temp_c=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].ambient_temp') 2 yes`
temp_h=`IDS_NUMBER_FORMAT $(echo ${INFO} | jq -r '.device0 .obs[].humidity') 2 yes`
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ] || [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "remotesystem" ]; then
if [[ "${SENSOR}" = *"CPU"* ]]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSOR}]} vcgencmd measure_temp) ; then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
fi
elif [[ "${SENSOR}" = *"FAN"* ]]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSOR}]} cat ${PW_FANINPUT}) ; then TIMEOUT=1; fi
if [ "${SENSOR}" == "Powerwall-FAN" ] && [ ${temp_c} -lt 1500 ]; then
START_POWERWALL_FAN >/dev/null 2>&1 &
fi
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
temp_c=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.20.1.6.1.${t} -O vq | sed -e 's/"//g')
temp_c=`echo "scale=1; ${temp_c}/10" | tr -d $'\r' | bc`
temp_warn=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.20.1.11.1.${t} -O vq | sed -e 's/"//g')
temp_warn=`echo "scale=1; ${temp_warn}/10" | tr -d $'\r' | bc`
temp_warn=$(echo "scale=2; ${temp_warn}*1.8 + 32" | tr -d $'\r' | bc)
temp_crit=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.20.1.10.1.${t} -O vq | sed -e 's/"//g')
temp_crit=`echo "scale=1; ${temp_crit}/10" | tr -d $'\r' | bc`
temp_crit=$(echo "scale=2; ${temp_crit}*1.8 + 32" | tr -d $'\r' | bc)
temp_crit_sys=${temp_crit}
temp_h=''
vSENSOR=${SENSOR}
SENSOR="${SENSORa}-${vSENSOR// /_}"
((t++))
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "cpu" ]; then
if [ "${SENSORa}" == "Powerwall-CPU-Usage" ]; then
temp_c=$(awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat) | sed -e 's/%//g')
else
temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSORa}]} "/opt/idssys/defaults/get-data.sh cpu-usage" | tr -d $'\r')
fi
temp_h=''
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "ds18b20" ]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSORa}]} cat /sys/devices/w1_bus_master1/${PW_SENSOR_DEVICEID[${SENSORa}]}/w1_slave | tail -n1 | cut -d "=" -f2) ; then TIMEOUT=1; fi
[ "${temp_c}" != "" ] && temp_c=$(echo "scale=2; ${temp_c}/1000" | tr -d $'\r' | bc)
temp_h=''
else
temp_c=''
fi
[ ! -f ${PW_TMPFOLDER}/.lasttemp/${SENSOR} ] && echo 0 > ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
last_temp=$(cat ${PW_TMPFOLDER}/.lasttemp/${SENSOR})
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ] && [ "${temp_c}" != "unavailable" ] && [ "${temp_c}" != "unknown" ] && [ "${temp_h}" != "0" ]; then
if [ -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] || [ -f ${PW_TMPFOLDER}/${SENSOR}.down ]; then
if [ -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] || [ -f ${PW_TMPFOLDER}/${SENSOR}.restart ]; then
SENDNOTICE "${SENSOR_DESC} Data" "${SENSOR_DESC} is reporting data again"
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSOR_DESC} - Sensor is reporting data again" >> ${logtemp}
fi
rm -f ${PW_TMPFOLDER}/${SENSOR}*
fi
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "cpu" ]; then
GAUGE="CPU-USAGE"
GAUGESH='%'
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ] && [[ "${SENSORa}" = *"FAN"* ]]; then
GAUGE="RPM"
GAUGESH="'R"
else
GAUGE="TEMP"
GAUGESH="'F"
fi
if [ "${SENSOR}" == "ServerRoomTH" ]; then
temp_f=`echo "scale=2; (${temp_c}*(9/5))+32+${PW_ServerRoomTH_Dev}" | tr -d $'\r' | bc`
else
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "cpu" ]; then
temp_f=$(echo "scale=2; $temp_c/1" | tr -d $'\r' | bc -l)
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
temp_f=${temp_c}
elif [ "${temp_f}" == "" ]; then
temp_f=$(bc <<< "scale=2; (${temp_c}*(9/5))+32")
fi
(( $(bc <<<"${temp_f} < 1") )) && [[ "${temp_f}" = *"."* ]] && temp_f="0${temp_f}"
fi
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" != "esxi" ]; then
echo ${PW_THRESHOLDS[${SENSOR}]} | cut -d',' -f 1 | read temp_warn
echo ${PW_THRESHOLDS[${SENSOR}]} | cut -d',' -f 2 | read temp_crit
echo ${PW_THRESHOLDS[${SENSOR}]} | cut -d',' -f 3 | read temp_crit_sys
##### ESXI FAN CONTROL #####
elif [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[${SENSORa}]}"* ]] && [[ "${vSENSOR}" = *"Exhaust"* ]] && [ "${FanSpeed}" != "" ]; then
if [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.chkset ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.chkset)) -ge 300 ] || [ ${FanSpeed} -ge 90 ] ; then
if [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ] || [ ${FanSpeed} -ge 90 ] ; then
[ ${FanSpeed} -ge 90 ] && rm -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.*
NEW_FanSpeed=$(GET_DEFAULT_FANSPEED ${SENSORa} ${FanSpeed})
SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FanSpeed Control" "Re-enabling Host Fan control to Powerwall. Setting fans to: ${NEW_FanSpeed}%"
ipmitool -I lanplus -H ${PW_HOST_IDRACS[${SENSORa}]} -U ${PW_ESXI_USER} -P "${ESXI_PASS}" raw 0x30 0x30 0x01 0x00 >/dev/null 2>&1
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} e >/dev/null 2>&1 &
fi
### GOLDILOCK ZONE ###
if ((( $(bc <<< "${temp_f} >= ${GL_LOW}") )) && (( $(bc <<< "${temp_f} <= ${GL_HIGH}") ))) || [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ]; then
if [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl ] && [ -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set)) -ge 3600 ]; then
# SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FAN CONTROL" "Goldilock Zone Found at ${FanSpeed}%"
echo "${FanSpeed}" >| ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${FanSpeed}% - ${SENSORa} - Goldilock Zone Found (1HR)" >> ${logtemp}
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${FanSpeed}% - ${SENSORa} - Goldilock Zone Found (1HR)" >> ${PW_LOGFOLDER}/esxi-fanspeeds.log
elif [ -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl)) -ge 3600 ] && [ ${FanSpeed} -gt ${PW_ESXI_MIN_FANSPEED} ] && (( $(bc <<< "${temp_f} < ${ESXI_DEFAULT_EXHAUST_MIN}") )); then
SET_ESXI_FANSPEED $(expr $(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set | cut -d'~' -f 1) - 5) ${SENSORa} 5 >/dev/null 2>&1 &
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${FanSpeed}% - ${SENSORa} - Goldilock zone, below min for another 1HR, reducing fans by 5" >> ${PW_LOGFOLDER}/esxi-fanspeeds.log
# elif [ -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl ] && [ ${FanSpeed} -gt ${PW_ESXI_MIN_FANSPEED} ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.gl)) -ge 10800 ]; then
# SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FAN CONTROL" "DAAAMMMNN GOLDIE!!!! Decreasing by 5 - ${FanSpeed}% --> $(expr ${FanSpeed} - 5)%"
# echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${FanSpeed}% - ${SENSORa} - DAAAMMMNN GOLDIE!!!! Decreasing by 5 - ${FanSpeed}% --> $(expr ${FanSpeed} - 5)%" >> ${logtemp}
# echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${FanSpeed}% - ${SENSORa} - DAAAMMMNN GOLDIE!!!! Decreasing by 5 - ${FanSpeed}% --> $(expr ${FanSpeed} - 5)%" >> ${PW_LOGFOLDER}/esxi-fanspeeds.log
# SET_ESXI_FANSPEED $(expr $(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set | cut -d'~' -f 1) - 5) ${SENSORa} 5 >/dev/null 2>&1 &
elif [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ]; then
NEW_FanSpeed=$(GET_DEFAULT_FANSPEED ${SENSORa} ${FanSpeed})
# SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FanSpeed Control" "GOLDILOCK: Defaulting FanSpeeds to ${NEW_FanSpeed}%"
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} >/dev/null 2>&1 &
fi
### INCREASING ###
elif (( $(bc <<< "${temp_f} >= ${ESXI_DEFAULT_EXHAUST_MIN}") )); then
if [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ]; then
NEW_FanSpeed=$(expr $(GET_DEFAULT_FANSPEED ${SENSORa} ${FanSpeed}) + 5)
# SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FanSpeed Control" "INCREASE: Defaulting FanSpeeds to ${NEW_FanSpeed}%"
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} 5 >/dev/null 2>&1 &
else
(( $(bc <<< "${temp_f} >= $(expr ${ESXI_DEFAULT_EXHAUST_MIN} + 5)") )) && FAN_INCREASE=10 || FAN_INCREASE=5
NEW_FanSpeed=$(expr $(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set | cut -d'~' -f 1) + ${FAN_INCREASE})
if [ ${NEW_FanSpeed} -le $(expr ${PW_ESXI_MAX_FANSPEED} + 4) ] && [ ${FanSpeed} -ne ${PW_ESXI_MAX_FANSPEED} ]; then
[ ${NEW_FanSpeed} -gt ${PW_ESXI_MAX_FANSPEED} ] && NEW_FanSpeed=${PW_ESXI_MAX_FANSPEED}
[ ${NEW_FanSpeed} -ge 60 ] && SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} Exhaust Warm" "Increasing fans to ${NEW_FanSpeed}%"
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} ${FAN_INCREASE} >/dev/null 2>&1 &
fi
fi
### DECREASING ###
else
if [ ! -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ]; then
NEW_FanSpeed=$(expr $(GET_DEFAULT_FANSPEED ${SENSORa} ${FanSpeed}) - 5)
# SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FanSpeed Control" "DECREASE: Defaulting FanSpeeds to ${NEW_FanSpeed}%"
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} 5 >/dev/null 2>&1 &
else
(( $(bc <<< "${temp_f} <= $(expr ${ESXI_DEFAULT_EXHAUST_MIN} - 5)") )) && FAN_DECREASE=10 || FAN_DECREASE=5
NEW_FanSpeed=$(expr $(cat ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set | cut -d'~' -f 1) - ${FAN_DECREASE})
if [ ${NEW_FanSpeed} -ge $(expr ${PW_ESXI_MIN_FANSPEED} - 4) ] && [ ${FanSpeed} -ne ${PW_ESXI_MIN_FANSPEED} ]; then
[ ${NEW_FanSpeed} -lt ${PW_ESXI_MIN_FANSPEED} ] && NEW_FanSpeed=${PW_ESXI_MIN_FANSPEED}
[ ${NEW_FanSpeed} -ge 65 ] && SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} Exhaust Cooling" "Decreasing fans to ${NEW_FanSpeed}%"
SET_ESXI_FANSPEED ${NEW_FanSpeed} ${SENSORa} ${FAN_DECREASE} >/dev/null 2>&1 &
fi
fi
fi
touch ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.chkset
fi
elif [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" != *"${PW_HOST_IDRACS[${SENSORa}]}"* ]] && [[ "${vSENSOR}" = *"Exhaust"* ]]; then
if [ -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ]; then
SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FanSpeed Control" "Resetting Fans back to being Host Controlled"
rm -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}*
ipmitool -I lanplus -H ${PW_HOST_IDRACS[${SENSORa}]} -U ${PW_ESXI_USER} -P "${ESXI_PASS}" raw 0x30 0x30 0x01 0x01 >/dev/null 2>&1
elif [ "${FanSpeed}" != "" ]&& [ ${FanSpeed} -ge 90 ] && [ ! -f ${PW_TMPFOLDER}/temp.* ] && [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" != *"${PW_HOST_IDRACS[${SENSORa}]}"* ]]; then
SENDNOTICE "${PW_HOST_IDRACS[${SENSORa}]} FAN ISSUE?!" "Possible fan issue, currently running at ${FanSpeed}%" 1
fi
fi
if [[ "${SENSORa}" != *"-Usage"* ]] && [[ "${SENSORa}" != *"FAN"* ]] && (( $(bc <<< "${temp_f} < ${temp_warn}") )); then
if (( $(bc <<< "${last_temp} >= ${temp_warn}") )); then
[ -f ${PW_TMPFOLDER}/${SENSORa}.down ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSORa}.down)) -ge 1800 ] && SENDNOTICE "${SENSOR_DESC} BACK TO NORMAL" "NORMAL TEMP: ${temp_f}${GAUGESH}
Previous Temp: ${last_temp}${GAUGESH}"
echo -e "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - Back to NORMAL ${GAUGE} - Previous ${GAUGE}: ${last_temp}${GAUGESH}" >> ${logtemp}
# [ "$(compgen -G "${PW_TMPFOLDER}/power.*.off")" != "" ] && rm -f ${PW_TMPFOLDER}/power.*.off
elif [ "${last_temp}" == "0" ]; then
# SENDNOTICE "${SENSOR} TEMP NORMAL" "Service Startup
# NORMAL TEMP: ${temp_f}${GAUGESH}"
echo -e "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - Service Startup - NORMAL ${GAUGE}" >> ${logtemp}
# echo -e "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - ${SENSOR} - Service Startup" >> ${PW_LOGFILE}
# [ "$(compgen -G "${PW_TMPFOLDER}/power.*.off")" != "" ] && rm -f ${PW_TMPFOLDER}/power.*.off
elif [ "${relog}" == "1" ]; then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - Normal ${GAUGE}" >> ${logtemp}
fi
[[ "${SENSOR}" = *"${PW_SHUTDOWN_SENSORS}"* ]] && rm -f ${PW_TMPFOLDER}/temp.*
rm -f ${PW_TMPFOLDER}/temp.*${SENSOR}*
rm -f ${PW_TMPFOLDER}/power.${SENSORa}.*
# if [ "${last_temp}" != "1" ]; then
# last_temp=1
echo ${temp_f} >| ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
# fi
elif [[ "${SENSORa}" != *"-Usage"* ]] && [[ "${SENSORa}" != *"FAN"* ]]; then
if ([ ! "${last_temp}" ] || (( $(bc <<< "${last_temp} < 2") ))); then
if [ "${last_temp}" != "${temp_f}" ]; then
last_temp=${temp_f}
echo ${last_temp} >| ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
fi
fi
temp_diff=`echo "scale=2; ${last_temp}-${temp_f}" | tr -d $'\r' | bc`
[ $(bc -l <<< "${temp_diff} < 0") -eq 1 ] && temp_diff=`echo "scale=2; ${temp_diff}*-1" | tr -d $'\r' | bc`
if [ $(bc -l <<< "${temp_f} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit}") -eq 1 ]; then
# [[ "${SENSOR}" = *"${PW_SHUTDOWN_SENSORS}"* ]] && touch ${PW_TMPFOLDER}/temp.warn
touch ${PW_TMPFOLDER}/temp.warn.${SENSOR}
if [ ! -f ${PW_TMPFOLDER}/temp.warn.${SENSOR}.pre ]; then
touch ${PW_TMPFOLDER}/temp.warn.${SENSOR}.pre
elif [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/temp.warn.${SENSOR}.pre)) -ge 600 ]; then
# if (( $(bc <<< "${temp_diff} >= 1") )); then
touch ${PW_TMPFOLDER}/temp.warn.${SENSOR}.pre
SENDNOTICE "${SENSOR_DESC} ${GAUGE} WARNING" "WARNING ${GAUGE}: ${temp_f}${GAUGESH} - (Difference of ${temp_diff}${GAUGESH})" 1
if [ "${last_temp}" != "${temp_f}" ]; then
last_temp=${temp_f}
echo ${last_temp} >| ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
fi
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - WARNING ${GAUGE} - (Difference of ${temp_diff}${GAUGESH})" >> ${logtemp}
fi
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit}") -eq 1 ] && [ $(bc -l <<< "${temp_f} < ${temp_crit_sys}") -eq 1 ]; then
if [ ! -f ${PW_TMPFOLDER}/temp.crit.${SENSOR}.pre ]; then
touch ${PW_TMPFOLDER}/temp.crit.${SENSOR}.pre
elif [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/temp.crit.${SENSOR}.pre)) -ge 300 ]; then
# if (( $(bc <<< "${temp_diff} >= 1") )); then
touch ${PW_TMPFOLDER}/temp.crit.${SENSOR}.pre
SENDNOTICE "${SENSOR_DESC} ${GAUGE} CRITICAL" "CRITICAL ${GAUGE}: ${temp_f}${GAUGESH} - (Difference of ${temp_diff}${GAUGESH})" 1
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - CRITICAL - (Difference of ${temp_diff}${GAUGESH})" >> ${logtemp}
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSOR_DESC} - ${temp_f}${GAUGESH} - CRITICAL ${GAUGE} - (Difference of ${temp_diff}${GAUGESH})" >> ${PW_LOGFILE}
if [ "${last_temp}" != "${temp_f}" ]; then
last_temp=${temp_f}
echo ${last_temp} >| ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
fi
if [[ "${SENSOR}" = *"${PW_SHUTDOWN_SENSORS}"* ]] && [ ! -f ${PW_TMPFOLDER}/temp.crit.${SENSOR} ]; then
touch ${PW_TMPFOLDER}/temp.crit.${SENSOR}
SHUTDOWN_MAIN ${SENSOR} &
echo -e "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - Shutting down MAIN servers" >> ${logtemp}
# elif [ ! -f ${PW_TMPFOLDER}/power.${SENSORa}.off ]; then
# SENDNOTICE "${SENSORa} TEMP CRITICAL" "Host system and VMs shutting down!!" 1
# SHUTDOWN_SERVER ${SENSORa} -esxi off &
# touch ${PW_TMPFOLDER}/power.${SENSORa}.off
fi
fi
elif [ $(bc -l <<< "${temp_f} >= ${temp_crit_sys}") -eq 1 ]; then
if [ ! -f ${PW_TMPFOLDER}/temp.critsys.${SENSOR}.pre ]; then
touch ${PW_TMPFOLDER}/temp.critsys.${SENSOR}.pre
# elif [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/temp.critsys.${SENSOR}.pre)) -ge 120 ] || [ ${temp_diff} > 1 ]; then
elif [ ! -f ${PW_TMPFOLDER}/temp.critsys.${SENSOR} ] || [ ${temp_diff} > 1 ]; then
# if (( $(bc <<< "${temp_diff} >= 1") )); then
touch ${PW_TMPFOLDER}/temp.critsys.${SENSOR}.pre
SENDNOTICE "${SENSOR_DESC} TEMP CRITICAL" "SYSTEM CRITICAL ${GAUGE}: ${temp_f}${GAUGESH} - (Difference of ${temp_diff}${GAUGESH})" 1
# [ $(bc -l <<< "${temp_diff} >= 5") -eq 1 ] && SENDNOTICE "${SENSOR} TEMP CRITICAL" "SYSTEM CRITICAL ${GAUGE}: ${temp_f}${GAUGESH} - (Difference of ${temp_diff}${GAUGESH})" 1
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - SYSTEM CRITICAL - (Difference of ${temp_diff})" >> ${logtemp}
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - ${SENSOR} - CRITICAL ${GAUGE} SYSTEM - (Difference of ${temp_diff}${GAUGESH})" >> ${PW_LOGFILE}
if [ "${last_temp}" != "${temp_f}" ]; then
last_temp=${temp_f}
echo ${last_temp} >| ${PW_TMPFOLDER}/.lasttemp/${SENSOR}
fi
if [[ "${SENSOR}" = *"${PW_SHUTDOWN_SENSORS}"* ]] && [ ! -f ${PW_TMPFOLDER}/temp.critsys.${SENSOR} ]; then
touch ${PW_TMPFOLDER}/temp.critsys.${SENSOR}
SHUTDOWN_SYS ${SENSOR} TEMP &
SHUTDOWN_CRIT ${SENSOR} &
echo -e "($(date +'%Y-%m-%d %H:%M:%S')) - ${temp_f}${GAUGESH} - Sending system shutdown signals, if applicable. Check main Powerwall Logs" >> ${logtemp}
fi
fi
fi
fi
[ -f ${PW_TMPFOLDER}/.lastinsert/${SENSOR} ] && lastinsert=$(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastinsert/${SENSOR})) || lastinsert=100000
if [ $(ls ${PW_TMPFOLDER}/temp.* 2>/dev/null | wc -l) -gt 0 ] || [ "$(compgen -G "${PW_TMPFOLDER}/power.*.low")" != "" ]; then
wait=$(echo "scale=0; ${PW_MYSQL_LOG_INTERVAL_ABNORMAL}*60" | tr -d $'\r' | bc)
else
wait=$(echo "scale=0; ${PW_MYSQL_LOG_INTERVAL_NORMAL}*60" | tr -d $'\r' | bc)
fi
if [ "${mysql_conn}" != "" ] && [ "${PW_SENSOR_ID[${SENSORa}]}" != "" ] && [ ${lastinsert} -ge ${wait} ] && [ "${temp_f}" != "32.00" ] && [ "${temp_f}" != "32" ] && [ "${temp_f}" != "35.60" ]; then
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${vSENSOR// /_}' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
if [ "${entityid[1]}" == "" ]; then
${mysql_conn} -e "USE servermonitor; INSERT INTO entities (sensorid, name) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','${vSENSOR// /_}')"
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${vSENSOR// /_}' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
fi
entityid=${entityid[1]}
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, entity, date, temp) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','${entityid}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_f}')"
# if [[ "${PW_ESXI_FANSPEEDCONTROL_HOSTS}" = *"${PW_HOST_IDRACS[${SENSORa}]}"* ]] && [ "${vSENSOR// /_}" == "System_Board_Inlet" ] && [ "${FanSpeed}" != "" ]; then
if [ "${vSENSOR// /_}" == "System_Board_Inlet" ] && [ "${FanSpeed}" != "" ]; then
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='FanSpeed' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
if [ "${entityid[1]}" == "" ]; then
${mysql_conn} -e "USE servermonitor; INSERT INTO entities (sensorid, name) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','FanSpeed')"
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='FanSpeed' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
fi
entityid=${entityid[1]}
${mysql_conn} -e "USE servermonitor; INSERT INTO sensor_data (sensorid, entity, date, speed) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','${entityid}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${FanSpeed}')"
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ] && [[ "${SENSORa}" = *"FAN"* ]]; then
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, date, speed) VALUES ('${PW_SENSOR_ID[${SENSORa}]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_c}')"
elif [ "${temp_h}" != "" ] && [ "${temp_h}" != "0" ]; then
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, date, temp, hum) VALUES ('${PW_SENSOR_ID[${SENSORa}]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_f}','${temp_h}')"
elif [ "${SENSOR}" == "Powerwall-Switch" ]; then
[ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && touch ${PW_TMPFOLDER}/${SENSOR}.down
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ]; then
touch ${PW_TMPFOLDER}/${SENSOR}-error.reading
elif [ ! -f ${PW_TMPFOLDER}/${SENSOR}.disable ] && (([ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 60 ]) || ([ -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.sent)) -ge $(echo "scale=0; ${PW_RENOTIFY_TIMEOUT}*60" | tr -d $'\r' | bc) ])); then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSOR} Sensor - ERROR reading sensor data" >> ${logtemp}
if [ ${PW_ENABLE_RENOTIFY} -eq 1 ] || [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ]; then
SENDNOTICE "${SENSOR_DESC} Sensor ERROR" "ERROR reading sensor data" 1
touch ${PW_TMPFOLDER}/${SENSOR}-error.sent
fi
fi
QRY=""
elif [ "${SENSOR}" == "AC" ]; then
if [ "${target}" != "32" ] && [ "${target}" != "32.00" ]; then
${mysql_conn} -e "USE servermonitor; INSERT INTO sensor_data (sensorid, date, temp) VALUES ('38',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${target}')"
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, date, temp) VALUES ('${PW_SENSOR_ID[${SENSOR}]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_f}')"
fi
else
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, date, temp) VALUES ('${PW_SENSOR_ID[${SENSORa}]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_f}')"
fi
if [ "${QRY}" != "" ]; then
${mysql_conn} -e "${QRY}"
echo "${temp_f}" >| ${PW_TMPFOLDER}/.lastinsert/${SENSOR}
if [[ "${PW_LATEST_TEMP_SENSORS}" == *",${PW_SENSOR_ID[${SENSOR}]},"* ]] || [[ "${PW_LATEST_TEMP_SENSORS}" == "${PW_SENSOR_ID[${SENSOR}]},"* ]] || [[ "${PW_LATEST_TEMP_SENSORS}" == *",${PW_SENSOR_ID[${SENSORa}]}" ]]; then
# ltid=($(${mysql_conn} -e "SELECT id FROM servermonitor.latest_sensor_data WHERE sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
# if [ "${ltid[1]}" == "" ]; then
# ${mysql_conn} -e "USE servermonitor; INSERT INTO latest_sensor_data (sensorid, date, temp) VALUES ('${PW_SENSOR_ID[${SENSORa}]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_f}')"
# else
${mysql_conn} -e "USE servermonitor; UPDATE latest_sensor_data SET date = CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'), temp = '${temp_f}' WHERE sensorid='${PW_SENSOR_ID[${SENSORa}]}'"
# fi
fi
fi
# if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "lacrosse" ]; then
# ${mysql_conn} -e "USE servermonitor; INSERT INTO sensor_data (sensorid, date, temp) VALUES ('${PW_SENSOR_ID["${SENSORa}-Probe"]}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${temp_probe_f}')"
# 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
# if [ ! -f ${PW_TMPFOLDER}/.log.sr.difference ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.log.sr.difference)) -ge 300 ]; then
# if [ "${temp_f}" != "" ] && (( $(bc <<< "${temp_f} >= 2") )) && [ -f ${PW_TMPFOLDER}/.serverroomtemp ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.serverroomtemp)) -lt 30 ]; then
# [ ! -f ${PW_TMPFOLDER}/.log.sr.difference ] && touch ${PW_TMPFOLDER}/.log.sr.difference
# temp_difference=$(bc <<< "scale=2; $(cat ${PW_TMPFOLDER}/.serverroomtemp)-${temp_f}")
# # (( $(bc <<<"${temp_difference} < 0") )) && temp_difference=`echo "scale=2; ${temp_difference} * -1" | tr -d $'\r' | bc`
# echo "$(date "+%Y-%m-%d %H:%M:%S")~${temp_difference}" >> ${PW_TMPFOLDER}/.log.sr.difference
# # echo "[$(date +'%Y-%m-%d %H:%M:%S')] ${temp_f} - $(cat ${PW_TMPFOLDER}/.serverroomtemp) = ${temp_difference}"
# rm -f ${PW_TMPFOLDER}/.serverroomtemp
# fi
# fi
# elif [ "${SENSOR}" == "ServerRoomTemp" ]; then
# echo ${temp_f} >| ${PW_TMPFOLDER}/.serverroomtemp
# fi
###################
else
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.disable ] && ([ "${PW_ESXI_HOST_NAME[${SENSORa}]}" == "" ] || ([[ "${PW_ESXI_HOST_NAME[${SENSORa}]}" != *"10.2."* ]] || ([[ "${PW_ESXI_HOST_NAME[${SENSORa}]}" = *"10.2."* ]] && [ ! -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ]))); then
[ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] && touch ${PW_TMPFOLDER}/${SENSOR}.down
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ]; then
touch ${PW_TMPFOLDER}/${SENSOR}-error.reading
elif [ ! -f ${PW_TMPFOLDER}/${SENSOR}.disable ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 60 ]; then
if [ "${SENSOR}" == "ServerRoomTemp" ] && ([ ! -f ${PW_TMPFOLDER}/${SENSOR}.restart ] || ([ -f ${PW_TMPFOLDER}/${SENSOR}.restart ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.restart)) -ge 900 ])); then
# if [ "${PW_REMOTE_SENSORS[${SENSOR}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSOR}]})" != "false" ]; then
touch ${PW_TMPFOLDER}/${SENSOR}.restart
SENDNOTICE "Restarting TG-Outlet-2 to restart ServerRoom-NetworkRack" "ERROR reading ServerRoom-NetworkRack"
RUN=$(curl -m 8 -s -H "Authorization: Bearer ${PW_ESPHOME_API}" -H "Content-Type: application/json" -d '{"entity_id": "switch.smart_15em_plug_in_2_socket"}' ${PW_HOMEASSISTANT_URL}/api/services/switch/turn_off)
sleep 2s
RUN=$(curl -m 8 -s -H "Authorization: Bearer ${PW_ESPHOME_API}" -H "Content-Type: application/json" -d '{"entity_id": "switch.smart_15em_plug_in_2_socket"}' ${PW_HOMEASSISTANT_URL}/api/services/switch/turn_on)
# fi
elif [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] || ([ -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.sent)) -ge $(echo "scale=0; ${PW_RENOTIFY_TIMEOUT}*60" | tr -d $'\r' | bc) ]); then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSOR} Sensor - ERROR reading sensor data" >> ${logtemp}
if [ ${PW_ENABLE_RENOTIFY} -eq 1 ] || [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.sent ]; then
SENDNOTICE "${SENSOR_DESC} Sensor ERROR" "ERROR reading sensor data" 1
touch ${PW_TMPFOLDER}/${SENSOR}-error.sent
fi
fi
fi
fi
fi
done
if [ "${mysql_conn}" != "" ] && [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
vHOST_FANS=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.12.1.8.1 -O vq | sed -e 's/"//g')
IFS=$'\n'; read -rd '' -a vHOST_FANS <<<"${vHOST_FANS}"; unset IFS
vHFid=0
for vHOST_FAN in "${vHOST_FANS[@]}"; do
((vHFid++))
fanrpm=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${SENSORa}]} .1.3.6.1.4.1.674.10892.5.4.700.12.1.6.1.${vHFid} -O vq | sed -e 's/"//g')
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${vHOST_FAN// /_}' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
if [ "${entityid[1]}" == "" ]; then
${mysql_conn} -e "USE servermonitor; INSERT INTO entities (sensorid, name) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','${vHOST_FAN// /_}')"
entityid=($(${mysql_conn} -e "SELECT id FROM servermonitor.entities WHERE BINARY name='${vHOST_FAN// /_}' AND sensorid='${PW_SENSOR_ID[${SENSORa}]}'"))
fi
entityid=${entityid[1]}
QRY="USE servermonitor; INSERT INTO sensor_data (sensorid, entity, date, speed) VALUES ('${PW_SENSOR_ID[${SENSORa}]}','${entityid}',CONVERT_TZ('$(date +'%Y-%m-%d %H:%M:%S')', 'America/Chicago', 'UTC'),'${fanrpm}')"
${mysql_conn} -e "${QRY}"
echo "${fanrpm}" >| ${PW_TMPFOLDER}/.lastinsert/${SENSORa}-${vHOST_FAN// /_}
done
fi
fi
else
if [ ! -f ${PM_TMPFOLDER}/${SENSORa}.disable ] && ([ "${PW_ESXI_HOST_NAME[${SENSORa}]}" == "" ] || ([[ "${PW_ESXI_HOST_NAME[${SENSORa}]}" != *"10.2."* ]] || ([[ "${PW_ESXI_HOST_NAME[${SENSORa}]}" = *"10.2."* ]] && [ ! -f ${PW_TMPFOLDER}/OFF-vMS-Host1.down ]))); then
[ ! -f ${PW_TMPFOLDER}/${SENSORa}.down ] && touch ${PW_TMPFOLDER}/${SENSORa}.down
if [ ! -f ${PW_TMPFOLDER}/${SENSORa}-error.reading ]; then
touch ${PW_TMPFOLDER}/${SENSORa}-error.reading
elif [ ! -f ${PW_TMPFOLDER}/${SENSORa}.disable ] && (([ ! -f ${PW_TMPFOLDER}/${SENSORa}-error.sent ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSORa}-error.reading)) -ge 60 ]) || ([ -f ${PW_TMPFOLDER}/${SENSORa}-error.sent ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSORa}-error.sent)) -ge $(echo "scale=0; ${PW_RENOTIFY_TIMEOUT}*60" | tr -d $'\r' | bc) ])); then
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SENSORa} Sensor - ERROR reading sensor data" >> ${logtemp}
if [ ${PW_ENABLE_RENOTIFY} -eq 1 ] || [ ! -f ${PW_TMPFOLDER}/${SENSORa}-error.sent ]; then
SENDNOTICE "${SENSOR_DESC} Sensor ERROR" "ERROR reading sensor data" 1
touch ${PW_TMPFOLDER}/${SENSORa}-error.sent
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ] && [ -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set ] && [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set)) -ge 900 ]; then
rm -f ${PW_TMPFOLDER}/.lastfancheck/${SENSORa}.set
fi
fi
fi
rm -f ${PW_TMPFOLDER}/ztemprun.${SENSORa}.running
touch ${PW_TMPFOLDER}/ztemprun.${SENSORa}.done
}
SET_ESXI_FANSPEED(){
[ "${PW_ESXI_DEF_FANSPEED}" != "" ] && ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED} || ESXI_DEF_FANSPEED=${PW_ESXI_DEF_FANSPEED}
SET_FanSpeed=${1}
SET_HOST=${2}
SET_fanchange=${3}
fan="${FanSpeed}%"
[[ "${PW_HOST_IDRACS[${SET_HOST}]}" = "10.6."* ]] && ESXI_PASS=${PW_ESXI_PASS_KP} || ESXI_PASS=${PW_ESXI_PASS}
if [ ${SET_FanSpeed} -ge ${PW_ESXI_MIN_FANSPEED} ] && [ ${SET_FanSpeed} -le ${PW_ESXI_MAX_FANSPEED} ]; then
ipmitool -I lanplus -H ${PW_HOST_IDRACS[${SET_HOST}]} -U ${PW_ESXI_USER} -P "${ESXI_PASS}" raw 0x30 0x30 0x01 0x00 >/dev/null 2>&1
ipmitool -I lanplus -H ${PW_HOST_IDRACS[${SET_HOST}]} -U ${PW_ESXI_USER} -P "${ESXI_PASS}" raw 0x30 0x30 0x02 0xff 0x$(printf "%X" "${SET_FanSpeed}") >/dev/null 2>&1
if [ "${3}" == "manual" ]; then
MSG="Manually set Fans to: ${SET_FanSpeed}%"
fan=manual
elif [ "${SET_FanSpeed}" == "${ESXI_DEF_FANSPEED}" ]; then
MSG="Setting Fans back to defaults: ${SET_FanSpeed}%"
elif (( $(bc <<< "${SET_FanSpeed} < $(cat ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set | cut -d'~' -f 1)") )); then
MSG="Decreasing fans to ${SET_FanSpeed}%"
else
MSG="Increasing fans to ${SET_FanSpeed}%"
fi
[ ! -f ${PW_LOGFOLDER}/esxi-fanspeeds.log ] && touch ${PW_LOGFOLDER}/esxi-fanspeeds.log
[ "${logtemp}" != "" ] && echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SET_FanSpeed}% - ${SET_HOST} - ${MSG}" >> ${logtemp}
[ ${SET_FanSpeed} -ge $(expr ${PW_ESXI_MAX_FANSPEED} - 5) ] && echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${SET_FanSpeed}% - ${SET_HOST} - ${MSG}" >> ${PW_LOGFILE}
echo "($(date +'%Y-%m-%d %H:%M:%S')) - ${fan} - ${SET_HOST} - ${MSG}" >> ${PW_LOGFOLDER}/esxi-fanspeeds.log
if [ "${SET_fanchange}" == "manual" ]; then
echo "${SET_FanSpeed}~m" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set
elif [ "${SET_fanchange}" == "" ]; then
echo "${SET_FanSpeed}~" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set
else
if [ $(bc -l <<< "${SET_FanSpeed} < $(cat ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set | cut -d'~' -f 1)") -eq 1 ]; then
[ "${SET_fanchange}" == "10" ] && echo "${SET_FanSpeed}~dd" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set || echo "${SET_FanSpeed}~d" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set
elif [ $(bc -l <<< "$(cat ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set | cut -d'~' -f 1) < ${SET_FanSpeed}") -eq 1 ]; then
[ "${SET_fanchange}" == "10" ] && echo "${SET_FanSpeed}~uu" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set || echo "${SET_FanSpeed}~u" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set
else
echo "${SET_FanSpeed}~e" >| ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.set
fi
fi
[ -f ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.gl ] && rm -f ${PW_TMPFOLDER}/.lastfancheck/${SET_HOST}.gl
fi
}
ESXI_FANSPEED_MGMT(){
HOST=${1}
FANSPEED=${2}
MN=0
if [ "${HOST}" == "" ] || [ "${FANSPEED}" == "" ]; then
echo -e "\nMissing arguments\n"
exit 1
fi
echo -e "${idsCL[Yellow]}Setting new FanSpeeds for the following ESXi Hosts:"
DIVIDER . yellow ${PRI_WIDTH}
if [ "${PW_iDRACHOST_SHORTNAMES[${HOST}]}" != "" ]; then
tmp=${PW_iDRACHOST_SHORTNAMES[${HOST}]}
ESXI_HOST=${PW_HOST_ADDRESSES[${tmp}]}
elif [ "${PW_ESXI_HOST_NAMES[${HOST}]}" != "" ]; then
ESXI_HOST=${HOST}
elif [ "${PW_HOST_ADDRESSES[iDS-vMS-Host${HOST}]}" != "" ]; then
ESXI_HOST=${PW_HOST_ADDRESSES[iDS-vMS-Host${HOST}]}
elif ([ "${HOST::1}" == "o" ] || [ "${HOST::1}" == "O" ]) && [ "${PW_HOST_ADDRESSES[OFF-vMS-Host${HOST: -1}]}" != "" ]; then
ESXI_HOST=${PW_HOST_ADDRESSES[OFF-vMS-Host${HOST: -1}]}
elif ([ "${HOST::1}" == "k" ] || [ "${HOST::1}" == "K" ]) && [ "${PW_HOST_ADDRESSES[KP-vMS-Host${HOST: -1}]}" != "" ]; then
ESXI_HOST=${PW_HOST_ADDRESSES[KP-vMS-Host${HOST: -1}]}
elif [ "${PW_HOST_ADDRESSES[${HOST}]}" != "" ]; then
ESXI_HOST=${PW_HOST_ADDRESSES[${HOST}]}
elif [ "${HOST^^}" == "ALL" ] || [ "${HOST^^}" == "MAINSITE" ] || [ "${HOST^^}" == "OFFSITE" ] || [ "${HOST^^}" == "MAIN" ] || [ "${HOST^^}" == "SYS" ] || [ "${HOST^^}" == "CONSERVE" ]; then
ESXI_HOST=${HOST^^}
MN=1
else
ESXI_HOST=''
fi
if [ "${ESXI_HOST}" == "" ]; then
echo -e "Invalid host\n"
exit 1
fi
if [ ${MN} -eq 1 ]; then
[ "${ESXI_HOST}" == "ALL" ] && hostname="All Host Servers" || hostname="All ${ESXI_HOST} Host Servers"
ESXI_HOSTS=PW_${ESXI_HOST}_HOSTS; ESXI_HOSTS=${!ESXI_HOSTS}
else
tmp=${PW_ESXI_HOST_NAMES[${ESXI_HOST}]}
idracip=${PW_HOST_IDRACS[${tmp}]}
hostname=${PW_iDRACHOST_SHORTNAMES[${idracip}]}
fi
h=1
for host in ${PW_ESXI_FANSPEEDCONTROLHOSTS[@]}; do
tmp=temp
if ([ ${MN} -eq 1 ] && [[ "${ESXI_HOSTS}" = *"${PW_HOST_ADDRESSES[${PW_iDRACHOST_SHORTNAMES[${host}]}]}"* ]]) || ([ "${idracip}" != "" ] && [ "${idracip}" == "${host}" ]); then
tmp=temp
echo -en "${idsCL[LightCyan]}${1}) ${PW_iDRACHOST_SHORTNAMES[${host}]} [${PW_HOST_ADDRESSES[${PW_iDRACHOST_SHORTNAMES[${host}]}]}]"
[ -f ${PW_TMPFOLDER}/${PW_iDRACHOST_SHORTNAMES[${host}]}.down ] && echo " - Offline, skipping" || echo
fi
done
DIVIDER true yellow ${PRI_WIDTH}
for host in ${PW_ESXI_FANSPEEDCONTROLHOSTS[@]}; do
tmp=temp
if ([ ${MN} -eq 1 ] && [[ "${ESXI_HOSTS}" = *"${PW_HOST_ADDRESSES[${PW_iDRACHOST_SHORTNAMES[${host}]}]}"* ]]) || ([ "${idracip}" != "" ] && [ "${idracip}" == "${host}" ]); then
echo -en "${idsCL[Yellow]}Setting new FanSpeeds for ${PW_iDRACHOST_SHORTNAMES[${host}]} [${PW_HOST_ADDRESSES[${PW_iDRACHOST_SHORTNAMES[${host}]}]}]: "
if [ ! -f ${PW_TMPFOLDER}/${PW_iDRACHOST_SHORTNAMES[${host}]}.down ]; then
SET_ESXI_FANSPEED ${FANSPEED} ${PW_iDRACHOST_SHORTNAMES[${host}]} manual #>/dev/null 2>&1
rm -f ${PW_TMPFOLDER}/.lastfancheck/${PW_iDRACHOST_SHORTNAMES[${host}]}.gl
echo -e "${idsCL[Green]}FanSpeed set to ${FANSPEED}${idsCL[Default]}"
else
echo -e "${idsCL[Yellow]}Skipping, host offline${idsCL[Default]}"
fi
fi
done
echo
}
SENDTEMPS(){
st_temps=$(SENDTEMP ${2})
SENDNOTICE "${1}" "${st_temps}"
}
SENDTEMP(){
echo
echo -en "Sensor Temperature(s)"
[ "${1}" != "" ] && echo " Now / 1DayAVG / 7DayAVG" || echo
DIVIDER . . 40
for SENSORa in ${PW_SENSOR_ORD[@]}; do
# echo "HERE: ${SENSORa}"
# ([[ "${SENSORa}" = *"-Probe"* ]] || [[ "${SENSORa}" = *"-Usage"* ]]) && cw=25 || cw=30
cw=30
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" != "esxi" ] && ([ "${PW_SENSOR_TYPE[${SENSORa}]}" == "lacrosse" ] || ([ "${PW_REMOTE_SENSORS[${SENSORa}]}" != "" ] && [ "$(CHECK_HOST ${PW_REMOTE_SENSORS[${SENSORa}]})" != "false" ])); then
SENSORS_CHECK=(${SENSORa})
for SENSOR in "${SENSORS_CHECK[@]}"; do
[ "${PW_DESC_TEMP[${SENSOR}]}" != "" ] && SENSOR_DESC=${PW_DESC_TEMP[${SENSOR}]} || SENSOR_DESC=${SENSOR}
c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR_DESC}`; until [ ${c} = ${spc1} ]; do spc="${spc} "; ((c++)); done
# echo "HERE: ${SENSOR} - ${SENSORa} ~ ${SENSOR_DESC}"
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "cpu" ]; then
GAUGESH="'%"
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
GAUGESH="'R"
else
GAUGESH="'F"
fi
[ "${last_sensor}" != "" ] && [ "${last_sensor%%-*}" != "${SENSOR_DESC%%-*}" ] && echo
if [ "${mqtt_conn}" != "" ] && [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "mqtt" ]; then
mqtt_message=`${mqtt_conn} -t tele/${SENSORa}/SENSOR -C 1`
echo ${mqtt_message} | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "lacrosse" ]; then
INFO=$(curl -m 5 -s --get -d "deviceid=${PW_SENSOR_DEVICEID[${SENSOR}]}" -d "limit=1" -d "metric=1" -d "timezone=2" https://decent-destiny-704.appspot.com/laxservices/device_info.php | jq)
if [[ "${SENSORa}" = *"-Probe" ]]; then
temp_c=$(echo ${INFO} | jq -r '.device0 .obs[].probe_temp')
else
temp_c=$(echo ${INFO} | jq -r '.device0 .obs[].ambient_temp')
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esphome" ]; then
if ! temp_c=$(curl -m 5 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${SENSORa}]}_temperature | jq -r '.state') ; then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_f=${temp_c}
temp_h=$(curl -m 5 -s GET -H "Authorization: Bearer ${PW_ESPHOME_API}" ${PW_HOMEASSISTANT_URL}/api/states/sensor.${PW_SENSOR_DEVICEID[${SENSORa}]}_humidity | jq -r '.state')
else
temp_c=''
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "espdev" ]; then
if ! temp_c=$(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${SENSORa}]}:8090/sensor/${PW_SENSOR_DEVICEID[${SENSORa}]} | jq '.value'); then TIMEOUT=1; fi
if [ "${temp_c}" != "" ]; then
temp_h=$(curl -m 8 -s -u "${PW_ESP_USER}:${PW_ESP_PASS}" http://${PW_REMOTE_SENSORS[${SENSORa}]}:8090/sensor/${PW_SENSOR_DEVICEID[${SENSORa}]/temperature/humidity} | jq '.value')
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "tuya" ]; then
IFS=: read -r temp_c temp_h <<< $(GET_TUYA_TEMP ${SENSORa}); unset IFS
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "midea" ]; then
IFS='~' read -r token key <<< ${PW_SENSOR_DEVICEID[${SENSORa}]}; unset IFS
info=$(midea-beautiful-air-cli status --ip ${PW_REMOTE_SENSORS[${SENSORa}]} --token ${token} --key ${key})
temp_c=$(echo "${info}" | grep indoor | awk ' {print $3}')
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "system" ]; then
if [[ "${SENSOR}" = *"CPU"* ]]; then
temp_c=$(vcgencmd measure_temp)
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
elif [[ "${SENSOR}" = *"FAN"* ]]; then
temp_c=$(cat ${PW_FANINPUT})
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "remotesystem" ]; then
temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSORa}]} vcgencmd measure_temp)
if [ "${temp_c}" != "" ]; then
temp_c=${temp_c%\'*}
temp_c=${temp_c#*=}
fi
# elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
# temp_c=${2}
# temp_warn=`echo $(bc <<< "scale=2; ((${3}*(9/5))+32)/1") | awk '{print int($1+0.5)}'`
# temp_crit=`echo $(bc <<< "scale=2; ((${4}*(9/5))+32)/1") | awk '{print int($1+0.5)}'`
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "cpu" ]; then
if [ "${SENSORa}" == "Powerwall-CPU-Usage" ]; then
temp_c=$(awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat) | sed -e 's/%//g')
else
temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSORa}]} "/opt/idssys/defaults/get-data.sh cpu-usage")
fi
elif [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "ds18b20" ]; then
if ! temp_c=$(${SSHCMD} root@${PW_REMOTE_SENSORS[${SENSORa}]} cat /sys/devices/w1_bus_master1/${PW_SENSOR_DEVICEID[${SENSORa}]}/w1_slave | tail -n1 | cut -d "=" -f2) ; then TIMEOUT=1; fi
[ "${temp_c}" != "" ] && temp_c=$(echo "scale=2; ${temp_c}/1000" | tr -d $'\r' | bc)
else
temp_c=''
fi
if [ "${1}" != "" ]; then
if [ "${PW_SENSOR_TYPE[${SENSORa}]}" == "esxi" ]; then
average1=$(AVERAGETEMP ${SENSORa} 1 ${vSENSOR// /_})
average7=$(AVERAGETEMP ${SENSORa} 7 ${vSENSOR// /_})
# average7=0
else
average1=$(AVERAGETEMP ${SENSORa} 1)
average7=$(AVERAGETEMP ${SENSORa} 7)
# average7=0
fi
fi
if [ "${temp_c}" != "null" ] && [ "${temp_c}" != "" ]; then
if [ "${SENSOR}" == "ServerRoomTH" ]; then
temp_f=`echo "scale=2; (${temp_c}*(9/5))+32+${PW_ServerRoomTH_Dev}" | tr -d $'\r' | bc`
else
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "cpu" ]; then
temp_f=$(echo "scale=2; $temp_c/1" | tr -d $'\r' | bc -l)
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
temp_f=${temp_c}
else
temp_f=$(bc <<< "scale=2; (${temp_c}*(9/5))+32")
fi
(( $(bc <<<"${temp_f} < 1") )) && [[ "${temp_f}" = *"."* ]] && temp_f="0${temp_f}"
fi
# if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ] && [[ "${SENSOR}" = *"FAN"* ]]; then
# temp_f_disp=$(IDS_NUMBER_FORMAT ${temp_f} 2 yes)
# if [ "${1}" != "" ]; then
# average1_disp=$(IDS_NUMBER_FORMAT ${average1} 2 yes)
# average7_disp=$(IDS_NUMBER_FORMAT ${average7} 2 yes)
# fi
# else
# temp_f_disp=${temp_f}
# if [ "${1}" != "" ]; then
# average1_disp=${average1}
# average7_disp=${average7}
# fi
# fi
temp_f_disp=$(IDS_NUMBER_FORMAT ${temp_f} 2 yes)
if [ "${1}" != "" ]; then
average1_disp=$(IDS_NUMBER_FORMAT ${average1} 2 yes)
average7_disp=$(IDS_NUMBER_FORMAT ${average7} 2 yes)
fi
[ "${1}" != "" ] && echo -e "${SENSOR_DESC}${spc}${temp_f_disp}${GAUGESH} / ${average1_disp}${GAUGESH} / ${average7_disp}${GAUGESH}" || echo -e "${SENSOR_DESC}${spc}${temp_f_disp}${GAUGESH}"
else
echo -e "${SENSOR_DESC}${spc}No Data"
fi
last_sensor=${SENSOR_DESC}
done
fi
done
}
GET_LACROSSE_INFO(){
INFO=$(/bin/python3 ${PW_INCFOLDER}/getInfo.lacrosse.py "${PW_SENSOR_DEVICEID[${1}]}" | sed -e "s/\[{'//g" | sed -e "s/}\]//g" | sed -e "s/', '/~/g" | sed -e "s/': '/:/g" | sed -e "s/': /:/g")
IFS=$'~'; read -rd '' -a INFO <<<"${INFO}"; unset IFS; declare -A DEVICE_INFO
for DINFOtmp in "${INFO[@]}"; do key=${DINFOtmp%%:*}; val=${DINFOtmp##*:}; val=${val//[$'\t\r\n ']}; DEVICE_INFO[${key}]=${val}; done
echo ${DEVICE_INFO['probe_temp']}
}
SERVERROOM_TEMP_DIFFERENCE(){
start=$(date +%s)
scandefault=288
while [ $# -gt 0 ]; do
case "${1}" in
-l|-last) LAST=${2};;
-h|-help|--help)
echo -e "Usage: ${idsCL[Yellow]}[powerwall or pw] tempdiff {opt}${idsCL[Default]} {"
width=15
printf "%-${width}s- %s\n" " -l,-last" "(number of last scan times to average from, defaults to ${scandefault})"
echo -e "}\n"
exit 0;;
esac
shift
done
[ "${LAST}" == "" ] && LAST=${scandefault}
echo -en "${idsCL[Yellow]}Pulling data and calculating average temperature differences for the last '${LAST}' scans ... "
last_tempdiff=$(tail -n 1 ${PW_TMPFOLDER}/.log.sr.difference)
last_tempdiff=${last_tempdiff#*~}
# if [ $(bc -l <<< "${last_tempdiff} < 1") -eq 1 ]; then [ "${last_tempdiff}" = "0" ] && last_tempdiff="0.0" || last_tempdiff="0${last_tempdiff}"; fi
last_tempdiff=`IDS_NUMBER_FORMAT ${last_tempdiff} 2 yes`
tempdiffs=$(tail -n ${LAST} ${PW_TMPFOLDER}/.log.sr.difference)
largest_tempdiff=0
IFS=$'\n'
read -rd '' -a tempdiffs <<<"${tempdiffs}"
unset IFS
tempdiff_total=0; scansfound=0
tempdiff_large_total=0; scansfound_large=0
for tempdiff in "${tempdiffs[@]}"; do
[[ "${tempdiff}" = *"~"* ]] && tempdiff=${tempdiff#*~}
if [ $(bc -l <<< "${tempdiff} <= 15") -eq 1 ]; then
# (( $(bc <<<"${tempdiff} < 0") )) && tempdiff_tmp1=`echo "scale=2; ${tempdiff} * -1" | tr -d $'\r' | bc` || tempdiff_tmp1=${tempdiff}
# (( $(bc <<<"${largest_tempdiff} < 0") )) && tempdiff_tmp2=`echo "scale=2; ${largest_tempdiff} * -1" | tr -d $'\r' | bc` || tempdiff_tmp2=${largest_tempdiff}
# [ $(bc -l <<< "${tempdiff_tmp1} >= ${tempdiff_tmp2}") -eq 1 ] && largest_tempdiff=${tempdiff}
# (( $(bc <<<"${tempdiff} < 0") )) && tempdiff_tmp1=`echo "scale=2; ${tempdiff} * -1" | tr -d $'\r' | bc` || tempdiff_tmp1=${tempdiff}
# [ $(bc -l <<< "${tempdiff_tmp1} >= ${largest_tempdiff}") -eq 1 ] && largest_tempdiff=${tempdiff_tmp1}
# [ $(bc -l <<< "${tempdiff} >= ${largest_tempdiff}") -eq 1 ] && largest_tempdiff=${tempdiff}
tempdiff_total=$(bc <<< "scale=2; ${tempdiff_total}+${tempdiff}")
((scansfound++))
else
tempdiff_large_total=$(bc <<< "scale=2; ${tempdiff_large_total}+${tempdiff}")
((scansfound_large++))
fi
done
# largest_tempdiff=`IDS_NUMBER_FORMAT ${largest_tempdiff} 2 yes`
# [ ${scansfound} -eq 0 ] && average=0 || average=$(bc <<< "scale=2; ${tempdiff_total}/${scansfound}")
[ ${scansfound} -eq 0 ] && average=0 || average=$(ROUND_NUMBER $(echo "scale=4; ${tempdiff_total}/${scansfound}" | tr -d $'\r' | bc -l) 2)
# [ ${scansfound_large} -eq 0 ] && average_large=0 || average_large=$(bc <<< "scale=2; ${tempdiff_large_total}/${scansfound_large}")
[ ${scansfound_large} -eq 0 ] && average_large=0 || average_large=$(ROUND_NUMBER $(echo "scale=4; ${tempdiff_large_total}/${scansfound_large}" | tr -d $'\r' | bc -l) 2)
# if [ $(bc -l <<< "${average} < 1") -eq 1 ]; then [ "${average}" = "0" ] && average="0.0" || average="0${average}"; fi
average=`IDS_NUMBER_FORMAT ${average} 2 yes`
[ -f ${PW_TMPFOLDER}/.log.sr.difference ] && last_scancheck=$(date -d @$(stat -c %Y ${PW_TMPFOLDER}/.log.sr.difference) "+%Y-%m-%d %H:%M:%S") || last_scancheck=""
echo -en "\r\033[K"
echo -e "${idsCL[LightCyan]}Scan Type Scans Average Temp Difference${idsCL[Default]}"
DIVIDER . lightCyan 60
echo -e "${idsCL[Green]}Average for last `IDS_NUMBER_FORMAT ${scansfound}` ${idsCL[LightGreen]}${average}'F${idsCL[Default]}"
DIVIDER . lightCyan 60
echo -e "${idsCL[Cyan]} - Large runs `IDS_NUMBER_FORMAT ${scansfound_large}` ${idsCL[LightCyan]}${average_large}'F${idsCL[Default]}"
echo
# echo -e "${idsCL[LightCyan]}Largest Temp Difference : ${idsCL[LightGreen]}${largest_tempdiff}'F${idsCL[Default]}"
# echo
echo -e "${idsCL[LightCyan]}Last Temp Difference : ${idsCL[LightGreen]}${last_tempdiff}'F${idsCL[Default]}"
echo -e "${idsCL[LightCyan]}Last Check : ${idsCL[LightGreen]}${last_scancheck}${idsCL[Default]}"
echo
echo -e "${idsCL[LightCyan]}Current Temp Deviation : ${idsCL[LightRed]}${PW_ServerRoomTH_Dev}'F${idsCL[Default]}"
if [ ${scansfound} -le 500 ]; then
if [ ${scansfound} -gt 15 ]; then
echo -en "\n${idsCL[LightCyan]}List out these '${scansfound}' scan times? (y/N): ${idsCL[Default]}"
read -n1 choice
if [ "${choice^^}" == "Y" ]; then
echo -en "\r\033[K"
gofor=1
else
gofor=0
fi
else
gofor=1
echo
fi
if [ ${gofor} -eq 1 ]; then
lastscansnum=${scansfound}
last_tempdiffs=$(tail -n ${lastscansnum} ${PW_TMPFOLDER}/.log.sr.difference)
IFS=$'\n'
read -rd '' -a last_tempdiffs <<<"${last_tempdiffs}"
unset IFS
echo -e "${idsCL[LightCyan]}Last ${lastscansnum} Scan Times\n${idsCL[Green]}------------------------------------------${idsCL[Default]}"
for tempdiff in "${last_tempdiffs[@]}"; do
if [[ "${tempdiff}" = *"~"* ]]; then
dt="${tempdiff%~*}"
tempdiff=${tempdiff#*~}
# if [ $(bc -l <<< "${tempdiff} < 1") -eq 1 ]; then [ "${tempdiff}" = "0" ] && tempdiff="0.0" || tempdiff="0${tempdiff}"; fi
tempdiff=`IDS_NUMBER_FORMAT ${tempdiff} 2 yes`
else
dt=" "
fi
echo -e "${idsCL[White]} ${dt} : ${idsCL[Yellow]}${tempdiff}'F${idsCL[Default]}"
done
fi
fi
end=`date +%s`; runtime=$((end-start))
echo -e "\nscript runtime: ${runtime}s\n"
}
GET_DEFAULT_FANSPEED(){
current=${2}
if [ ${current} -le ${PW_ESXI_MIN_FANSPEED} ]; then
set_current=${PW_ESXI_MIN_FANSPEED}
elif [ ${current} -ge ${PW_ESXI_MAX_FANSPEED} ]; then
set_current=${PW_ESXI_MAX_FANSPEED}
else
tmp_rem=$((current % 5))
[ "${tmp_rem}" -ge 3 ] && rounded_current=$((current + (5 - tmp_rem))) || rounded_current=$((current - tmp_rem))
set_current=${rounded_current}
fi
hfsfs=$(snmpwalk -v 1 -c public -t 2 ${PW_HOST_IDRACS[${1}]} .1.3.6.1.4.1.674.10892.5.2.5 -O vq | sed -e 's/"//g')
([ "${set_current}" != "" ] && [ ${current} -lt ${PW_ESXI_MAX_FANSPEED} ] && [ ${hfsfs} -ge 1800 ] && [ ${hfsfs} -le 60000 ]) && echo ${set_current} || echo ${PW_ESXI_DEF_FANSPEED}
}
GET_TUYA_TEMP(){
INFO=$(curl -m 3 -s http://${PW_REMOTE_SENSORS[${1}]}:8888/status/${PW_SENSOR_DEVICEID[${1}]} | jq '.dps')
if [ "${INFO}" != "" ]; then
TEMP=-1
if [ "$(echo "${INFO}" | grep '"108":')" != "" ]; then
TEMP=$(echo "${INFO}" | grep '"6":' | cut -d' ' -f 4 | sed 's/,//g')
TEMP=$(ROUND_NUMBER $(echo "scale=1; ${TEMP}/10" | tr -d $'\r' | bc -l) 1)
HUM=$(echo "${INFO}" | grep '"20":' | cut -d' ' -f 4 | sed 's/,//g')
# elif [ "$(echo "${INFO}" | grep '"6":')" != "" ]; then
# AMP=$(echo "${INFO}" | grep '"4":' | cut -d' ' -f 4 | sed 's/,//g')
# AMP=$(ROUND_NUMBER $(echo "scale=3; ${AMP}/1000" | tr -d $'\r' | bc -l) 2)
# WATT=$(echo "${INFO}" | grep '"5":' | cut -d' ' -f 4 | sed 's/,//g')
# WATT=$(echo "scale=1; ${WATT}/10" | tr -d $'\r' | bc -l)
# VOLT=$(echo "${INFO}" | grep '"6":' | cut -d' ' -f 4 | sed 's/,//g')
# VOLT=$(echo "scale=1; ${VOLT}/10" | tr -d $'\r' | bc -l)
fi
[ "${TEMP}" != "-1" ] && echo "${TEMP}:${HUM}" || echo "0:0"
fi
}