aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/check_log.sh
diff options
context:
space:
mode:
authorGravatar rincewind <rincewind@vulgrim.de> 2021-07-02 18:38:12 +0200
committerGravatar rincewind <rincewind@vulgrim.de> 2021-07-02 18:38:12 +0200
commit53b77dee91f780b4d78839f881c642189b829e3c (patch)
tree6ea73d3ef108051a6840fa9841b4bbbac62b37e6 /plugins-scripts/check_log.sh
parentc2aa1a5fa2dd96c7186704901d33721a63b9cd03 (diff)
downloadmonitoring-plugins-53b77dee91f780b4d78839f881c642189b829e3c.tar.gz
Add -a option to print all matching lines and -p and -e options for perl and extended RE
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-xplugins-scripts/check_log.sh51
1 files changed, 37 insertions, 14 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 6e9fbca5..8af07b5e 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -69,6 +69,11 @@ 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() {
@@ -115,35 +120,35 @@ while test -n "$1"; do
;;
--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
+ shift 2
;;
--extended-regex)
ERE=1
@@ -161,13 +166,20 @@ while test -n "$1"; do
PRE=1
shift
;;
+ --all)
+ ALL=1
+ shift
+ ;;
+ -a)
+ ALL=1
+ shift
+ ;;
*)
echo "Unknown argument: $1"
print_usage
exit "$STATE_UNKNOWN"
;;
esac
- shift
done
# Parameter sanity check
@@ -176,6 +188,8 @@ if [ $ERE ] && [ $PRE ] ; then
exit "$STATE_UNKNOWN"
fi
+GREP="grep"
+
if [ $ERE ]; then
GREP="grep -E"
fi
@@ -219,11 +233,20 @@ fi
diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
-# Count the number of matching log entries we have
-count=$($GREP -c "$query" "$tempdiff")
+if [ $ALL ]; then
+ # Get the last matching entry in the diff file
+ entry=$($GREP "$query" "$tempdiff")
-# Get the last matching entry in the diff file
-lastentry=$($GREP "$query" "$tempdiff" | tail -1)
+ # 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"
@@ -232,7 +255,7 @@ 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"
+ echo "($count) $entry"
exitstatus=$STATE_CRITICAL
fi