====== Como utilizar o sensor Temper para enviar e-mails de alerta ====== ===== No Proxmox / debian ou seus forks ===== * Baixe e instale os pacotes necessários echo baixando/instalando os pacotes/arquivos necessarios #apt install python3-serial jq git apt install python3-serial git git clone https://github.com/ccwienk/temper.git * Crie o script necessario para medir a temperatura e enviar e-mail com alerta #temperatura=$( /opt/temper/temper.py --json | jq --raw-output '.[] ."internal temperature"' ) temperatura=$( /opt/temper/temper.py | awk '{print $7}' | sed 's/C//' ) echo $temperatura maximo=26.0 teste=$(echo "$temperatura < $maximo" | bc) if [ $teste = '1' ]; then echo "temperature $temperaturaºC is smaller than $maximoºC"; else echo 'Alert! Temperature $temperaturaºC is biggest than $maximoºC'; echo "Enviando email..." set smtp=smtps://smtp.grude.ufmg.br:465 set from="sddr@icb.ufmg.br" set smtp-auth-user=icb-smtp set smtp-auth-password=SENHANOWIKI set smtp-auth=login set smtp-verify=ignore echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" gti@icb.ufmg.br echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" miguel@icb.ufmg.br echo "Enviado com sucesso" curl https://sistemas.icb.ufmg.br/whatsapp/api_tal.php?temperatura=$temperatura&key=094845968309298375 fi; ===== No XenServer/XCP-NG / redhat ou seus forks ===== * Instale os pacotes necessarios (comandos adaptados do site, mas precisa testar) #sudo apt install libhidapi-dev cmake sudo yum install hidapi cmake mkdir /opt cd /opt git clone https://github.com/edorfaus/TEMPered cd TEMPered cmake . cd utils make sudo /opt/TEMPered/utils/hid-query /dev/hidraw0 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 * Crie o seguinte script #!/bin/bash ## ## temper.sh ## reads and print temperature from TEMPer device(s) ## requires hid-query from the TEMPered project ## https://cylab.be/blog/92/measure-ambient-temperature-with-temper-and-linux ## for device in /dev/hidraw*; do ## quey $device and grep for return value #hexvalue=`/opt/TEMPered/utils/hid-query "$device" 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 2> /dev/null | grep -oP "80 80 K([0-9a-fA-F]{2} [0-9a-fA-F]{2})" | tr -d ' '` hexvalue=$(/opt/TEMPered/utils/hid-query "$device" 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 2> /dev/null | grep "80 80" | tr -d ' ') hexvalue=${hexvalue:5:4} ## convert hex to dec decvalue=`printf "%d" $((16#$hexvalue))` ## divide by 100 decvalue=`bc <<< "scale=2; ${decvalue}/100"` printf "%s : %s °C " $device $decvalue done; # continuar o codigo aqui para testar a temperatura se tiver acima de 26 graus e enviar e-mail de alerta # ... ===== Criando a cron para automatizar o teste de temperatura ===== * Se redhat ou derivados: Edite o arquivo /var/spool/cron/root * Se debian ou devirados: execute "crontab -e" * Cole o seguinte conteudo: 00-59/10 * * * * bash /opt/temper/cron.sh >> /opt/temper/cron.log