Whitespace changes only
[monitoring-plugins.git] / contrib / check_pfstate
blob57dde3f612b9c13a2ba0a926de65ff6903e3756b
1 #!/usr/bin/perl
3 use strict;
4 use Getopt::Long;
5 use vars qw($opt_V $opt_h $opt_P $opt_H $opt_w $opt_c $PROGNAME);
6 use lib "/usr/local/nagios/libexec" ;
7 use utils qw(%ERRORS &print_revision &support &usage);
9 my $remote_user = "root";
10 my $path_to_ssh = "/usr/bin/ssh";
11 my $path_to_grep = "/usr/bin/grep";
12 my $path_to_awk = "/usr/bin/awk";
13 my $warn = 50000;
14 my $crit = 60000;
16 $PROGNAME = "check_pfstate";
17 $ENV{'PATH'}='';
18 $ENV{'BASH_ENV'}='';
19 $ENV{'ENV'}='';
21 Getopt::Long::Configure('bundling');
22 GetOptions
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);
29 if ($opt_V) {
30 print_revision($PROGNAME,'$Revision: 1112 $');
31 exit $ERRORS{'OK'};
33 if ($opt_h) {
34 print_help();
35 exit $ERRORS{'OK'};
37 if ($opt_w) {
38 if ($opt_w =~ /(\d+)/) {
39 $warn = $1;
40 } else {
41 usage("Invalid values: $opt_w\n");
42 exit $ERRORS{'OK'};
45 if ($opt_c) {
46 if ($opt_c =~ /(\d+)/) {
47 $crit = $1;
48 } else {
49 usage("Invalid values: $opt_c\n");
50 exit $ERRORS{'OK'};
53 ($opt_H) || usage("Host name/address not specified\n");
54 my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
55 ($host) || usage("Invalid host: $opt_H\n");
57 my $result = `$path_to_ssh -l $remote_user $host '/sbin/pfctl -s info' | $path_to_grep entries`;
58 chomp $result;
59 $result =~ /(\d+)/;
60 $result = $1;
62 print "$result PF state entries\n";
64 exit $ERRORS{'CRITICAL'} if ($result >= $crit);
65 exit $ERRORS{'WARNING'} if ($result >= $warn);
66 exit $ERRORS{'OK'};
69 sub print_help {
70 print_revision($PROGNAME,'$Revision: 1112 $');
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();