summaryrefslogtreecommitdiff
path: root/tests/check_bigcouch_errors.sh
blob: d14ab922e677099a4fe518c74c69a7d6655f5398 (plain)
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
#!/bin/bash


WARN=10
CRIT=20
STATUS[0]='OK'
STATUS[1]='Warning'
STATUS[2]='Critical'
CHECKNAME='Bigcouch_Log'

LOG='/opt/bigcouch/var/log/bigcouch.log'

# for debugging: zgrep through old logs
#LOG=/opt/bigcouch/var/log/bigcouch.log.1.gz
#errors=`zcat $LOG | grep 'error' | sed 's/\[.*\] //' | sort`

errors=`grep 'error' $LOG | sed 's/\[.*\] //' | sort `
errors_uniq=`echo -e "$errors" | uniq`

total=`echo -e "$errors" | grep -v '^$' | wc -l`

if [ $total -lt $WARN ]
then
  exitcode=0
else
  if [ $total -le $CRIT ]
  then
    exitcode=1
  else
      exitcode=2
  fi
fi

echo -n "$exitcode $CHECKNAME errors=$total ${STATUS[exitcode]}: $total errors in total in $LOG."

if [ ! $total -eq 0 ]
then

  echo -e "$errors_uniq" | while read -r line
  do 
    count=`echo -e "$errors" | grep "$line" | wc -l`
    echo -n " $count occurrences of \"$line\"."
  done
fi

echo

exit $exitcode