control.sh
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/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