New upstream version 2.3.2
This commit is contained in:
parent
09f4277f49
commit
21323d25dd
104 changed files with 34386 additions and 7430 deletions
|
@ -1,8 +1,7 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Log file pattern detector plugin for monitoring
|
||||
# Written by Ethan Galstad (nagios@nagios.org)
|
||||
# Last Modified: 07-31-1999
|
||||
# Written originally by Ethan Galstad (nagios@nagios.org)
|
||||
#
|
||||
# Usage: ./check_log <log_file> <old_log_file> <pattern>
|
||||
#
|
||||
|
@ -44,6 +43,10 @@
|
|||
# check the same <log_file> for pattern matches. This is necessary
|
||||
# because of the way the script operates.
|
||||
#
|
||||
# 4. This plugin does NOT have an understanding of logrotation or similar
|
||||
# mechanisms. Therefore bad timing could lead to missing events
|
||||
#
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# Check for login failures in the syslog...
|
||||
|
@ -60,20 +63,25 @@
|
|||
|
||||
PATH="@TRUSTED_PATH@"
|
||||
export PATH
|
||||
PROGNAME=`basename $0`
|
||||
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
||||
PROGNAME=$(basename "$0")
|
||||
PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
|
||||
REVISION="@NP_VERSION@"
|
||||
|
||||
. $PROGPATH/utils.sh
|
||||
. "$PROGPATH"/utils.sh
|
||||
|
||||
print_usage() {
|
||||
echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
|
||||
echo "Usage: $PROGNAME --help"
|
||||
echo "Usage: $PROGNAME --version"
|
||||
echo ""
|
||||
echo "Other parameters:"
|
||||
echo " -a|--all : Print all matching lines"
|
||||
echo " -p|--perl-regex : Use perl style regular expressions in the query"
|
||||
echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)"
|
||||
}
|
||||
|
||||
print_help() {
|
||||
print_revision $PROGNAME $REVISION
|
||||
print_revision "$PROGNAME" "$REVISION"
|
||||
echo ""
|
||||
print_usage
|
||||
echo ""
|
||||
|
@ -87,7 +95,7 @@ print_help() {
|
|||
|
||||
if [ $# -lt 1 ]; then
|
||||
print_usage
|
||||
exit $STATE_UNKNOWN
|
||||
exit "$STATE_UNKNOWN"
|
||||
fi
|
||||
|
||||
# Grab the command line arguments
|
||||
|
@ -100,79 +108,123 @@ while test -n "$1"; do
|
|||
case "$1" in
|
||||
--help)
|
||||
print_help
|
||||
exit $STATE_OK
|
||||
exit "$STATE_OK"
|
||||
;;
|
||||
-h)
|
||||
print_help
|
||||
exit $STATE_OK
|
||||
exit "$STATE_OK"
|
||||
;;
|
||||
--version)
|
||||
print_revision $PROGNAME $REVISION
|
||||
exit $STATE_OK
|
||||
print_revision "$PROGNAME" "$REVISION"
|
||||
exit "$STATE_OK"
|
||||
;;
|
||||
-V)
|
||||
print_revision $PROGNAME $REVISION
|
||||
exit $STATE_OK
|
||||
print_revision "$PROGNAME" "$REVISION"
|
||||
exit "$STATE_OK"
|
||||
;;
|
||||
--filename)
|
||||
logfile=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
-F)
|
||||
logfile=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
--oldlog)
|
||||
oldlog=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
-O)
|
||||
oldlog=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
--query)
|
||||
query=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
-q)
|
||||
query=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
-x)
|
||||
exitstatus=$2
|
||||
shift
|
||||
shift 2
|
||||
;;
|
||||
--exitstatus)
|
||||
exitstatus=$2
|
||||
shift 2
|
||||
;;
|
||||
--extended-regex)
|
||||
ERE=1
|
||||
shift
|
||||
;;
|
||||
-e)
|
||||
ERE=1
|
||||
shift
|
||||
;;
|
||||
--perl-regex)
|
||||
PRE=1
|
||||
shift
|
||||
;;
|
||||
-p)
|
||||
PRE=1
|
||||
shift
|
||||
;;
|
||||
--all)
|
||||
ALL=1
|
||||
shift
|
||||
;;
|
||||
-a)
|
||||
ALL=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1"
|
||||
print_usage
|
||||
exit $STATE_UNKNOWN
|
||||
exit "$STATE_UNKNOWN"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Parameter sanity check
|
||||
if [ $ERE ] && [ $PRE ] ; then
|
||||
echo "Can not use extended and perl regex at the same time"
|
||||
exit "$STATE_UNKNOWN"
|
||||
fi
|
||||
|
||||
GREP="grep"
|
||||
|
||||
if [ $ERE ]; then
|
||||
GREP="grep -E"
|
||||
fi
|
||||
|
||||
if [ $PRE ]; then
|
||||
GREP="grep -P"
|
||||
fi
|
||||
|
||||
# If the source log file doesn't exist, exit
|
||||
|
||||
if [ ! -e $logfile ]; then
|
||||
if [ ! -e "$logfile" ]; then
|
||||
echo "Log check error: Log file $logfile does not exist!"
|
||||
exit $STATE_UNKNOWN
|
||||
elif [ ! -r $logfile ] ; then
|
||||
exit "$STATE_UNKNOWN"
|
||||
elif [ ! -r "$logfile" ] ; then
|
||||
echo "Log check error: Log file $logfile is not readable!"
|
||||
exit $STATE_UNKNOWN
|
||||
exit "$STATE_UNKNOWN"
|
||||
fi
|
||||
# If no oldlog was given this can not work properly, abort then
|
||||
if [ -z "$oldlog" ]; then
|
||||
echo "Oldlog parameter is needed"
|
||||
exit $STATE_UNKNOWN
|
||||
fi
|
||||
|
||||
# If the old log file doesn't exist, this must be the first time
|
||||
# we're running this test, so copy the original log file over to
|
||||
# the old diff file and exit
|
||||
|
||||
if [ ! -e $oldlog ]; then
|
||||
cat $logfile > $oldlog
|
||||
if [ ! -e "$oldlog" ]; then
|
||||
cat "$logfile" > "$oldlog"
|
||||
echo "Log check data initialized..."
|
||||
exit $STATE_OK
|
||||
exit "$STATE_OK"
|
||||
fi
|
||||
|
||||
# The old log file exists, so compare it to the original log now
|
||||
|
@ -180,31 +232,42 @@ fi
|
|||
# The temporary file that the script should use while
|
||||
# processing the log file.
|
||||
if [ -x /bin/mktemp ]; then
|
||||
tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX`
|
||||
|
||||
tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX)
|
||||
else
|
||||
tempdiff=`/bin/date '+%H%M%S'`
|
||||
tempdiff=$(/bin/date '+%H%M%S')
|
||||
tempdiff="/tmp/check_log.${tempdiff}"
|
||||
touch $tempdiff
|
||||
chmod 600 $tempdiff
|
||||
touch "$tempdiff"
|
||||
chmod 600 "$tempdiff"
|
||||
fi
|
||||
|
||||
diff $logfile $oldlog | grep -v "^>" > $tempdiff
|
||||
diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
|
||||
|
||||
# Count the number of matching log entries we have
|
||||
count=`grep -c "$query" $tempdiff`
|
||||
|
||||
# Get the last matching entry in the diff file
|
||||
lastentry=`grep "$query" $tempdiff | tail -1`
|
||||
if [ $ALL ]; then
|
||||
# Get the last matching entry in the diff file
|
||||
entry=$($GREP "$query" "$tempdiff")
|
||||
|
||||
rm -f $tempdiff
|
||||
cat $logfile > $oldlog
|
||||
# Count the number of matching log entries we have
|
||||
count=$(echo "$entry" | wc -l)
|
||||
|
||||
else
|
||||
# Count the number of matching log entries we have
|
||||
count=$($GREP -c "$query" "$tempdiff")
|
||||
|
||||
# Get the last matching entry in the diff file
|
||||
entry=$($GREP "$query" "$tempdiff" | tail -1)
|
||||
fi
|
||||
|
||||
rm -f "$tempdiff"
|
||||
cat "$logfile" > "$oldlog"
|
||||
|
||||
if [ "$count" = "0" ]; then # no matches, exit with no error
|
||||
echo "Log check ok - 0 pattern matches found"
|
||||
exitstatus=$STATE_OK
|
||||
else # Print total matche count and the last entry we found
|
||||
echo "($count) $lastentry"
|
||||
else # Print total match count and the last entry we found
|
||||
echo "($count) $entry"
|
||||
exitstatus=$STATE_CRITICAL
|
||||
fi
|
||||
|
||||
exit $exitstatus
|
||||
exit "$exitstatus"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue