Commit 8ec449c2 by Luciano Barletta

First commit

0 parents
ID=$1
DATA=$(curl -d "id=$ID" -H "application/x-www-form-urlencoded" 192.168.15.75:5000/cons)
echo $DATA
\ No newline at end of file
#!/bin/bash
HOST=$(hostname)
PHONE="5493415959169"
NOW=$(date "+%D %T")
NOW_EPOCH=$(date -d "$NOW" +"%s")
LOG_FILE="/dev/shm/info_colmena"
ENDL="
"
BASE="*$HOST*:$ENDL$ENDL"
# Inicializacion
if [ ! -e $LOG_FILE ]
then
touch $LOG_FILE
fi
### Carga de CPU ###
MSG=$BASE
# Cantidad maxima de carga
RESULT=$(cat /proc/cpuinfo | grep processor | tail -n1 | cut -c13)
MAX=$(echo $(( ($RESULT + 1) * 100 )) )
# Cantidad actual de carga
RESULT=$(cat /proc/loadavg | cut -c6-9 | tr -d .)
RESULT=$(expr $RESULT + 0)
PERC=$(echo $(( $RESULT * 100 / $MAX )) )
# Reinicio automatico
#if [ ! $PERC -gt 40 ]
#then
#MSG="${MSG}La carga promedio es *$PERC%*. *Reiniciando...*"
#wget "${WPPURL}${PHONE}${MSG}"
#reboot
#fi
# Carga maxima superada
LAST_REPORT=$(grep carga $LOG_FILE | tail -n1 | cut -d ">" -f1)
LAST_REPORT_EPOCH=$(date -d "$LAST_REPORT + 1 day" +"%s") # Ventana de un dia
if [ -z "$LAST_REPORT" ] || [ $NOW_EPOCH \> $LAST_REPORT_EPOCH ]
then
if [ ! $RESULT -lt $MAX ]
then
echo "${NOW} > carga" >> $LOG_FILE
MSG="${MSG}La carga promedio supera la carga maxima de *$MAX*. *Carga: $RESULT*.$ENDL"
fi
fi
### Temperatura ###
LAST_REPORT=$(grep temperatura $LOG_FILE | tail -n1 | cut -d ">" -f1)
LAST_REPORT_EPOCH=$(date -d "$LAST_REPORT + 1 day" +"%s") # Ventana de un dia
if [ -z "$LAST_REPORT" ] || [ $NOW_EPOCH \> $LAST_REPORT_EPOCH ]
then
RESULT=$(sensors | grep °C | head -n1 | cut -c16-17)
if [ ! $RESULT -lt 70 ]
then
echo "${NOW} > temperatura" >> /dev/shm/info_colmena
MSG="${MSG}La temperatura alcanza *$RESULT°C*.$ENDL"
fi
fi
### Uso del disco ###
LAST_REPORT=$(grep disco $LOG_FILE | tail -n1 | cut -d ">" -f1)
LAST_REPORT_EPOCH=$(date -d "$LAST_REPORT + 1 day" +"%s") # Ventana de un dia
if [ -z "$LAST_REPORT" ] || [ $NOW_EPOCH \> $LAST_REPORT_EPOCH ]
then
RESULT=$(df / | cut -c52-54 | grep 9.)
if [ ! -z "$RESULT" ]
then
echo "${NOW} > disco" >> /dev/shm/info_colmena
MSG="${MSG}El disco se encuentra por arriba del *90%* de uso.$ENDL"
fi
RESULT=$(df / | cut -c52-54 | grep 100)
if [ ! -z "$RESULT" ]
then
echo "${NOW} > disco" >> /dev/shm/info_colmena
MSG="${MSG}El disco se encuentra en el *100%* del uso.$ENDL"
fi
fi
### Disco roto ###
LAST_REPORT=$(grep fallo-critico $LOG_FILE | tail -n1 | cut -d ">" -f1)
LAST_REPORT_EPOCH=$(date -d "$LAST_REPORT + 1 day" +"%s") # Ventana de un dia
if [ -z "$LAST_REPORT" ] || [ $NOW_EPOCH \> $LAST_REPORT_EPOCH ]
then
RESULT=$(dmesg | grep "exception Emask" | tail -n1)
if [ ! -z "$RESULT" ]
then
echo "${NOW} > fallo-critico" >> /dev/shm/info_colmena
MSG="${MSG}*HAY UN FALLO CRITICO EN UN DISCO*.$ENDL"
fi
fi
### Uso de memoria Swap ###
LAST_REPORT=$(grep swap $LOG_FILE | tail -n1 | cut -d ">" -f1)
LAST_REPORT_EPOCH=$(date -d "$LAST_REPORT + 1 day" +"%s") # Ventana de un dia
if [ -z "$LAST_REPORT" ] || [ $NOW_EPOCH \> $LAST_REPORT_EPOCH ]
then
# Cantidad maxima de Swap
MAX=$(free | grep Swap | sed 's/\s\+/,/g' | cut -d , -f2)
# Cantidad usada de Swap
RESULT=$(free | grep Swap | sed 's/\s\+/,/g' | cut -d , -f3)
RESULT=$(echo $(($RESULT * 100 / $MAX)) )
if [ ! $RESULT -lt 50 ]
then
echo "${NOW} > swap" >> /dev/shm/info_colmena
MSG="${MSG}El swap se encuentra en *$RESULT%* de uso.$ENDL"
fi
fi
# Se pidio mandar algo?
if [[ ! "$MSG" == "$BASE" ]]
then
./send.sh wpp1 "$MSG" "$PHONE" "text"
fi
SERV=$1
MSG=$2
PHONE=$3
TYPE=$4
# receive public key if one doesn't exist
if [ ! -e server_rsa_key.pub ]
then
echo "getting new public key from server"
PUB_KEY=$(curl 192.168.15.75:5000/init)
printf "%s" "$PUB_KEY" > server_rsa_key.pub
fi
# generate random key
echo "generating random encryption key"
openssl rand -base64 32 > rand.key
# encode data with random key
echo "encoding $MSG with random key"
echo "$MSG" | openssl enc -aes-256-cbc -salt -out data.enc -pass file:./rand.key
#printf "%s" "$MSG" > data
# encrypt random key with server's pubkey
openssl rsautl -encrypt -inkey server_rsa_key.pub -pubin -in rand.key -out rand.key.enc
rm rand.key
# send data as file (with optional encripted symectric key)
curl -F "data=@data.enc" -F "key=@rand.key.enc" 192.168.15.75:5000/data
#curl -F "data=@data" 192.168.15.75:5000/data
# send the rest of the parameter to send the data
echo "calling message sending method of server"
DATA=$(curl -d "serv=$SERV" -d "dest=$PHONE" -d "type=$TYPE" 192.168.15.75:5000/msg)
echo $DATA >> msg_ids.txt
# cleanup
rm ./rand.key.enc
rm ./data.enc
# DEBUGGING
rm /dev/shm/info_colmena
rm ./server_rsa_key.pub
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!