summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 71ce143)
raw | patch | inline | side by side (parent: 71ce143)
author | Harper Mann <harpermann@users.sourceforge.net> | |
Fri, 16 Dec 2005 18:41:45 +0000 (18:41 +0000) | ||
committer | Harper Mann <harpermann@users.sourceforge.net> | |
Fri, 16 Dec 2005 18:41:45 +0000 (18:41 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1300 f882894a-f735-0410-b71e-b25c423dba1c
contrib/check_log2.pl | patch | blob | history |
diff --git a/contrib/check_log2.pl b/contrib/check_log2.pl
index befbf98d1fd05eeb7d0e480751e2f1a728531b25..61a11708fd5035d96af3b29c5ff8555a793ac8d0 100644 (file)
--- a/contrib/check_log2.pl
+++ b/contrib/check_log2.pl
-#!/usr/bin/perl
+#!/usr/bin/perl -w
+#
+# $Id$
#
# Log file regular expression detector for Nagios.
# Written by Aaron Bostick (abostick@mydoconline.com)
use lib $main::prog_dir;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
use Getopt::Long;
+my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
sub print_usage ();
sub print_version ();
# Initialize strings
$log_file = '';
$seek_file = '';
+ $critical = '';
$re_pattern = '';
$neg_re_pattern = '';
$pattern_count = 0;
GetOptions
("l|logfile=s" => \$log_file,
"s|seekfile=s" => \$seek_file,
+ "c|critical" => \$critical,
"p|pattern=s" => \$re_pattern,
"n|negpattern:s" => \$neg_re_pattern,
"v|version" => \$version,
($re_pattern) || usage("Regular expression not specified.\n");
# Open log file
- open LOG_FILE, $log_file || die "Unable to open log file $log_file: $!";
+ open (LOG_FILE, $log_file) || die "Unable to open log file $log_file: $!";
# Try to open log seek file. If open fails, we seek from beginning of
# file by default.
# If file is empty, no need to seek...
if ($seek_pos[0] != 0) {
- # Compare seek position to actual file size. If file size is smaller
+ # Compare seek position to actual file size.
+ # If file size is smaller
# then we just start from beginning i.e. file was rotated, etc.
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat(LOG_FILE);
# Print result and return exit code.
if ($pattern_count) {
+ if ($critical) {
+ print "CRITICAL: ";
+ } else {
+ print "WARNING: ";
+ }
print "($pattern_count): $pattern_line";
- exit $ERRORS{'WARNING'};
+ if ($critical) {
+ exit $ERRORS{'CRITICAL'};
+ } else {
+ exit $ERRORS{'WARNING'};
+ }
} else {
print "OK - No matches found.\n";
exit $ERRORS{'OK'};
#
sub print_usage () {
- print "Usage: $prog_name -l <log_file> -s <log_seek_file> -p <pattern> [-n <negpattern>]\n";
+ print "Usage: $prog_name -l <log_file> -s <log_seek_file> -p <pattern> [-n <negpattern>] -c | --critical\n";
print "Usage: $prog_name [ -v | --version ]\n";
print "Usage: $prog_name [ -h | --help ]\n";
}
print " The regular expression to scan for in the log file\n";
print "-n, --negpattern=<negpattern>\n";
print " The regular expression to skip in the log file\n";
+ print "-c, --critical\n";
+ print " Return critical instead of warning on error\n";
print "\n";
support();
exit $ERRORS{'OK'};