summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2005-01-27 04:46:08 +0000
committerStanley Hopcroft <stanleyhopcroft@users.sourceforge.net>2005-01-27 04:46:08 +0000
commitfce1f09f770fc5bbc6d323865af709ff515c803c (patch)
tree1e997a0bc1ace6217cc0dab87b65de52bca8be20
parentccf789e017547e1f71b5945b2e1d85ce5b9cb8e4 (diff)
downloadmonitoring-plugins-fce1f09f770fc5bbc6d323865af709ff515c803c.tar.gz
New /contrib plugin
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1112 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--contrib/check_arping.pl120
-rw-r--r--contrib/check_cpqarray.c430
-rw-r--r--contrib/check_frontpage151
-rw-r--r--contrib/check_logins.c351
-rw-r--r--contrib/check_oracle_tbs206
-rw-r--r--contrib/check_pcpmetric.py106
-rw-r--r--contrib/check_pfstate75
7 files changed, 1439 insertions, 0 deletions
diff --git a/contrib/check_arping.pl b/contrib/check_arping.pl
new file mode 100644
index 00000000..b78ec68f
--- /dev/null
+++ b/contrib/check_arping.pl
@@ -0,0 +1,120 @@
1#! /usr/bin/perl -w
2#
3# check_arping.pl - Nagios plugin to check host status via ARP ping
4#
5# usage:
6# check_arping -H hostname -I interface -T timeout
7#
8#
9# Copyright (C) 2003 Kenny Root
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24#
25#
26# Report bugs to: kenny@the-b.org, nagiosplug-help@lists.sf.net
27
28use POSIX;
29use strict;
30use lib "/usr/lib/nagios/plugins" ;
31use utils qw($TIMEOUT %ERRORS &print_revision &support);
32
33use Net::Arping;
34use Getopt::Long;
35
36my $PROGNAME = "check_arping";
37
38my($status, $state, $answer);
39my($opt_V, $opt_h, $opt_t, $opt_I, $opt_H);
40
41
42#Option checking
43$status = GetOptions(
44 "V|version" => \$opt_V,
45 "help" => \$opt_h,
46 "I|interface=s" => \$opt_I,
47 "H|host=s" => \$opt_H,
48 "t|timeout=i" => \$opt_t);
49
50if ($status == 0)
51{
52 print_help() ;
53 exit $ERRORS{'OK'};
54}
55
56
57if ($opt_V) {
58 print_revision($PROGNAME,'$Revision$ ');
59 exit $ERRORS{'OK'};
60}
61
62if ($opt_h) {
63 print_help();
64 exit $ERRORS{'OK'};
65}
66
67if ($opt_t) {
68 if ($opt_t ne int($opt_t)) {
69 print "Timeout not in seconds!\n";
70 print_help();
71 exit $ERRORS{'OK'};
72 }
73 $opt_t = int($opt_t);
74} else {
75 $opt_t = 3;
76}
77
78if (! utils::is_hostname($opt_H)){
79 usage();
80 exit $ERRORS{"UNKNOWN"};
81}
82
83my $ping = Net::Arping->new();
84
85my $reply = $ping->arping(Host => $opt_H, Interface => $opt_I, Timeout => $opt_t);
86
87if ($reply eq "0") {
88 $state = "CRITICAL";
89 print "$state: no reply from $opt_H on interface $opt_I in $opt_t seconds.\n";
90 exit $ERRORS{$state};
91} else {
92 $state = "OK";
93 $answer = "replied with MAC address $reply";
94}
95
96print "ARPING $state - $answer\n";
97exit $ERRORS{$state};
98
99
100sub usage {
101 print "\nMissing arguments!\n";
102 print "\n";
103 print "check_arping -I <interface> -H <host IP> [-t <timeout>]\n";
104 print "\n\n";
105 support();
106 exit $ERRORS{"UNKNOWN"};
107}
108
109sub print_help {
110 print "check_arping pings hosts that normally wouldn't allow\n";
111 print "ICMP packets but are still on the local network.\n";
112 print "\nUsage:\n";
113 print " -H (--host) IP to query - (required)\n";
114 print " -I (--interface) Interface to use.\n";
115 print " -t (--timeout) Timeout in seconds.\n";
116 print " -V (--version) Plugin version\n";
117 print " -h (--help) usage help \n\n";
118 print_revision($PROGNAME, '$Revision$');
119
120}
diff --git a/contrib/check_cpqarray.c b/contrib/check_cpqarray.c
new file mode 100644
index 00000000..badffeb4
--- /dev/null
+++ b/contrib/check_cpqarray.c
@@ -0,0 +1,430 @@
1/*
2 check_cpqarray, an extension for Netsaint / Nagios to check the
3 status of a Compaq SmartArray controller from the commandline.
4 Copyright (C) 2003 Guenther Mair
5
6 based on the work and using main parts of
7
8 CpqArray Deamon, a program to monitor and remotely configure a
9 SmartArray controller.
10 Copyright (C) 1999 Hugo Trippaers
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <unistd.h>
28#include <sys/ioctl.h>
29#include <sys/utsname.h>
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33#include <errno.h>
34
35#include "/usr/src/linux/drivers/block/ida_ioctl.h"
36#include "/usr/src/linux/drivers/block/ida_cmd.h"
37#include "/usr/src/linux/drivers/block/cpqarray.h"
38
39
40const char *controllers[] =
41{
42 "/dev/ida/c0d0",
43 "/dev/ida/c1d0",
44 "/dev/ida/c2d0",
45 "/dev/ida/c3d0",
46 "/dev/ida/c4d0",
47 "/dev/ida/c5d0",
48 "/dev/ida/c6d0",
49 "/dev/ida/c7d0"
50};
51
52const char *statusstr[] = {
53 "Logical drive /dev/ida/c%dd%d: OK\n",
54 "Logical drive /dev/ida/c%dd%d: FAILED\n",
55 "Logical drive /dev/ida/c%dd%d: not configured.\n",
56 "Logical drive /dev/ida/c%dd%d: using interim recovery mode, %3.2f%% done.\n",
57 "Logical drive /dev/ida/c%dd%d: ready for recovery operation.\n",
58 "Logical drive /dev/ida/c%dd%d: is currently recovering, %3.2f%% done.\n",
59 "Wrong physical drive was replaced.\n",
60 "A physical drive is not properly connected.\n",
61 "Hardware is overheating.\n",
62 "Hardware has overheated.\n",
63 "Logical drive /dev/ida/c%dd%d: currently expanding, %3.2f%% done.\n",
64 "Logical drive /dev/ida/c%dd%d: not yet available.\n",
65 "Logical drive /dev/ida/c%dd%d: queued for expansion.\n",
66};
67
68extern char *optarg;
69extern int optind, opterr, optopt;
70
71int ctrls_found_num;
72int exit_code = 0;
73struct controller ctrls_found[8];
74
75#define DEBUG(x) fprintf(stderr, x)
76
77struct opts
78{
79 char debug;
80};
81
82struct slog_disk
83{
84 int status;
85 float pvalue;
86};
87
88struct controller
89{
90 char ctrl_devicename[20];
91 int num_logd_found;
92 struct slog_disk log_disk[16];
93};
94
95
96
97int status_check (struct opts opts)
98{
99 int devicefd;
100 int ctrl_cntr;
101 int logd_cntr;
102 ida_ioctl_t io, io2;
103 int status, nr_blks, blks_tr;
104 float pvalue;
105 int counter;
106
107 for ( ctrl_cntr=0;
108 ctrl_cntr < ctrls_found_num;
109 ctrl_cntr++) {
110
111 devicefd = open (controllers[ctrl_cntr], O_RDONLY);
112
113 for ( logd_cntr=0;
114 logd_cntr < ctrls_found[ctrl_cntr].num_logd_found;
115 logd_cntr++) {
116
117 memset (&io, 0, sizeof (io));
118
119 io.cmd = SENSE_LOG_DRV_STAT;
120 io.unit = logd_cntr | UNITVALID;
121
122 if (ioctl (devicefd, IDAPASSTHRU, &io) < 0)
123 {
124 perror ("SENSE_LOG_DRV_STAT ioctl");
125 return 0;
126 }
127
128 status=io.c.sense_log_drv_stat.status;
129
130 if ((status == 3) || (status == 5) || (status == 7)) {
131 /* is a progress indicator required?
132 */
133 memset (&io2, 0, sizeof (io));
134
135 io2.cmd = ID_LOG_DRV;
136 io2.unit = logd_cntr | UNITVALID;
137
138 if (ioctl (devicefd, IDAPASSTHRU, &io2) < 0)
139 {
140 perror ("ID_LOG_DRV ioctl");
141 /* return 0; no return this isn't fatal for now */
142 }
143 else
144 {
145 nr_blks = io2.c.id_log_drv.nr_blks;
146 blks_tr = io.c.sense_log_drv_stat.blks_to_recover;
147
148 pvalue = ((float)(nr_blks - blks_tr)/(float)nr_blks) * 100;
149 }
150 }
151 else {
152 pvalue = 0.0;
153 }
154
155 if (opts.debug) {
156 fprintf(stdout, "DEBUG: Status of controller %d unit %d is %d\n",
157 ctrl_cntr, logd_cntr, status);
158 fprintf(stdout, "DEBUG: ");
159 fprintf(stdout, statusstr[status],
160 ctrl_cntr, logd_cntr, pvalue);
161 fprintf(stdout, "\n");
162 }
163
164 printf(statusstr[status], ctrl_cntr, logd_cntr, pvalue);
165
166 switch(status)
167 {
168 case 1:
169 case 2:
170 case 6:
171 case 7:
172 case 9:
173 /* CRITICAL */
174 exit_code = 2;
175 break;
176 case 3:
177 case 4:
178 case 5:
179 case 8:
180 case 10:
181 case 11:
182 case 12:
183 /* WARNING (only if not yet at CRITICAL LEVEL) */
184 if (exit_code < 2) exit_code = 1;
185 break;
186 case 0:
187 default:
188 /* do nothing */
189 break;
190 }
191
192 ctrls_found[ctrl_cntr].log_disk[logd_cntr].pvalue = pvalue;
193 ctrls_found[ctrl_cntr].log_disk[logd_cntr].status = status;
194 }
195 close (devicefd);
196 }
197
198 return 1;
199}
200
201int discover_controllers (struct opts opts)
202{
203 int cntr;
204 int foundone = 0;
205
206 for (cntr = 0; cntr < 8; cntr++)
207 {
208 /* does this device exist ? */
209 if ((access (controllers[cntr], R_OK | F_OK)) == 0)
210 {
211 /* it does :) */
212 if (interrogate_controller (opts, cntr))
213 {
214 foundone = 1;
215 if (opts.debug)
216 fprintf (stderr, "DEBUG: %s is a existing controller\n",
217 controllers[cntr]);
218 }
219 }
220 else if (opts.debug)
221 {
222 fprintf (stderr, "DEBUG: Device %s could not be opened\n", controllers[cntr]);
223 perror ("DEBUG: reason");
224 }
225 }
226 return foundone;
227}
228
229void boardid2str (unsigned long board_id, char *name)
230{
231 switch (board_id)
232 {
233 case 0x0040110E: /* IDA */
234 strcpy (name, "Compaq IDA");
235 break;
236 case 0x0140110E: /* IDA-2 */
237 strcpy (name, "Compaq IDA-2");
238 break;
239 case 0x1040110E: /* IAES */
240 strcpy (name, "Compaq IAES");
241 break;
242 case 0x2040110E: /* SMART */
243 strcpy (name, "Compaq SMART");
244 break;
245 case 0x3040110E: /* SMART-2/E */
246 strcpy (name, "Compaq SMART-2/E");
247 break;
248 case 0x40300E11: /* SMART-2/P or SMART-2DH */
249 strcpy (name, "Compaq SMART-2/P (2DH)");
250 break;
251 case 0x40310E11: /* SMART-2SL */
252 strcpy (name, "Compaq SMART-2SL");
253 break;
254 case 0x40320E11: /* SMART-3200 */
255 strcpy (name, "Compaq SMART-3200");
256 break;
257 case 0x40330E11: /* SMART-3100ES */
258 strcpy (name, "Compaq SMART-3100ES");
259 break;
260 case 0x40340E11: /* SMART-221 */
261 strcpy (name, "Compaq SMART-221");
262 break;
263 case 0x40400E11: /* Integrated Array */
264 strcpy (name, "Compaq Integrated Array");
265 break;
266 case 0x40500E11: /* Smart Array 4200 */
267 strcpy (name, "Compaq Smart Array 4200");
268 break;
269 case 0x40510E11: /* Smart Array 4250ES */
270 strcpy (name, "Compaq Smart Array 4250ES");
271 break;
272 case 0x40580E11: /* Smart Array 431 */
273 strcpy (name, "Compaq Smart Array 431");
274 break;
275 default:
276 /*
277 * Well, its a SMART-2 or better, don't know which
278 * kind.
279 */
280 strcpy (name, "Unknown Controller Type");
281 }
282}
283
284int interrogate_controller (struct opts opts, int contrnum)
285{
286 int devicefd;
287 ida_ioctl_t io;
288 char buffer[30];
289 int foundone = 0;
290 int cntr;
291
292 devicefd = open (controllers[contrnum], O_RDONLY);
293 /* no checks, did that before */
294
295 /* clear io */
296 memset (&io, 0, sizeof (io));
297
298 io.cmd = ID_CTLR;
299
300 if (ioctl (devicefd, IDAPASSTHRU, &io) < 0)
301 {
302 if (opts.debug) perror ("DEBUG: ioctl");
303 return 0;
304 }
305
306 boardid2str (io.c.id_ctlr.board_id, buffer);
307
308 strncpy (ctrls_found[ctrls_found_num].ctrl_devicename,
309 buffer, 20);
310
311 ctrls_found[ctrls_found_num].num_logd_found = 0;
312
313 for (cntr = 0; cntr < io.c.id_ctlr.nr_drvs; cntr++)
314 {
315 if (interrogate_logical (opts, devicefd, cntr))
316 {
317 /* logical drive found, this could be used later one */
318 foundone = 1;
319 }
320 }
321
322 switch (ctrls_found[ctrls_found_num].num_logd_found)
323 {
324 case 0:
325 printf("Found a %s with no logical drives.\n", buffer);
326 break;
327 case 1:
328 printf("Found a %s with one Logical drive.\n", buffer,
329 ctrls_found[ctrls_found_num].num_logd_found);
330 break;
331 default:
332 printf("Found a %s with %d Logical drives.\n", buffer,
333 ctrls_found[ctrls_found_num].num_logd_found);
334 break;
335 }
336
337 ctrls_found_num++;
338
339 close (devicefd);
340 return 1;
341}
342
343int interrogate_logical (struct opts opts, int devicefd, int unit_nr)
344{
345 ida_ioctl_t io;
346 ida_ioctl_t io2;
347 int nr_blks, blks_tr;
348
349 if (opts.debug) printf ("DEBUG: interrogating unit %d\n", unit_nr);
350
351 memset (&io, 0, sizeof (io));
352
353 io.cmd = ID_LOG_DRV;
354 io.unit = unit_nr | UNITVALID;
355
356 if (ioctl (devicefd, IDAPASSTHRU, &io) < 0)
357 {
358 perror ("FATAL: ID_LOG_DRV ioctl");
359 return 0;
360 }
361
362 memset (&io2, 0, sizeof (io2));
363
364 io2.cmd = SENSE_LOG_DRV_STAT;
365 io2.unit = unit_nr | UNITVALID;
366
367 if (ioctl (devicefd, IDAPASSTHRU, &io2) < 0)
368 {
369 perror ("FATAL: SENSE_LOG_DRV_STAT ioctl");
370 return 0;
371 }
372
373 ctrls_found[ctrls_found_num].num_logd_found++;
374 /* ctrls_found[ctrls_found_num].log_disk[unit_nr].status =
375 * io2.c.sense_log_drv_stat.status;
376
377 * nr_blks = io2.c.id_log_drv.nr_blks;
378 * blks_tr = io.c.sense_log_drv_stat.blks_to_recover;
379 * ctrls_found[ctrls_found_num].log_disk[unit_nr].pvalue =
380 * ((float)(nr_blks - blks_tr)/(float)nr_blks) * 100;
381 */
382 ctrls_found[ctrls_found_num].log_disk[unit_nr].status = 0;
383 ctrls_found[ctrls_found_num].log_disk[unit_nr].pvalue = 0;
384
385 return 1;
386}
387
388
389void print_usage()
390{
391 printf("cpqarrayd [options]\n");
392 printf(" -h prints this text\n");
393 printf(" -d enables debugging\n");
394}
395
396
397int main(int argc, char *argv[])
398{
399 char option;
400 struct opts opts; /* commandline options */
401
402 memset(&opts, 0, sizeof(struct opts));
403
404 /* check options */
405 while ((option = getopt (argc, argv, "dh:")) != EOF)
406 {
407 switch (option)
408 {
409 case 'd':
410 opts.debug = 1;
411 break;
412 case '?':
413 case 'h':
414 default:
415 print_usage();
416 exit(0);
417 break;
418 }
419 }
420
421 /* Check for existance of array controllers */
422 if (!discover_controllers(opts)) {
423 printf("No array controller found!\n\n");
424 exit(1);
425 }
426
427 status_check(opts);
428
429 return exit_code;
430}
diff --git a/contrib/check_frontpage b/contrib/check_frontpage
new file mode 100644
index 00000000..ee958d30
--- /dev/null
+++ b/contrib/check_frontpage
@@ -0,0 +1,151 @@
1#! /usr/bin/perl -w
2#
3# $Id$
4#
5# Check that FrontPage extensions appear to be working on a specified host.
6# Currently only checks that the hit counter is not returning an error.
7#
8# Probably not a good idea to use this on a host that someone's counting
9# the hits on, so create a separate vhost for frontpage extensions testing,
10# or just install the extensions on the default/root host for your server, and
11# point it against that hostname, running it against all vhosts on a server is
12# probably rather wasteful.
13#
14# Kev Green, oRe Net (http://www.orenet.co.uk/).
15
16
17use strict;
18use lib "/usr/lib/nagios/plugins";
19use utils qw($TIMEOUT %ERRORS &print_revision &support);
20use vars qw($PROGNAME);
21use Getopt::Long;
22use LWP;
23use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H);
24my ($tt,$url,$response,$stime, $etime,$warning,$critical,$mimetype,$failtype,$temp,$message);
25my $rt = 0;
26
27$PROGNAME = "check_frontpage";
28sub print_help ();
29sub print_usage ();
30
31$ENV{'PATH'}='';
32$ENV{'BASH_ENV'}='';
33$ENV{'ENV'}='';
34
35Getopt::Long::Configure('bundling');
36GetOptions
37 ("V" => \$opt_V, "version" => \$opt_V,
38 "h" => \$opt_h, "help" => \$opt_h,
39 "v" => \$verbose, "verbose" => \$verbose,
40 "w=s" => \$opt_w, "warning=s" => \$opt_w,
41 "c=s" => \$opt_c, "critical=s" => \$opt_c,
42 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
43
44if ($opt_V) {
45 print_revision($PROGNAME,'$Revision$'); #'
46 exit $ERRORS{'OK'};
47}
48
49if ($opt_h) {
50 print_help();
51 exit $ERRORS{'OK'};
52}
53
54$opt_H = shift unless ($opt_H);
55print_usage() unless $opt_H;
56my $host = $1 if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z0-9][-a-zA-Z0-9]+)*)$/);
57print_usage() unless $host;
58
59($opt_c) || ($opt_c = shift) || ($opt_c = 120);
60if ($opt_c =~ /([0-9]+)/) {
61 $critical = $1;
62} else {
63 $critical = 10;
64}
65
66($opt_w) || ($opt_w = shift) || ($opt_w = 60);
67if ($opt_w =~ /([0-9]+)/) {
68 $warning = $1;
69} else {
70 $warning = 5;
71}
72
73# Guts go here, once we're through argument parsing and have warning and
74# critical thresholds.
75my $browser = LWP::UserAgent->new;
76
77my @urls = (
78 # This is the "Hit Counter", which continues to work if frontpage extensions
79 # are 'uninstall'ed from the site, but not when they are 'fulluninstall'ed.
80 {
81 url => "_vti_bin/fpcount.exe?Page=_borders/right.htm|Image=4",
82 mimetype => "image/gif",
83 message => "None, or broken frontpage extensions on server, or virtual site 'fulluninstall'ed?",
84 failtype => "CRITICAL"
85 },
86 # This is the "FrontPage Configuration Information" file, which is removed
87 # when you 'uninstall' the extensions from a site.
88 {
89 url => "_vti_inf.html",
90 mimetype => "text/html",
91 message => "Someone 'uninstall'ed extensions on virtual site?",
92 failtype => "WARNING"
93 }
94);
95
96print "FRONTPAGE: ";
97
98foreach $temp (@urls) {
99 $url = $temp->{'url'};
100 $mimetype = $temp->{'mimetype'};
101 $failtype = $temp->{'failtype'};
102 $message = $temp->{'message'};
103 $stime = time();
104 $response=$browser->get("http://".$host."/".$url);
105 $etime = time();
106 $tt = $etime - $stime;
107
108# If we got a server error, or unknown output type, report back as critical.
109 if ($response->status_line !~ "^200") {
110 print $message." (".$response->status_line.")\r\n";
111 exit $ERRORS{$failtype};
112 } elsif ($response->content_type !~ $mimetype) {
113 print $message." (Wrong Content-type: ".$response->content_type.")\r\n";
114 exit $ERRORS{$failtype};
115 } else {
116 # Because we're dealing with multiple URL's
117 $rt += $tt;
118 }
119
120# Decide if the response time was critical or not.
121#
122 if ($rt > $critical) {
123 print "Response time ".$rt." over critical threshold ".$critical."\r\n";
124 exit($ERRORS{'CRITICAL'});
125 } elsif ($rt > $warning) {
126 print "Response time ".$rt." over warning threshold ".$warning."\r\n";
127 exit($ERRORS{'WARNING'});
128 }
129}
130printf(" %s - %s second response time, ",$response->status_line, $rt);
131
132# If all the required URL's give the right responses quick enough, then we
133# should be okay.
134exit($ERRORS{'OK'});
135
136sub print_usage () {
137 print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
138 exit;
139}
140
141sub print_help () {
142 print_revision($PROGNAME,'$Revision$');
143 print "Copyright (c) 2003 Kev Green\n";
144 print "\n";
145 print "FrontPage remains a copyright/trademark of Microsoft Corporation.\n";
146 print_usage();
147 print "\n";
148 print "<warn> = Unknown.\n";
149 print "<crit> = Server error from FrontPage extensions.\n\n";
150 support();
151}
diff --git a/contrib/check_logins.c b/contrib/check_logins.c
new file mode 100644
index 00000000..fa3ed177
--- /dev/null
+++ b/contrib/check_logins.c
@@ -0,0 +1,351 @@
1/*=================================
2 * check_logins - Nagios plugin
3 * Copyright (C) 2003 Dag Robøle
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors email: drobole@broadpark.no
20 */
21//=================================
22#include <sys/types.h>
23#include <signal.h>
24#include <errno.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29
30#include "config.h"
31#include "common.h"
32#include "utils.h"
33#include "popen.h"
34//=================================
35#define REVISION "$Revision$"
36#define COPYRIGHT "2003"
37#define AUTHOR "Dag Robole"
38#define EMAIL "drobole@broadpark.no"
39#define SUMMARY "Check for multiple user logins"
40
41#define check(func, errmsg) { if((func) == -1) die(STATE_UNKNOWN, errmsg); }
42#define checkz(func, errmsg) { if(!(func)) die(STATE_UNKNOWN, errmsg); }
43//=================================
44typedef struct USERNODE_TYP {
45 char *name;
46 char *host;
47 struct USERNODE_TYP* next;
48} USERNODE;
49//=================================
50char *progname = NULL;
51USERNODE *userlist = NULL, *adminlist = NULL;
52int warning_limit = 0, critical_limit = 0;
53
54void print_usage();
55void print_help();
56void process_arguments(int argc, char* *argv);
57void parse_wholine(const char *line, char *name, char *host);
58void node_create(USERNODE* *node, const char *name, const char *host);
59void node_free(USERNODE* *node);
60USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node);
61void list_free(USERNODE* *list);
62void cleanup();
63//=================================
64int main(int argc, char* *argv)
65{
66 FILE *who;
67 USERNODE *newnode, *nptra, *nptrb;
68 char buffer[BUFSIZ], username[BUFSIZ], hostname[BUFSIZ], *cptra, *cptrb;
69 char max_login_name[BUFSIZ], currname[BUFSIZ];
70 int max_login_count = 0, counter = 0, skip;
71 void (*old_sig_alrm)();
72
73 progname = argv[0];
74 if(atexit(cleanup))
75 die(STATE_UNKNOWN, "atexit failed\n");
76
77 if((old_sig_alrm = signal((int)SIGALRM, timeout_alarm_handler)) == SIG_ERR)
78 die(STATE_UNKNOWN, "signal failed\n");
79 alarm(timeout_interval);
80
81 process_arguments(argc, argv);
82
83 checkz(who = spopen(PATH_TO_WHO), "spopen failed\n");
84
85 while(fgets(buffer, sizeof(buffer), who) != NULL) {
86 parse_wholine(buffer, username, hostname);
87 skip = 0;
88 nptra = adminlist;
89
90 while(nptra != NULL) {
91 if(!strcmp(nptra->name, username)) {
92 skip = 1;
93 break;
94 }
95 nptra = nptra->next;
96 }
97 if(!skip) {
98 node_create(&newnode, username, hostname);
99 if(!list_insert_sort_uniq(&userlist, &newnode))
100 node_free(&newnode);
101 }
102 }
103
104 check(spclose(who), "spclose failed\n");
105
106 if(userlist != NULL) {
107 nptra = userlist;
108 strcpy(currname, nptra->name);
109 strcpy(max_login_name, nptra->name);
110 max_login_count = 1;
111 while(nptra != NULL) {
112 if(!strcmp(currname, nptra->name))
113 ++counter;
114 else {
115 if(counter > max_login_count) {
116 max_login_count = counter;
117 strcpy(max_login_name, currname);
118 }
119 strcpy(currname, nptra->name);
120 counter = 1;
121 }
122 nptra = nptra->next;
123 }
124
125 if(counter > max_login_count) {
126 max_login_count = counter;
127 strcpy(max_login_name, currname);
128 }
129 }
130
131 if(signal((int)SIGALRM, old_sig_alrm) == SIG_ERR)
132 die(STATE_UNKNOWN, "signal failed\n");
133
134 if(max_login_count) {
135 if(critical_limit && max_login_count >= critical_limit) {
136 printf("CRITICAL - User %s has logged in from %d different hosts\n", max_login_name, max_login_count);
137 return STATE_CRITICAL;
138 }
139 else if(warning_limit && max_login_count >= warning_limit) {
140 printf("WARNING - User %s has logged in from %d different hosts\n", max_login_name, max_login_count);
141 return STATE_WARNING;
142 }
143 }
144
145 printf("OK - No users has exceeded the login limits\n");
146 return STATE_OK;
147}
148//=================================
149void print_usage()
150{
151 fprintf(stderr, "Usage: %s [ -hV ] [ -w limit ] [ -c limit ] [ -u username1, ... ,usernameN ]\n", progname);
152}
153//=================================
154void print_help()
155{
156 print_revision(progname, REVISION);
157 printf("Copyright (c) %s %s <%s>\n\n%s\n\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
158 print_usage();
159 printf("\nDescription:\n"
160 "\tThis plugin supports the w (warning) and c (critical) options indicating the upper limits\n"
161 "\tof logins allowed before a warning is given.\n"
162 "\tThe output from %s is the username and number of login sessions for the user\n"
163 "\twho has the most login sessions (from different hosts) running at a given point in time.\n"
164 "\tThe u (users) option takes a comma separated list of usernames that will be ignored\n"
165 "\twhile scannig users.\n"
166 "\nOptions:\n"
167 "\t-h | --help\n\t\tShow this help message and exit\n"
168 "\t-V | --version\n\t\tShow version description\n"
169 "\t-w | --warning=INTEGER\n\t\tSet warning limit for logins (minimum value is 2)\n"
170 "\t-c | --critical=INTEGER\n\t\tSet critical limit for logins (minimum value is 2)\n"
171 "\t-u | --users=STRING\n\t\tSet usernames to be ignored\n"
172 "\nExamples:\n\t%s -w 3 -c 5\n"
173 "\t%s -w 3 -c 5 -u root,guest,jcarmack\n\n", progname, progname, progname);
174}
175//=================================
176void process_arguments(int argc, char* *argv)
177{
178 USERNODE *newnode;
179 int optch;
180 char buffer[BUFSIZ], *cptra;
181 static struct option long_opts[] = {
182 {"help", no_argument, 0, 'h'},
183 {"version", no_argument, 0, 'V'},
184 {"warning", required_argument, 0, 'w'},
185 {"critical", required_argument, 0, 'c'},
186 {"users", required_argument, 0, 'u'},
187 {0, 0, 0, 0},
188 };
189
190 while((optch = getopt_long(argc, argv, "hVw:c:u:", long_opts, NULL)) != -1) {
191 switch(optch) {
192 case 'h':
193 print_help();
194 exit(STATE_OK);
195 break;
196 case 'V':
197 print_revision(progname, REVISION);
198 exit(STATE_OK);
199 break;
200 case 'w':
201 if(!is_numeric(optarg)) {
202 print_usage();
203 die(STATE_UNKNOWN, "invalid options\n");
204 }
205 warning_limit = atoi(optarg) > 2 ? atoi(optarg) : 2;
206 break;
207 case 'c':
208 if(!is_numeric(optarg)) {
209 print_usage();
210 die(STATE_UNKNOWN, "invalid options\n");
211 }
212 critical_limit = atoi(optarg) > 2 ? atoi(optarg) : 2;
213 break;
214 case 'u':
215 strcpy(buffer, optarg);
216 cptra = strtok(buffer, ",");
217 while(cptra != NULL) {
218 node_create(&newnode, cptra, "(adminhost)");
219 list_insert_sort_uniq(&adminlist, &newnode);
220 cptra = strtok(NULL, ",");
221 }
222 break;
223 default:
224 print_usage();
225 exit(STATE_UNKNOWN);
226 break;
227 }
228 }
229
230 if(argc > optind) {
231 print_usage();
232 die(STATE_UNKNOWN, "invalid options\n");
233 }
234
235 if(!warning_limit && !critical_limit) {
236 print_usage();
237 die(STATE_UNKNOWN, "you must provide a limit for this plugin\n");
238 }
239
240 if(critical_limit && warning_limit > critical_limit) {
241 print_usage();
242 die(STATE_UNKNOWN, "warning limit must be less or equal critical limit\n");
243 }
244}
245//=================================
246void parse_wholine(const char *line, char *name, char *host)
247{
248 char buffer[BUFSIZ], *cptra, *cptrb, *display;
249 strcpy(buffer, line);
250
251 cptra = buffer;
252 checkz(cptrb = (char*)strchr(buffer, ' '), "strchr failed\n");
253 strncpy(name, cptra, cptrb-cptra);
254 name[cptrb-cptra] = '\0';
255
256 if((cptra = strchr(buffer, '(')) != NULL) // hostname found in source arg...
257 {
258 if(cptra[1] == ':') // local host
259 strcpy(host, "(localhost)");
260 else // extern host
261 {
262 checkz(cptrb = strchr(cptra, ')'), "strchr failed\n");
263 cptrb++;
264 strncpy(host, cptra, cptrb-cptra);
265 host[cptrb-cptra] = '\0';
266 }
267 }
268 else // no hostname in source arg, look in line arg...
269 {
270 checkz(cptra = strtok(buffer, " \t\r\n"), "strtok failed\n");
271 checkz(cptra = strtok(NULL, " \t\r\n"), "strtok failed\n");
272 if(cptra[0] == ':') // local host
273 strcpy(host, "(localhost)");
274 else // extern host
275 sprintf(host, "(%s)", cptra);
276 }
277
278 if((cptra = strchr(host, ':')) != NULL) // remove display if any...
279 strcpy(cptra, ")");
280}
281//=================================
282void node_create(USERNODE* *node, const char *name, const char *host)
283{
284 checkz(*node = (USERNODE*)malloc(sizeof(USERNODE)), "malloc failed\n");
285 checkz((*node)->name = (char*)malloc(strlen(name)+1), "malloc failed\n");
286 checkz((*node)->host = (char*)malloc(strlen(host)+1), "malloc failed\n");
287 (*node)->next = NULL;
288 strcpy((*node)->name, name);
289 strcpy((*node)->host, host);
290}
291//=================================
292void node_free(USERNODE* *node)
293{
294 free((*node)->name);
295 free((*node)->host);
296 free(*node);
297 *node = NULL;
298}
299//=================================
300USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node)
301{
302 char n1[BUFSIZ], n2[BUFSIZ];
303 USERNODE *last_nptr = NULL, *nptr = *list;
304
305 if(*list == NULL)
306 return(*list = *node);
307 else {
308 sprintf(n1, "%s %s", (*node)->name, (*node)->host);
309 while(nptr != NULL) {
310 sprintf(n2, "%s %s", nptr->name, nptr->host);
311 if(!strcmp(n1, n2))
312 return NULL;
313 else if(strcmp(n1, n2) < 0) {
314 if(last_nptr) {
315 last_nptr->next = *node;
316 (*node)->next = nptr;
317 }
318 else {
319 (*node)->next = *list;
320 *list = *node;
321 }
322 break;
323 }
324 else {
325 last_nptr = nptr;
326 nptr = nptr->next;
327 }
328 }
329 if(nptr == NULL)
330 last_nptr->next = *node;
331 }
332 return *node;
333}
334//=================================
335void list_free(USERNODE* *list)
336{
337 USERNODE *doe, *nptr = *list;
338 while(nptr != NULL) {
339 doe = nptr;
340 nptr = nptr->next;
341 node_free(&doe);
342 }
343 *list = NULL;
344}
345//=================================
346void cleanup()
347{
348 list_free(&userlist);
349 list_free(&adminlist);
350}
351//=================================
diff --git a/contrib/check_oracle_tbs b/contrib/check_oracle_tbs
new file mode 100644
index 00000000..bcc4af87
--- /dev/null
+++ b/contrib/check_oracle_tbs
@@ -0,0 +1,206 @@
1#!/usr/local/bin/perl -w
2
3# (c)2003 John Koyle, RFP Depot, LLC.
4# This is free software use it however you would like.
5# Thanks to the folks at http://www.think-forward.com for the SQL query
6
7
8use strict;
9use DBI;
10use Getopt::Long 2.16;
11use lib "/usr/local/nagios/libexec";
12use utils qw(%ERRORS);
13
14
15#*******************************************************************************
16# Set user configureable options here.
17#
18# Global Oracle info set here rather than command line to avoid output in ps -ef
19# Make sure this script is mode 700 and owner of the nrpe user
20#
21#*******************************************************************************
22my $orasid = "";
23my $orauser = "";
24my $orapwd = "";
25
26
27if (!$ENV{ORACLE_HOME}) {
28 $ENV{ORACLE_HOME} = '/a01/app/oracle/product/9.2.0.1';
29}
30
31#*****************You shouldn't need to modify anything below here *************
32my $state = $ERRORS{'UNKNOWN'};
33my $answer = undef;
34
35my ($MAJOR_VERSION, $MINOR_VERSION) = q$Revision$ =~ /(\d+)\.(\d+)/;
36my $VERSION = sprintf("%d.%02d", $MAJOR_VERSION - 1, $MINOR_VERSION);
37
38my $opt_debug; # -d|--debug
39my $opt_help; # -h|--help
40my $opt_version; # -V|--version
41my $opt_warn_space; # -w|--warn-space
42my $opt_crit_space; # -c|--crit-space
43
44my $help = <<MARK; # help statement
45
46check_oracle_tbs v$VERSION
47
48Checks the tablespaces in an Oracle database for available free space.
49Usage: check_oracle_tbs [-w <warn>] [-c <crit>]
50
51 -d, --debug Output debug to screen.
52 -h, --help Displays this help and exits.
53 -w, --warn-space=... Warning threshold % free (default 15)
54 -c, --crit-space=... Critical threshold % free (default 10)
55 -V, --version Output version information and exit.
56
57MARK
58
59## We want exact matches to the switches
60
61Getopt::Long::config('no_auto_abbrev', 'no_ignore_case');
62
63my $rc = GetOptions(
64 "debug|d" => \$opt_debug,
65 "help|h" => \$opt_help,
66 "w|warn-space=s" => \$opt_warn_space,
67 "c|crit-space=s" => \$opt_crit_space,
68 "V|version" => \$opt_version,
69 );
70
71
72#***********************************************************************
73# Process command-line switches
74#***********************************************************************
75
76if (! $rc || defined $opt_help)
77{
78 print STDERR $help;
79 exit (defined $opt_help ? 0 : 1);
80}
81
82if (defined $opt_version)
83{
84 print STDERR "check_oracle_tbs v$VERSION\n";
85 exit 0;
86}
87
88if (! defined $opt_warn_space)
89{
90 if(defined $opt_debug) {
91 print STDOUT "Warn space not defined, using 80%\n\n";
92 }
93 $opt_warn_space = 15;
94}
95
96if (! defined $opt_crit_space)
97{
98 if(defined $opt_debug) {
99 print STDOUT "Crit space not defined, using 90%\n\n";
100 }
101 $opt_crit_space = 10;
102}
103
104my $array_ref = executeSQL();
105
106foreach my $row (@$array_ref) {
107 my ( $tbs_name, $tot_mb, $free_mb, $free_pct, $used_pct, $fsfi) = @$row;
108 if ($opt_debug) { print STDOUT "Output: $tbs_name\t$tot_mb\t$free_mb\t$free_pct\t$used_pct\t$fsfi\n\n"; }
109 if ($used_pct > (100 - $opt_crit_space) && $tbs_name !~ /RBS/) {
110 $state = $ERRORS{'CRITICAL'};
111 $answer .= "$tbs_name = $used_pct\% ";
112 last;
113 }
114 if ($used_pct > (100 - $opt_warn_space) && $tbs_name !~ /RBS/) {
115 $state = $ERRORS{'WARNING'};
116 $answer .= "$tbs_name = $used_pct\% ";
117 }
118}
119
120if ($state != $ERRORS{'CRITICAL'} && $state != $ERRORS{'WARNING'}) {
121 $state = $ERRORS{'OK'};
122 $answer = "All Tablespaces OK";
123}
124
125if ($opt_debug && $state != $ERRORS{'OK'}) { print STDOUT "The following tablespaces are in question: $answer\n\n"; }
126
127foreach my $key (keys %ERRORS) {
128 if ($state==$ERRORS{$key}) {
129 print ("$key: $answer");
130 last;
131 }
132}
133exit $state;
134
135sub executeSQL
136{
137 my ($dbh, $sth, $results);
138
139 $dbh = openOracle();
140
141 eval {
142 $dbh->{RaiseError} = 1;
143 # This query is taken from this URL and used with permission: http://www.think-forward.com/sql/tspace.htm
144 $sth = $dbh->prepare(q{
145 select df.tablespace_name tspace,
146 df.bytes/(1024*1024) tot_ts_size,
147 sum(fs.bytes)/(1024*1024) free_ts_size,
148 round(sum(fs.bytes)*100/df.bytes) ts_pct,
149 round((df.bytes-sum(fs.bytes))*100/df.bytes) ts_pct1,
150 ROUND(100*SQRT(MAX(fs.bytes)/SUM(fs.bytes))*
151 (1/SQRT(SQRT(COUNT(fs.bytes)))) ,2) FSFI
152 from dba_free_space fs, (select tablespace_name, sum(bytes) bytes
153 from dba_data_files
154 group by tablespace_name ) df
155 where fs.tablespace_name = df.tablespace_name
156 group by df.tablespace_name, df.bytes
157 });
158
159 $sth->execute();
160 $results = $sth->fetchall_arrayref();
161 $sth->finish;
162 $dbh->{RaiseError} = 0;
163 };
164
165 if ($@) {
166 closeOracle($dbh);
167 if($opt_debug) { print STDOUT "DB Failed Query: $@\n"; }
168 CleanupAndExit($ERRORS{'UNKNOWN'});
169 }
170
171 closeOracle($dbh);
172
173 return $results;
174}
175
176#------ Open the connection to the database and return the handle
177sub openOracle
178{
179 my ($dbh);
180
181 $dbh = DBI->connect("$orasid", "$orauser", "$orapwd", "Oracle");
182
183 if (!$dbh) {
184 if ($opt_debug) { print "ERROR: Could not connect to Oracle!\n\n"; }
185 CleanupAndExit($ERRORS{'UNKNOWN'});
186 }
187 if ($opt_debug) { print "Connected to Oracle SID $orasid\n\n"; }
188 return $dbh;
189}
190
191#------- Close the database connection
192sub closeOracle()
193{
194 my ($dbh) = @_;
195
196 $dbh->disconnect;
197}
198
199#------ Exit with the current return code
200sub CleanupAndExit
201{
202 my ($rc) = @_;
203
204 exit($rc);
205}
206
diff --git a/contrib/check_pcpmetric.py b/contrib/check_pcpmetric.py
new file mode 100644
index 00000000..71d816d4
--- /dev/null
+++ b/contrib/check_pcpmetric.py
@@ -0,0 +1,106 @@
1#! /usr/bin/env python
2#
3# Nagios client for checking Performance Co-Pilot metrics
4#
5#
6
7from sys import argv,exit
8import popen2, getopt, string, types
9
10DEBUG=0
11
12nagios_pcpclient_version = 0.01
13PMVAL='/usr/bin/pmval'
14COMMANDLINE=PMVAL + " -s 1"
15METRIC='undefined'
16CRITICAL=0
17WARNING=0
18
19def usage():
20 print "Usage:", argv[0], "[options]"
21 print "Options:"
22 print "\t[-H host]\tHostname to contact"
23 print "\t[-m metric]\tPCP metric to check"
24 print "\t[-i instance]\tPCP metric instance"
25 print "\t[-w warn]\tIssue warning alert if value is larger than this"
26 print "\t[-c critical]\tIssue critical alert value is larger than this"
27 print "\t[-V]\t\tProgram version"
28 print "\t[-h]\t\tThis helptext"
29 print ""
30 print "F.ex. to check 5 minute loadaverage, warn if the load is above 2,"
31 print "and give critical warning if it's above 10:"
32 print "\n\t%", argv[0], " -i 5 -m kernel.all.load -w 2 -c 10"
33 print ""
34 print "A list of all PCP metrics can be found with the command 'pminfo'."
35 print "A list of all instances within a metric can be found with 'pminfo -f metric'."
36 print "F.ex. to see all available instances of 'filesys.full' execute:"
37 print "\n\t% pminfo -f filesys.full"
38 print "\tfilesys.full"
39 print """\t\tinst [0 or "/dev/root"] value 45.35514044640914"""
40 print """\t\tinst [1 or "/dev/sda1"] value 46.74285959344712"""
41 print """\t\tinst [2 or "/dev/sdb1"] value 0.807766570678168"""
42 print ""
43 print "And the command to have nagios monitor the /dev/sda1 filesystem would be:"
44 print "\n\t", argv[0], " -i /dev/sda1 -m filesys.full -w 70 -c 90"
45
46
47opts, args = getopt.getopt(argv[1:],'hH:c:w:m:i:V')
48for opt in opts:
49 key,value = opt
50 if key == '-H':
51 COMMANDLINE = COMMANDLINE + " -h " + value
52 elif key == '-m':
53 METRIC=value
54 elif key == '-i':
55 COMMANDLINE = COMMANDLINE + " -i " + value
56 elif key == '-c':
57 CRITICAL = value
58 elif key == '-w':
59 WARNING = value
60 elif key == '-h':
61 usage()
62 exit(0)
63 elif key == '-V':
64 print "Nagios Performance CoPilot client v%.2f" % nagios_pcpclient_version
65 print "Written by Jan-Frode Myklebust <janfrode@parallab.uib.no>"
66 exit(0)
67
68if METRIC == 'undefined':
69 usage()
70 exit(3)
71
72COMMANDLINE = COMMANDLINE + " " + METRIC
73if DEBUG: print COMMANDLINE
74p=popen2.Popen4(COMMANDLINE)
75exitcode=p.wait()
76
77# Get the last line of output from 'pmval':
78buffer = p.fromchild.readline()
79while (buffer != ''):
80 output=buffer
81 buffer = p.fromchild.readline()
82
83returndata = string.split(output)[0]
84
85
86# Confirm that we have gotten a float, and not
87# some errormessage in the returndata. If not,
88# print the error, and give the UNKNOWN exit code:
89
90try:
91 retval = string.atof(returndata)
92except ValueError, e:
93 print e
94 exit(3)
95
96if (retval < WARNING):
97 EXITCODE=0
98elif (retval > CRITICAL):
99 EXITCODE=2
100elif (retval > WARNING):
101 EXITCODE=1
102else:
103 EXITCODE=3
104
105print retval
106exit(EXITCODE)
diff --git a/contrib/check_pfstate b/contrib/check_pfstate
new file mode 100644
index 00000000..6fe0d9b0
--- /dev/null
+++ b/contrib/check_pfstate
@@ -0,0 +1,75 @@
1#!/usr/bin/perl
2
3use strict;
4use Getopt::Long;
5use vars qw($opt_V $opt_h $opt_P $opt_H $opt_w $opt_c $PROGNAME);
6use lib "/usr/local/nagios/libexec" ;
7use utils qw(%ERRORS &print_revision &support &usage);
8
9my $remote_user = "root";
10my $path_to_ssh = "/usr/bin/ssh";
11my $path_to_grep = "/usr/bin/grep";
12my $path_to_awk = "/usr/bin/awk";
13my $warn = 50000;
14my $crit = 60000;
15
16$PROGNAME = "check_pfstate";
17$ENV{'PATH'}='';
18$ENV{'BASH_ENV'}='';
19$ENV{'ENV'}='';
20
21Getopt::Long::Configure('bundling');
22GetOptions
23 ("V" => \$opt_V, "version" => \$opt_V,
24 "h" => \$opt_h, "help" => \$opt_h,
25 "H=s" => \$opt_H, "hostname=s" => \$opt_H,
26 "w=s" => \$opt_w, "warning=s" => \$opt_w,
27 "c=s" => \$opt_c, "critical=s" => \$opt_c);
28
29if ($opt_V) {
30 print_revision($PROGNAME,'$Revision$');
31 exit $ERRORS{'OK'};
32}
33if ($opt_h) {
34 print_help();
35 exit $ERRORS{'OK'};
36}
37if ($opt_w) {
38 if ($opt_w =~ /(\d+)/) {
39 $warn = $1;
40 } else {
41 usage("Invalid values: $opt_w\n");
42 exit $ERRORS{'OK'};
43 }
44}
45if ($opt_c) {
46 if ($opt_c =~ /(\d+)/) {
47 $crit = $1;
48 } else {
49 usage("Invalid values: $opt_c\n");
50 exit $ERRORS{'OK'};
51 }
52}
53($opt_H) || usage("Host name/address not specified\n");
54my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
55($host) || usage("Invalid host: $opt_H\n");
56
57my $result = `$path_to_ssh -l $remote_user $host '/sbin/pfctl -s info' | $path_to_grep entries`;
58chomp $result;
59$result =~ /(\d+)/;
60$result = $1;
61
62print "$result PF state entries\n";
63
64exit $ERRORS{'CRITICAL'} if ($result >= $crit);
65exit $ERRORS{'WARNING'} if ($result >= $warn);
66exit $ERRORS{'OK'};
67
68
69sub print_help {
70 print_revision($PROGNAME,'$Revision$');
71 print "Copyright (c) 2002 Jason Dixon\n\nThis plugin checks the number of state table entries on a PF-enabled OpenBSD system.\n\n";
72 print "Usage:\t-H, --hostname=<HOST> [-w, --warning=<WARNING>] [-c, --critical=<CRITICAL>]\n\n\tDefault warning is 50000 and critical is 60000.\n\n";
73 support();
74}
75