summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_log.sh
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-09-14 02:13:48 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-09-14 02:13:48 (GMT)
commit4907426318fc394c3d11ba71a0694a0732cf8bf0 (patch)
tree610ad1077e3d46aa005f2f2be530f172d30c3f09 /plugins-scripts/check_log.sh
parent2f496448dddd65ca1e1f6464fd63129ca0982477 (diff)
downloadmonitoring-plugins-4907426318fc394c3d11ba71a0694a0732cf8bf0.tar.gz
patch from Matthew Peters <mattp@esec.com.au>, plus turned up a few bugs on my own
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@96 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-xplugins-scripts/check_log.sh168
1 files changed, 84 insertions, 84 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 08e7fef..0f22156 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -74,27 +74,27 @@ REVISION=`echo '$Revision$' | /bin/sed -e 's/[^0-9.]//g'`
74. $PROGPATH/utils.sh 74. $PROGPATH/utils.sh
75 75
76print_usage() { 76print_usage() {
77 echo "Usage: $PROGNAME -F logfile -O oldlog -q query" 77 echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
78 echo "Usage: $PROGNAME --help" 78 echo "Usage: $PROGNAME --help"
79 echo "Usage: $PROGNAME --version" 79 echo "Usage: $PROGNAME --version"
80} 80}
81 81
82print_help() { 82print_help() {
83 print_revision $PROGNAME $REVISION 83 print_revision $PROGNAME $REVISION
84 echo "" 84 echo ""
85 print_usage 85 print_usage
86 echo "" 86 echo ""
87 echo "Log file pattern detector plugin for Nagios" 87 echo "Log file pattern detector plugin for Nagios"
88 echo "" 88 echo ""
89 support 89 support
90} 90}
91 91
92# Make sure the correct number of command line 92# Make sure the correct number of command line
93# arguments have been supplied 93# arguments have been supplied
94 94
95if [ $# -lt 1 ]; then 95if [ $# -lt 1 ]; then
96 print_usage 96 print_usage
97 exit $STATE_UNKNOWN 97 exit $STATE_UNKNOWN
98fi 98fi
99 99
100# Grab the command line arguments 100# Grab the command line arguments
@@ -104,69 +104,69 @@ fi
104#query=$3 104#query=$3
105exitstatus=$STATE_WARNING #default 105exitstatus=$STATE_WARNING #default
106while test -n "$1"; do 106while test -n "$1"; do
107 case "$1" in 107 case "$1" in
108 --help) 108 --help)
109 print_help 109 print_help
110 exit $STATE_OK 110 exit $STATE_OK
111 ;; 111 ;;
112 -h) 112 -h)
113 print_help 113 print_help
114 exit $STATE_OK 114 exit $STATE_OK
115 ;; 115 ;;
116 --version) 116 --version)
117 print_revision $PROGNAME $VERSION 117 print_revision $PROGNAME $VERSION
118 exit $STATE_OK 118 exit $STATE_OK
119 ;; 119 ;;
120 -V) 120 -V)
121 print_revision $PROGNAME $VERSION 121 print_revision $PROGNAME $VERSION
122 exit $STATE_OK 122 exit $STATE_OK
123 ;; 123 ;;
124 --filename) 124 --filename)
125 logfile=$2 125 logfile=$2
126 shift 126 shift
127 ;; 127 ;;
128 -F) 128 -F)
129 logfile=$2 129 logfile=$2
130 shift 130 shift
131 ;; 131 ;;
132 --oldlog) 132 --oldlog)
133 oldlog=$2 133 oldlog=$2
134 shift 134 shift
135 ;; 135 ;;
136 -O) 136 -O)
137 oldlog=$2 137 oldlog=$2
138 shift 138 shift
139 ;; 139 ;;
140 --query) 140 --query)
141 query=$2 141 query=$2
142 shift 142 shift
143 ;; 143 ;;
144 -q) 144 -q)
145 query=$2 145 query=$2
146 shift 146 shift
147 ;; 147 ;;
148 -x) 148 -x)
149 exitstatus=$2 149 exitstatus=$2
150 shift 150 shift
151 ;; 151 ;;
152 --exitstatus) 152 --exitstatus)
153 exitstatus=$2 153 exitstatus=$2
154 shift 154 shift
155 ;; 155 ;;
156 *) 156 *)
157 echo "Unknown argument: $1" 157 echo "Unknown argument: $1"
158 print_usage 158 print_usage
159 exit $STATE_UNKNOWN 159 exit $STATE_UNKNOWN
160 ;; 160 ;;
161 esac 161 esac
162 shift 162 shift
163done 163done
164 164
165# If the source log file doesn't exist, exit 165# If the source log file doesn't exist, exit
166 166
167if [ ! -e $logfile ]; then 167if [ ! -e $logfile ]; then
168 $ECHO "Log check error: Log file $logfile does not exist!\n" 168 $ECHO "Log check error: Log file $logfile does not exist!\n"
169 exit 2 169 exit $STATE_UNKNOWN
170fi 170fi
171 171
172# If the old log file doesn't exist, this must be the first time 172# If the old log file doesn't exist, this must be the first time
@@ -174,21 +174,22 @@ fi
174# the old diff file and exit 174# the old diff file and exit
175 175
176if [ ! -e $oldlog ]; then 176if [ ! -e $oldlog ]; then
177 $CAT $logfile > $oldlog 177 $CAT $logfile > $oldlog
178 $ECHO "Log check data initialized...\n" 178 $ECHO "Log check data initialized...\n"
179 exit 0 179 exit $STATE_OK
180fi 180fi
181 181
182# The old log file exists, so compare it to the original log now 182# The old log file exists, so compare it to the original log now
183 183
184# The temporary file that the script should use while 184# The temporary file that the script should use while
185# processing the log file. 185# processing the log file.
186if [-x /bin/mktemp]; then 186if [ -x /bin/mktemp ]; then
187 tempdiff="/bin/mktemp /tmp/check_log.XXXXXXXXXX" 187 tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX`
188else 188else
189 tempdiff="/tmp/check_log.`/bin/date '+%H%M%S'`" 189 tempdiff=`/bin/date '+%H%M%S'`
190 /bin/touch $tempdiff 190 tempdiff="/tmp/check_log.${tempdiff}"
191 chmod 600 $tempdiff 191 /bin/touch $tempdiff
192 chmod 600 $tempdiff
192fi 193fi
193 194
194$DIFF $logfile $oldlog > $tempdiff 195$DIFF $logfile $oldlog > $tempdiff
@@ -203,12 +204,11 @@ $RM -f $tempdiff
203$CAT $logfile > $oldlog 204$CAT $logfile > $oldlog
204 205
205if [ "$count" = "0" ]; then # no matches, exit with no error 206if [ "$count" = "0" ]; then # no matches, exit with no error
206 $ECHO "Log check ok - 0 pattern matches found\n" 207 $ECHO "Log check ok - 0 pattern matches found\n"
207 exitstatus=0 208 exitstatus=$STATE_OK
208else # Print total matche count and the last entry we found 209else # Print total matche count and the last entry we found
209 $ECHO "($count) $lastentry" 210 $ECHO "($count) $lastentry"
211 exitstatus=$STATE_CRITICAL
210fi 212fi
211 213
212exit exitstatus 214exit $exitstatus
213
214