#!/usr/bin/env bash # powerwall - CLI commands to control VM guest power action="$1" FOLDER='/opt/idssys/powerwall' VERS='1.030921' source /opt/idssys/powerwall/defaults.inc source /opt/idssys/powerwall/powerwall.conf source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc shopt -s lastpipe #ssh root@10.5.10.35 '/vmfs/volumes/NFS_ESXi-Vault/esxi-shutdown.sh > /dev/null 2>&1' & > /dev/null 2>&1 CHECKTEMP(){ mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc` #echo "$temp_c -> $temp_f" echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then echo "WARNING: $temp_f°F" elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then echo "CRITICAL: $temp_f°F" else echo "normal: $temp_f°F" fi fi } CHECKTEMP_SERVICE(){ mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` while true do ${mqtt_conn} -t tele/${1}/SENSOR | while read -r mqtt_message do 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 echo $mqtt_message | cut -d'T' -f 2 | cut -d"\"" -f 3 | read temp_d echo $mqtt_message | cut -d'T' -f 3 | cut -d"\"" -f 1 | read temp_t if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc` #echo "$temp_c -> $temp_f" echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then echo "WARNING TEMP: $temp_f°F" | mail -s "${1} TEMP WARNING" $email_alert echo "($temp_d @ $temp_t) WARNING: $temp_f°F" elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then echo "CRITICAL TEMP: $temp_f°F" | mail -s "${1} TEMP CRITICAL" $email_alert echo "($temp_d @ $temp_t) CRITICAL: $temp_f°F" else echo "($temp_d @ $temp_t) normal: $temp_f°F" fi QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`, \`hum\`) VALUES ('${SENSOR_ID[$1]}','${temp_d} ${temp_t}','${temp_f}','${temp_h}')" # ${mysql_conn} -e "${QRY}" fi done sleep 10 done & } if [ ${action-x} ]; then case $action in checktemp) CHECKTEMP ${2};; checktemp_service) CHECKTEMP_SERVICE ${2};; esac fi exit 0