-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcheck_log_count_include
executable file
·52 lines (42 loc) · 1.39 KB
/
check_log_count_include
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
#!/bin/bash
# script to check how many key in the last hour
# Felipe Ferreira June 2012
#update Nov 2014
dia=`date +%d -d "1 hour ago"`
mes=`date +%m -d "1 hour ago"`
ano=`date +%Y -d "1 hour ago"`
hora=`date +%H -d "1 hour ago"`
tday="$ano-$mes-$dia $hora"
log="/var/log/tomcat.classificados/captacao/gerencia-anuncio-integradores.log"
if [ "$4" == "" ]
then
echo -e "\n Syntax: $0 <logfile> <key> <Warning> <Critical> \nex.: $0 '/var/log/tomcat.classificados/captacao/gerencia-anuncio-integradores.log' 'Registrando sucesso de publica' 10 90 \n O script retorana a contagem de $key quantidade de da ultima hora \n"
exit 3
fi
log=$1
key=$2
warn=$3
crit=$4
#log="/var/log/escenic/engine/ece-messages.log.2015-03-24"
if [ ! -f $log ]; then
echo "OK - File $log not found!"
exit 0
fi
log_short=`echo $log|awk -F"/" '{ print $NF}'`
#echo "DATE: $tday"
c=`grep "$tday" $log |grep -ic "${key}"`
if [ -z "$c" ]; then
c=0
fi
if [ "$c" -ge "$crit" ]; then
#get ID
ID=`grep "$tday" $log |grep "${key}" |tail -n 1|awk -F ")" '{ print $2 }' |awk -F"," '{ print $1 }' | awk '{ print $6 " " $7 " " $8 " " $9 }'`
echo "CRITICAL - Existem $c $key ref ao $ID no $log_short as $hora horas|count=$c"
exit 2
elif [ "$c" -ge "$warn" ]; then
echo "WARNING - Existem $c $key no $log_short as $hora horas|count=$c"
exit 1
else
echo "OK - Existem $c $key no $log_short as $hora horas|count=$c"
exit 0
fi