From fce1f09f770fc5bbc6d323865af709ff515c803c Mon Sep 17 00:00:00 2001 From: Stanley Hopcroft Date: Thu, 27 Jan 2005 04:46:08 +0000 Subject: New /contrib plugin git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1112 f882894a-f735-0410-b71e-b25c423dba1c --- contrib/check_pfstate | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 contrib/check_pfstate (limited to 'contrib/check_pfstate') 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 @@ +#!/usr/bin/perl + +use strict; +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_P $opt_H $opt_w $opt_c $PROGNAME); +use lib "/usr/local/nagios/libexec" ; +use utils qw(%ERRORS &print_revision &support &usage); + +my $remote_user = "root"; +my $path_to_ssh = "/usr/bin/ssh"; +my $path_to_grep = "/usr/bin/grep"; +my $path_to_awk = "/usr/bin/awk"; +my $warn = 50000; +my $crit = 60000; + +$PROGNAME = "check_pfstate"; +$ENV{'PATH'}=''; +$ENV{'BASH_ENV'}=''; +$ENV{'ENV'}=''; + +Getopt::Long::Configure('bundling'); +GetOptions + ("V" => \$opt_V, "version" => \$opt_V, + "h" => \$opt_h, "help" => \$opt_h, + "H=s" => \$opt_H, "hostname=s" => \$opt_H, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision$'); + exit $ERRORS{'OK'}; +} +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} +if ($opt_w) { + if ($opt_w =~ /(\d+)/) { + $warn = $1; + } else { + usage("Invalid values: $opt_w\n"); + exit $ERRORS{'OK'}; + } +} +if ($opt_c) { + if ($opt_c =~ /(\d+)/) { + $crit = $1; + } else { + usage("Invalid values: $opt_c\n"); + exit $ERRORS{'OK'}; + } +} +($opt_H) || usage("Host name/address not specified\n"); +my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/); +($host) || usage("Invalid host: $opt_H\n"); + +my $result = `$path_to_ssh -l $remote_user $host '/sbin/pfctl -s info' | $path_to_grep entries`; +chomp $result; +$result =~ /(\d+)/; +$result = $1; + +print "$result PF state entries\n"; + +exit $ERRORS{'CRITICAL'} if ($result >= $crit); +exit $ERRORS{'WARNING'} if ($result >= $warn); +exit $ERRORS{'OK'}; + + +sub print_help { + print_revision($PROGNAME,'$Revision$'); + print "Copyright (c) 2002 Jason Dixon\n\nThis plugin checks the number of state table entries on a PF-enabled OpenBSD system.\n\n"; + print "Usage:\t-H, --hostname= [-w, --warning=] [-c, --critical=]\n\n\tDefault warning is 50000 and critical is 60000.\n\n"; + support(); +} + -- cgit v1.2.3-74-g34f1