2 # Copyright (C) 2008-2010 Equinox Software, Inc.
\r
3 # Written by Don McMorris <dmcmorris@esilibrary.com>
\r
5 # This program is free software; you can redistribute it and/or
\r
6 # modify it under the terms of the GNU General Public License
\r
7 # as published by the Free Software Foundation; either version 2
\r
8 # of the License, or (at your option) any later version.
\r
10 # This program is distributed in the hope that it will be useful,
\r
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 # GNU General Public License for more details.
\r
16 # Author : Don McMorris, Sys Admin, ESI
\r
17 # Purpose : Look for excessive NULLS in the gateway logs
\r
18 # Usage : check_null <# mins to check> <WARNLIMIT> <CRITLIMIT>
\r
24 # Note: These should really be checked to ensure they are defined and within range...
\r
27 LOGFILE="/var/log/evergreen/prod/$(date +%Y/%m/%d)/gateway.$(date +%H).log"
\r
29 if [ $(date +%H | cut -b1) = 0 ]; then
\r
30 CURRHOUR=$(date +%H | cut -b2)
\r
32 CURRHOUR=$(date +%H)
\r
35 if [ $(date +%M | cut -b1) = 0 ]; then
\r
36 CURRMIN=$(date +%M | cut -b2 )
\r
41 if [ $CURRMIN -lt $PERIOD ]; then
\r
42 # How many minutes of the last hour do we need to check?
\r
43 TMPDIFFM2=$((60 - $(($PERIOD - $CURRMIN))))
\r
45 # This logic will mean that "Returning NULL"'s logged at the late 2300 hour will not be counted during the early Midnight hour check.
\r
46 # This is acceptable for now.
\r
47 if [ $CURRHOUR -gt 0 ]; then
\r
48 # define LOGFILE2 (last hours' log)
\r
49 if [ $CURRHOUR -gt 11 ]; then
\r
50 LOGFILE2="/var/log/evergreen/prod/$(date +%Y/%m/%d)/gateway.$(($CURRHOUR - 1)).log"
\r
52 LOGFILE2="/var/log/evergreen/prod/$(date +%Y/%m/%d)/gateway.0$(($CURRHOUR - 1)).log"
\r
55 while [ $TMPDIFFM2 -lt 60 ]; do
\r
56 PREVTOT=$(($PREVTOT + $(grep "Returning NULL" $LOGFILE2 | cut -d":" -f2 | grep -c $TMPDIFFM2)))
\r
57 TMPDIFFM2=$(($TMPDIFFM2 + 1))
\r
60 while [ $TMPDIFF1 -le $CURRMIN ]; do
\r
61 PREVTOT=$(($PREVTOT + $(grep "Returning NULL" $LOGFILE | cut -d":" -f2 | grep -c $TMPDIFF1)))
\r
62 TMPDIFF1=$(($TMPDIFF1 + 1))
\r
65 TMPDIFF1=$(($CURRMIN-$PERIOD))
\r
66 while [ $TMPDIFF1 -le $CURRMIN ]; do
\r
67 PREVTOT=$(($PREVTOT + $(grep "Returning NULL" $LOGFILE | cut -d":" -f2 | grep -c $TMPDIFF1)))
\r
68 TMPDIFF1=$(($TMPDIFF1 + 1))
\r
74 TOPSERVER=$(grep "Returning NULL" $LOGFILE | cut -d" " -f3 | sort | uniq -c | sort -nr | head -1)
\r
76 if [ "$TOPSERVER" != null ]; then
\r
77 SVRMSG=" (Top server this hour: $TOPSERVER)"
\r
82 if [ $PREVTOT -ge $CRITLIMIT ]; then
\r
83 echo "CRIT: $PREVTOT NULLs returned in past $PERIOD minutes$SVRMSG"
\r
85 elif [ $PREVTOT -ge $WARNLIMIT ]; then
\r
86 echo "WARN: $PREVTOT NULLs returned in the past $PERIOD minutes$SVRMSG"
\r
88 elif [ $PREVTOT -lt $WARNLIMIT ]; then
\r
89 echo "OK: $PREVTOT NULLs returned in the past $PERIOD minutes$SVRMSG"
\r
92 echo "WARN: An error has occurred $PREVTOT $PERIOD"
\r