From 099b6cd71b66d9715606efe8c6836ea58f568c11 Mon Sep 17 00:00:00 2001 From: Sergio Pernas Date: Tue, 22 Mar 2022 14:25:35 -0300 Subject: [PATCH] monitor --- raspberry/bin/nodemecu | 7 +++- raspberry/funciones | 82 ++++++++++++++++++++++++++++++++++++------ raspberry/registrador | 7 ++-- 3 files changed, 82 insertions(+), 14 deletions(-) diff --git a/raspberry/bin/nodemecu b/raspberry/bin/nodemecu index 623509a..673e093 100755 --- a/raspberry/bin/nodemecu +++ b/raspberry/bin/nodemecu @@ -56,10 +56,14 @@ case $com in funcion_configurar $@ ;; captura) + + test_conf_nombre || exit + test_conf_intervalo || exit + test_conf_key || exit funcion_captura $2 ;; monitor) - $install_dir/monitor.sh + funcion_monitor ;; cllave) if [ -z $nombre ]; then @@ -70,6 +74,7 @@ case $com in fi ;; + *) exit ;; diff --git a/raspberry/funciones b/raspberry/funciones index 0d21131..26b47c0 100644 --- a/raspberry/funciones +++ b/raspberry/funciones @@ -114,6 +114,9 @@ case $comando in if [[ $parametro -ge 1 && $parametro -le 60 ]]; then sed -i 's/intervalo=[0-9]*/intervalo='$parametro'/' $config echo "Intervalo seteado en $parametro" + echo "Para aplicar los cambios ejecute + sudo nodemecu captura dentener + sudo nodemecu captura iniciar" break else echo "Establezca un valor entre 1 y 60." @@ -139,16 +142,8 @@ esac funcion_captura() { - if [ "$1" = "iniciar" ]; then - if [ -z $intervalo ]; then - echo "Asegurese de haber establecido 'intervalo' de regitro y envio de datos." - exit 1 - fi - if [ -z $nombre ]; then - echo "Asegurese de haber establecido el 'nombre' de dispositivo." - exit 1 - fi + if [ "$1" = "iniciar" ]; then echo "Iniciando la captura de datos en modo '$modo'" echo "" @@ -170,6 +165,41 @@ funcion_captura() { } +### Validaciones + +test_conf_nombre() { + + if [ -z $nombre ]; then + echo "No se establecio un nombre para el dispositivo." + return 1 + fi +} + + +test_conf_servidor () { + + if [ -z $servidor ];then + echo "No se establecio un servidor de entrega." + return 1 + fi +} + +test_conf_intervalo() { + + if [ -z $intervalo ];then + echo "No se establecio un intervalo de captura." + return 1 + fi +} + +test_conf_key() { + + if [ ! -f $private_key ];then + echo "No se creo juego de llaves." + return 1 + fi +} + @@ -191,8 +221,8 @@ funcion_verificar_internet() { } funcion_espera() { - - sleep ${intervalo:-1}m + sleep 1m + #sleep ${intervalo:-1}m } @@ -207,4 +237,34 @@ funcion_envio_registro() { } +funcion_monitor() { + local sb="\x1b[" + local eb="\x1b[K\x1b[0m" + local st="\e[" + local et="\e[0m" + + while :;do + clear + echo -e "${sb}1;44;97m Nodemecu Monitor${eb}" + echo "" + echo -e "${st}1;94mNombre:${et} $nombre ${st}1;94mServidor:${et} $servidor ${st}1;94mIntervalo:${et} $intervalo" + echo "" + echo -e "${sb}1;44;97m Registros${eb}" + echo "" + echo -e "En cola: $(ls -I *.sig $registros| wc -l)" + echo -e "Enviados: $(ls -I *.sig $historicos | wc -l)" + echo -e "Registros corrupts: $(ls -I *.sig $registros_corruptos | wc -l)" + echo "" + echo -e "${sb}1;44;97m Ultimos mensajes${eb}" + echo "" + echo -e ${st}1m"Systemd unit 'nodemecu.service'${et}" + journalctl -n 3 -u nodemecu + echo "" + echo -e ${st}1m"Fichero '$log'${et}" + cat /var/log/nodemecu_errors.log | grep -v "Salida de curl" | grep -v '[*<>{}]' | tail -3 + + sleep 2 + done + +} diff --git a/raspberry/registrador b/raspberry/registrador index c15dc0a..bddc9f3 100755 --- a/raspberry/registrador +++ b/raspberry/registrador @@ -17,7 +17,8 @@ while :;do # si no hay internet reinica el bucle if ! funcion_verificar_internet; then - echo "Parece no haber internet." + err_time=$(date +%Y-%m-%d-%H:%M:%S) + echo "$err_time - Parece no haber internet." | tee -a $log funcion_espera continue fi @@ -48,10 +49,10 @@ while :;do echo -e "$respuesta_servidor: \e[92mOK\e[0m" mv $registros/$file $registros/$file.sig $historicos else - echo -e "$uuid_registro: \e[91mFAIL\e[0m" err_time=$(date +%Y-%m-%d-%H:%M:%S) srv_msg="$(echo $respuesta_servidor | grep -o '.*')" + echo -e "$err_time - $uuid_registro: \e[91mFAIL\e[0m" echo "$err_time - $uuid_registro - Error del servidor: $error_servidor" >> $log echo "$err_time - $uuid_registro - Mensaje del servidor:" >> $log @@ -62,8 +63,10 @@ while :;do fi rm $curl_err + #funcion_espera fi + #exit done