diff options
-rw-r--r-- | contrib/check_log2.pl | 185 | ||||
-rw-r--r-- | contrib/check_vcs.pl | 165 |
2 files changed, 350 insertions, 0 deletions
diff --git a/contrib/check_log2.pl b/contrib/check_log2.pl new file mode 100644 index 0000000..befbf98 --- /dev/null +++ b/contrib/check_log2.pl | |||
@@ -0,0 +1,185 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # Log file regular expression detector for Nagios. | ||
4 | # Written by Aaron Bostick (abostick@mydoconline.com) | ||
5 | # Last modified: 05-02-2002 | ||
6 | # | ||
7 | # Thanks and acknowledgements to Ethan Galstad for Nagios and the check_log | ||
8 | # plugin this is modeled after. | ||
9 | # | ||
10 | # Usage: check_log2 -l <log_file> -s <seek_file> -p <pattern> [-n <negpattern>] | ||
11 | # | ||
12 | # Description: | ||
13 | # | ||
14 | # This plugin will scan arbitrary text files looking for regular expression | ||
15 | # matches. The text file to scan is specified with <log_file>. | ||
16 | # <log_seek_file> is a temporary file used to store the seek byte position | ||
17 | # of the last scan. This file will be created automatically on the first | ||
18 | # scan. <pattern> can be any RE pattern that perl's s/// syntax accepte. Be | ||
19 | # forewarned that a bad pattern will send this script into never never land! | ||
20 | # | ||
21 | # Output: | ||
22 | # | ||
23 | # This plugin returns OK when a file is successfully scanned and no pattern | ||
24 | # matches are found. WARNING is returned when 1 or more patterns are found | ||
25 | # along with the pattern count and the line of the last pattern matched. | ||
26 | # CRITICAL is returned when an error occurs, such as file not found, etc. | ||
27 | # | ||
28 | # Notes (paraphrased from check_log's notes): | ||
29 | # | ||
30 | # 1. The "max_attempts" value for the service should be 1, as this | ||
31 | # will prevent Nagios from retrying the service check (the | ||
32 | # next time the check is run it will not produce the same results). | ||
33 | # | ||
34 | # 2. The "notify_recovery" value for the service should be 0, so that | ||
35 | # Nagios does not notify you of "recoveries" for the check. Since | ||
36 | # pattern matches in the log file will only be reported once and not | ||
37 | # the next time, there will always be "recoveries" for the service, even | ||
38 | # though recoveries really don't apply to this type of check. | ||
39 | # | ||
40 | # 3. You *must* supply a different <log_Seek_file> for each service that | ||
41 | # you define to use this plugin script - even if the different services | ||
42 | # check the same <log_file> for pattern matches. This is necessary | ||
43 | # because of the way the script operates. | ||
44 | # | ||
45 | # Examples: | ||
46 | # | ||
47 | # Check for error notices in messages | ||
48 | # check_log2 -l /var/log/messages -s ./check_log2.messages.seek -p 'err' | ||
49 | # | ||
50 | |||
51 | |||
52 | BEGIN { | ||
53 | if ($0 =~ s/^(.*?)[\/\\]([^\/\\]+)$//) { | ||
54 | $prog_dir = $1; | ||
55 | $prog_name = $2; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | require 5.004; | ||
60 | |||
61 | use lib $main::prog_dir; | ||
62 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
63 | use Getopt::Long; | ||
64 | |||
65 | sub print_usage (); | ||
66 | sub print_version (); | ||
67 | sub print_help (); | ||
68 | |||
69 | # Initialize strings | ||
70 | $log_file = ''; | ||
71 | $seek_file = ''; | ||
72 | $re_pattern = ''; | ||
73 | $neg_re_pattern = ''; | ||
74 | $pattern_count = 0; | ||
75 | $pattern_line = ''; | ||
76 | $plugin_revision = '$Revision$ '; | ||
77 | |||
78 | # Grab options from command line | ||
79 | GetOptions | ||
80 | ("l|logfile=s" => \$log_file, | ||
81 | "s|seekfile=s" => \$seek_file, | ||
82 | "p|pattern=s" => \$re_pattern, | ||
83 | "n|negpattern:s" => \$neg_re_pattern, | ||
84 | "v|version" => \$version, | ||
85 | "h|help" => \$help); | ||
86 | |||
87 | !($version) || print_version (); | ||
88 | !($help) || print_help (); | ||
89 | |||
90 | # Make sure log file is specified | ||
91 | ($log_file) || usage("Log file not specified.\n"); | ||
92 | # Make sure seek file is specified | ||
93 | ($seek_file) || usage("Seek file not specified.\n"); | ||
94 | # Make sure re pattern is specified | ||
95 | ($re_pattern) || usage("Regular expression not specified.\n"); | ||
96 | |||
97 | # Open log file | ||
98 | open LOG_FILE, $log_file || die "Unable to open log file $log_file: $!"; | ||
99 | |||
100 | # Try to open log seek file. If open fails, we seek from beginning of | ||
101 | # file by default. | ||
102 | if (open(SEEK_FILE, $seek_file)) { | ||
103 | chomp(@seek_pos = <SEEK_FILE>); | ||
104 | close(SEEK_FILE); | ||
105 | |||
106 | # If file is empty, no need to seek... | ||
107 | if ($seek_pos[0] != 0) { | ||
108 | |||
109 | # Compare seek position to actual file size. If file size is smaller | ||
110 | # 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); | ||
112 | |||
113 | if ($seek_pos[0] <= $size) { | ||
114 | seek(LOG_FILE, $seek_pos[0], 0); | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | |||
119 | # Loop through every line of log file and check for pattern matches. | ||
120 | # Count the number of pattern matches and remember the full line of | ||
121 | # the most recent match. | ||
122 | while (<LOG_FILE>) { | ||
123 | if ($neg_re_pattern) { | ||
124 | if ((/$re_pattern/) && !(/$neg_re_pattern/)) { | ||
125 | $pattern_count += 1; | ||
126 | $pattern_line = $_; | ||
127 | } | ||
128 | } elsif (/$re_pattern/) { | ||
129 | $pattern_count += 1; | ||
130 | $pattern_line = $_; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | # Overwrite log seek file and print the byte position we have seeked to. | ||
135 | open(SEEK_FILE, "> $seek_file") || die "Unable to open seek count file $seek_file: $!"; | ||
136 | print SEEK_FILE tell(LOG_FILE); | ||
137 | |||
138 | # Close seek file. | ||
139 | close(SEEK_FILE); | ||
140 | # Close the log file. | ||
141 | close(LOG_FILE); | ||
142 | |||
143 | # Print result and return exit code. | ||
144 | if ($pattern_count) { | ||
145 | print "($pattern_count): $pattern_line"; | ||
146 | exit $ERRORS{'WARNING'}; | ||
147 | } else { | ||
148 | print "OK - No matches found.\n"; | ||
149 | exit $ERRORS{'OK'}; | ||
150 | } | ||
151 | |||
152 | # | ||
153 | # Subroutines | ||
154 | # | ||
155 | |||
156 | sub print_usage () { | ||
157 | print "Usage: $prog_name -l <log_file> -s <log_seek_file> -p <pattern> [-n <negpattern>]\n"; | ||
158 | print "Usage: $prog_name [ -v | --version ]\n"; | ||
159 | print "Usage: $prog_name [ -h | --help ]\n"; | ||
160 | } | ||
161 | |||
162 | sub print_version () { | ||
163 | print_revision($prog_name, $plugin_revision); | ||
164 | exit $ERRORS{'OK'}; | ||
165 | } | ||
166 | |||
167 | sub print_help () { | ||
168 | print_revision($prog_name, $plugin_revision); | ||
169 | print "\n"; | ||
170 | print "Scan arbitrary log files for regular expression matches.\n"; | ||
171 | print "\n"; | ||
172 | print_usage(); | ||
173 | print "\n"; | ||
174 | print "-l, --logfile=<logfile>\n"; | ||
175 | print " The log file to be scanned\n"; | ||
176 | print "-s, --seekfile=<seekfile>\n"; | ||
177 | print " The temporary file to store the seek position of the last scan\n"; | ||
178 | print "-p, --pattern=<pattern>\n"; | ||
179 | print " The regular expression to scan for in the log file\n"; | ||
180 | print "-n, --negpattern=<negpattern>\n"; | ||
181 | print " The regular expression to skip in the log file\n"; | ||
182 | print "\n"; | ||
183 | support(); | ||
184 | exit $ERRORS{'OK'}; | ||
185 | } | ||
diff --git a/contrib/check_vcs.pl b/contrib/check_vcs.pl new file mode 100644 index 0000000..7ee0072 --- /dev/null +++ b/contrib/check_vcs.pl | |||
@@ -0,0 +1,165 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # Veritas Cluster System monitor for Nagios. | ||
4 | # Written by Aaron Bostick (abostick@mydoconline.com) | ||
5 | # Last modified: 05-22-2002 | ||
6 | # | ||
7 | # Usage: check_vcs {-g <vcs_group> | -r <vcs_resource> } -s <vcs_system> [-n] | ||
8 | # | ||
9 | # Description: | ||
10 | # | ||
11 | # This plugin is just a perl wrapper to the vcs commands hagrp and hares. | ||
12 | # You specify what group/resource and system you want the status for, and | ||
13 | # the plugin returns a status code based on the output of either hagrp or | ||
14 | # hares. | ||
15 | # | ||
16 | # Normal hagrp/hares status codes are ONLINE and OFFLINE depending on where the | ||
17 | # cluster service currently lives. I have added an option, -n, which makes | ||
18 | # the expected state to be OFFLINE rather than ONLINE so you can run the | ||
19 | # plugin on both sides of the cluster and will receive critical alerts when | ||
20 | # the cluster fails over i.e. a proper failover will make the standby node | ||
21 | # go from OFFLINE to ONLINE for the group, so an ONLINE status should alert | ||
22 | # you! (You do want to know when the cluster fails over, right? :)) | ||
23 | # | ||
24 | # Output: | ||
25 | # | ||
26 | # This plugin returns OK when hagrp/hares -state <grp> -sys <system> returns | ||
27 | # ONLINE (or OFFLINE if -n is specified). Any other hagrp/hares string returns | ||
28 | # CRITICAL... Would a WARNING ever be justified??? UNKNOWN is returned if | ||
29 | # hagrp/hares cannot run for some reason. | ||
30 | # | ||
31 | # Examples: | ||
32 | # | ||
33 | # Make sure group oracle is ONLINE on server dbserver1: | ||
34 | # check_vcs -g oracle -s dbserver1 | ||
35 | # | ||
36 | # Make sure group oracle is OFFLINE on server dbserver2: | ||
37 | # check_vcs -g oracle -s dbserver2 -n | ||
38 | # | ||
39 | # Make sure resource oraip is ONLINE on server dbserver1: | ||
40 | # check_vcs -r oraip -s dbserver1 | ||
41 | # | ||
42 | # Make sure resource oraip is OFFLINE on server dbserver2: | ||
43 | # check_vcs -r oraip -s dbserver2 -n | ||
44 | # | ||
45 | |||
46 | |||
47 | BEGIN { | ||
48 | if ($0 =~ s/^(.*?)[\/\\]([^\/\\]+)$//) { | ||
49 | $prog_dir = $1; | ||
50 | $prog_name = $2; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | require 5.004; | ||
55 | |||
56 | use lib $main::prog_dir; | ||
57 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | ||
58 | use Getopt::Long; | ||
59 | |||
60 | sub print_usage (); | ||
61 | sub print_version (); | ||
62 | sub print_help (); | ||
63 | |||
64 | # Initialize strings | ||
65 | $vcs_bin = '/opt/VRTSvcs/bin'; | ||
66 | $vcs_command = ''; | ||
67 | $vcs_arg = ''; | ||
68 | $vcs_group = ''; | ||
69 | $vcs_resource = ''; | ||
70 | $vcs_system = ''; | ||
71 | $vcs_negate = ''; | ||
72 | $vcs_result = ''; | ||
73 | $vcs_expected_result = 'ONLINE'; | ||
74 | $plugin_revision = '$Revision$ '; | ||
75 | |||
76 | # Grab options from command line | ||
77 | GetOptions | ||
78 | ("g|group:s" => \$vcs_group, | ||
79 | "r|resouce:s" => \$vcs_resource, | ||
80 | "s|system=s" => \$vcs_system, | ||
81 | "n|negate" => \$vcs_negate, | ||
82 | "v|version" => \$version, | ||
83 | "h|help" => \$help); | ||
84 | |||
85 | (!$version) || print_version (); | ||
86 | (!$help) || print_help (); | ||
87 | (!$vcs_negate) || ($vcs_expected_result = 'OFFLINE'); | ||
88 | |||
89 | # Make sure group and resource is not specified | ||
90 | !($vcs_group && $vcs_resource) || usage("Please specify either a group or a resource, but not both.\n"); | ||
91 | # Make sure group or resource is specified | ||
92 | ($vcs_group || $vcs_resource) || usage("HA group or resource not specified.\n"); | ||
93 | # Make sure system is specified | ||
94 | ($vcs_system) || usage("HA system not specified.\n"); | ||
95 | |||
96 | # Specify proper command | ||
97 | if ($vcs_group) { | ||
98 | $vcs_command = 'hagrp'; | ||
99 | $vcs_arg = $vcs_group; | ||
100 | } else { | ||
101 | $vcs_command = 'hares'; | ||
102 | $vcs_arg = $vcs_resource; | ||
103 | } | ||
104 | |||
105 | # Run command and save output | ||
106 | $vcs_result = `$vcs_bin/$vcs_command -state $vcs_arg -sys $vcs_system`; | ||
107 | chomp ($vcs_result); | ||
108 | |||
109 | # If empty result, return UNKNOWN | ||
110 | if (!$vcs_result) { | ||
111 | print "UNKNOWN: Problem running $vcs_command...\n"; | ||
112 | exit $ERRORS{'UNKNOWN'}; | ||
113 | } | ||
114 | |||
115 | # If result is expected, return OK | ||
116 | # If result is not expected, return CRITICAL | ||
117 | if ($vcs_result eq $vcs_expected_result) { | ||
118 | print "OK: $vcs_command $vcs_arg is $vcs_result\n"; | ||
119 | exit $ERRORS{'OK'}; | ||
120 | } else { | ||
121 | print "CRITICAL: $vcs_command $vcs_arg is $vcs_result\n"; | ||
122 | exit $ERRORS{'CRITICAL'}; | ||
123 | } | ||
124 | |||
125 | |||
126 | # | ||
127 | # Subroutines | ||
128 | # | ||
129 | |||
130 | sub usage () { | ||
131 | print @_; | ||
132 | print_usage(); | ||
133 | exit $ERRORS{'OK'}; | ||
134 | } | ||
135 | |||
136 | sub print_usage () { | ||
137 | print "\nUsage: $prog_name { -g <vcs_group> | -r <vcs_resource> } -s <vcs_system> [-n]\n"; | ||
138 | print "Usage: $prog_name [ -v | --version ]\n"; | ||
139 | print "Usage: $prog_name [ -h | --help ]\n"; | ||
140 | } | ||
141 | |||
142 | sub print_version () { | ||
143 | print_revision($prog_name, $plugin_revision); | ||
144 | exit $ERRORS{'OK'}; | ||
145 | } | ||
146 | |||
147 | sub print_help () { | ||
148 | print_revision($prog_name, $plugin_revision); | ||
149 | print "\n"; | ||
150 | print "Validate output from hagrp/hares command.\n"; | ||
151 | print "\n"; | ||
152 | print_usage(); | ||
153 | print "\n"; | ||
154 | print "-g, --group=<vcs_group>\n"; | ||
155 | print " The HA group to be validated\n"; | ||
156 | print "-r, --resource=<vcs_resource>\n"; | ||
157 | print " The HA resource to be validated\n"; | ||
158 | print "-s, --system=<vcs_system>\n"; | ||
159 | print " The HA system where the group/resource lives\n"; | ||
160 | print "-n, --negate=<negate>\n"; | ||
161 | print " Set expected result to OFFLINE instead of ONLINE\n"; | ||
162 | print "\n"; | ||
163 | support(); | ||
164 | exit $ERRORS{'OK'}; | ||
165 | } | ||