diff options
| author | Harper Mann <harpermann@users.sourceforge.net> | 2005-12-16 18:41:45 +0000 |
|---|---|---|
| committer | Harper Mann <harpermann@users.sourceforge.net> | 2005-12-16 18:41:45 +0000 |
| commit | 268ad0af8d439a0035f59211677907ee321d4066 (patch) | |
| tree | 097b4028d867c6db76ba8f6f08c6da3ef4c14348 /contrib | |
| parent | 71ce143ab1cac10b974084a21653b71bee68fe55 (diff) | |
| download | monitoring-plugins-268ad0af8d439a0035f59211677907ee321d4066.tar.gz | |
Added ability to output critical on error. Fixed open so it properly fails if the log file open throws an error, turned on -w in the perl call, fixed warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1300 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/check_log2.pl | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/contrib/check_log2.pl b/contrib/check_log2.pl index befbf98d..61a11708 100644 --- a/contrib/check_log2.pl +++ b/contrib/check_log2.pl | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl -w |
| 2 | # | ||
| 3 | # $Id$ | ||
| 2 | # | 4 | # |
| 3 | # Log file regular expression detector for Nagios. | 5 | # Log file regular expression detector for Nagios. |
| 4 | # Written by Aaron Bostick (abostick@mydoconline.com) | 6 | # Written by Aaron Bostick (abostick@mydoconline.com) |
| @@ -61,6 +63,7 @@ require 5.004; | |||
| 61 | use lib $main::prog_dir; | 63 | use lib $main::prog_dir; |
| 62 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | 64 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); |
| 63 | use Getopt::Long; | 65 | use Getopt::Long; |
| 66 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks); | ||
| 64 | 67 | ||
| 65 | sub print_usage (); | 68 | sub print_usage (); |
| 66 | sub print_version (); | 69 | sub print_version (); |
| @@ -69,6 +72,7 @@ sub print_help (); | |||
| 69 | # Initialize strings | 72 | # Initialize strings |
| 70 | $log_file = ''; | 73 | $log_file = ''; |
| 71 | $seek_file = ''; | 74 | $seek_file = ''; |
| 75 | $critical = ''; | ||
| 72 | $re_pattern = ''; | 76 | $re_pattern = ''; |
| 73 | $neg_re_pattern = ''; | 77 | $neg_re_pattern = ''; |
| 74 | $pattern_count = 0; | 78 | $pattern_count = 0; |
| @@ -79,6 +83,7 @@ sub print_help (); | |||
| 79 | GetOptions | 83 | GetOptions |
| 80 | ("l|logfile=s" => \$log_file, | 84 | ("l|logfile=s" => \$log_file, |
| 81 | "s|seekfile=s" => \$seek_file, | 85 | "s|seekfile=s" => \$seek_file, |
| 86 | "c|critical" => \$critical, | ||
| 82 | "p|pattern=s" => \$re_pattern, | 87 | "p|pattern=s" => \$re_pattern, |
| 83 | "n|negpattern:s" => \$neg_re_pattern, | 88 | "n|negpattern:s" => \$neg_re_pattern, |
| 84 | "v|version" => \$version, | 89 | "v|version" => \$version, |
| @@ -95,7 +100,7 @@ sub print_help (); | |||
| 95 | ($re_pattern) || usage("Regular expression not specified.\n"); | 100 | ($re_pattern) || usage("Regular expression not specified.\n"); |
| 96 | 101 | ||
| 97 | # Open log file | 102 | # Open log file |
| 98 | open LOG_FILE, $log_file || die "Unable to open log file $log_file: $!"; | 103 | open (LOG_FILE, $log_file) || die "Unable to open log file $log_file: $!"; |
| 99 | 104 | ||
| 100 | # Try to open log seek file. If open fails, we seek from beginning of | 105 | # Try to open log seek file. If open fails, we seek from beginning of |
| 101 | # file by default. | 106 | # file by default. |
| @@ -106,7 +111,8 @@ sub print_help (); | |||
| 106 | # If file is empty, no need to seek... | 111 | # If file is empty, no need to seek... |
| 107 | if ($seek_pos[0] != 0) { | 112 | if ($seek_pos[0] != 0) { |
| 108 | 113 | ||
| 109 | # Compare seek position to actual file size. If file size is smaller | 114 | # Compare seek position to actual file size. |
| 115 | # If file size is smaller | ||
| 110 | # then we just start from beginning i.e. file was rotated, etc. | 116 | # then we just start from beginning i.e. file was rotated, etc. |
| 111 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat(LOG_FILE); | 117 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat(LOG_FILE); |
| 112 | 118 | ||
| @@ -142,8 +148,17 @@ sub print_help (); | |||
| 142 | 148 | ||
| 143 | # Print result and return exit code. | 149 | # Print result and return exit code. |
| 144 | if ($pattern_count) { | 150 | if ($pattern_count) { |
| 151 | if ($critical) { | ||
| 152 | print "CRITICAL: "; | ||
| 153 | } else { | ||
| 154 | print "WARNING: "; | ||
| 155 | } | ||
| 145 | print "($pattern_count): $pattern_line"; | 156 | print "($pattern_count): $pattern_line"; |
| 146 | exit $ERRORS{'WARNING'}; | 157 | if ($critical) { |
| 158 | exit $ERRORS{'CRITICAL'}; | ||
| 159 | } else { | ||
| 160 | exit $ERRORS{'WARNING'}; | ||
| 161 | } | ||
| 147 | } else { | 162 | } else { |
| 148 | print "OK - No matches found.\n"; | 163 | print "OK - No matches found.\n"; |
| 149 | exit $ERRORS{'OK'}; | 164 | exit $ERRORS{'OK'}; |
| @@ -154,7 +169,7 @@ sub print_help (); | |||
| 154 | # | 169 | # |
| 155 | 170 | ||
| 156 | sub print_usage () { | 171 | sub print_usage () { |
| 157 | print "Usage: $prog_name -l <log_file> -s <log_seek_file> -p <pattern> [-n <negpattern>]\n"; | 172 | print "Usage: $prog_name -l <log_file> -s <log_seek_file> -p <pattern> [-n <negpattern>] -c | --critical\n"; |
| 158 | print "Usage: $prog_name [ -v | --version ]\n"; | 173 | print "Usage: $prog_name [ -v | --version ]\n"; |
| 159 | print "Usage: $prog_name [ -h | --help ]\n"; | 174 | print "Usage: $prog_name [ -h | --help ]\n"; |
| 160 | } | 175 | } |
| @@ -179,6 +194,8 @@ sub print_help () { | |||
| 179 | print " The regular expression to scan for in the log file\n"; | 194 | print " The regular expression to scan for in the log file\n"; |
| 180 | print "-n, --negpattern=<negpattern>\n"; | 195 | print "-n, --negpattern=<negpattern>\n"; |
| 181 | print " The regular expression to skip in the log file\n"; | 196 | print " The regular expression to skip in the log file\n"; |
| 197 | print "-c, --critical\n"; | ||
| 198 | print " Return critical instead of warning on error\n"; | ||
| 182 | print "\n"; | 199 | print "\n"; |
| 183 | support(); | 200 | support(); |
| 184 | exit $ERRORS{'OK'}; | 201 | exit $ERRORS{'OK'}; |
