From: Michael Howe Date: Tue, 20 Mar 2012 21:34:29 +0000 (+0000) Subject: Added new check_networkclients script X-Git-Tag: 0.6~1 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=854ce7870a5592ddad0a3dda1d71e5ad822f0ca5;p=packages%2Fn%2Fnagios-plugins-local.git Added new check_networkclients script --- diff --git a/Makefile b/Makefile index c40c57a..346b3ed 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ install: $(INSTALL) -m 0755 $(PLUGINDIR)/check_cert $(DSTPLUGINDIR) $(INSTALL) -m 0755 $(PLUGINDIR)/check_md_raid $(DSTPLUGINDIR) $(INSTALL) -m 0755 $(PLUGINDIR)/check_ldaps_ip $(DSTPLUGINDIR) + $(INSTALL) -m 0755 $(PLUGINDIR)/check_networkclients $(DSTPLUGINDIR) clean: $(RM) plugins/check_ldaps_ip diff --git a/debian/changelog b/debian/changelog index 2543a01..6ba7bc0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nagios-plugins-local (0.6) unstable; urgency=low + + * Added check_networkclients plugin + + -- Michael Howe Tue, 20 Mar 2012 21:32:08 +0000 + nagios-plugins-local (0.5) unstable; urgency=low * Fixed bug in check_cert plugin printing out certificates when it diff --git a/debian/control b/debian/control index 9d9ee3f..82ca05b 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,6 @@ Homepage: Package: nagios-plugins-local Architecture: amd64 -Depends: ${misc:Depends}, perl, python, libc6, gnutls-bin +Depends: ${misc:Depends}, perl, python, libc6, gnutls-bin, libnet-telnet-perl, libnagios-plugin-perl, libregexp-common-perl Description: Local nagios plugins Nagios plugins customized for use on michaelhowe.org hosts. diff --git a/plugins/check_networkclients b/plugins/check_networkclients new file mode 100755 index 0000000..44bfb11 --- /dev/null +++ b/plugins/check_networkclients @@ -0,0 +1,115 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Net::Telnet(); +use Regexp::Common qw/net/; + +use Nagios::Plugin; + +my $macre = $RE{net}{MAC}; +my $ipre = $RE{net}{IPv4}; + +use vars qw( $VERSION $PROGNAME $verbose $warn $critical $timeout $result ); +$VERSION = 1.0; + +use File::Basename; +$PROGNAME = basename( $0 ); + +my $p = Nagios::Plugin->new( + usage => "Usage: %s [-H ] [-t ] + [ -c|--critical=] + [ -w|--warning=]", + version => $VERSION, + blurb => "A plugin to check the number of hosts connected to the router", +); + +$p->add_arg( + spec => 'warning|w=i', + help => + qq{Number of hosts above which a warning state will be generated}, +); + +$p->add_arg( + spec => 'critical|c=i', + help => + qq{Number of hosts above which critical state will be generated}, +); + +$p->add_arg( + spec => 'host|H=s', + help => + qq{Host to connect to}, +); + +$p->getopts; + +unless( defined $p->opts->warning || defined $p->opts->critical ){ + $p->nagios_die( " no threshold (warning/critical) arguments supplied" ); +} + +unless( defined $p->opts->host ){ + $p->nagios_die( " no host was defined" ); +} + +my $timeout = defined( $p->opts->timeout ) ? $p->opts->timeout : 10; + +my $t = Net::Telnet->new( Timeout => $timeout ); + +if( $p->opts->verbose ){ + print "Printing entire conversation\n"; + $t->input_log( *STDOUT ); +} +$t->open( $p->opts->host ); +$t->waitfor('/Username :/'); +$t->print("SuperUser"); +$t->waitfor('/Password :/'); +$t->print( "O2Br0ad64nd" ); + +$t->waitfor( '/{SuperUser}=>/' ); +$t->print( 'hostmgr list' ); + +my ( $rtn ) = $t->waitfor( '/{SuperUser}=>/' ); + +$t->close(); + +my $rtn2 = " hostmgr list +MAC-address IP-address Flags Type Intf Hw Intf Hostname +----------- ---------- ----- ---- ---- ------- -------- +00:1d:68:ef:bf:86 192.168.1.254 CT Generic IP.Intf.LocalNetwork - localhost (null) +00:02:b3:27:e3:53 - L Generic IP.Intf.LocalNetwork ETH.Phys.ethif2 Unknown-00:02:b3:27:e3:53 (null) +00:1b:63:c1:0c:31 192.168.1.68 DL Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 bens-macbook (null) +00:19:db:ca:9e:2a 192.168.1.72 CDL Generic IP.Intf.LocalNetwork ETH.Phys.ethif3 Emily (null) +00:11:24:07:a1:6e - L Generic - - Unknown-00:11:24:07:a1:6e (null) +00:21:e9:b7:38:a8 - L Generic - - Unknown-00:21:e9:b7:38:a8 (null) +00:16:cb:c5:e2:51 - L Generic - - Unknown-00:16:cb:c5:e2:51 (null) +00:0a:e4:8a:83:24 - L Generic - - Unknown-00:0a:e4:8a:83:24 (null) +00:16:3e:fd:2c:d6 192.168.1.66 CDL Generic IP.Intf.LocalNetwork ETH.Phys.ethif2 Unknown-00:16:3e:fd:2c:d6 (null) +38:e7:d8:03:67:0f - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Unknown-38:e7:d8:03:67:0f (null) +90:27:e4:3a:1d:d0 - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Bens-iPhone-7 (null) +00:10:b5:11:32:1a 192.168.1.171 CD Generic IP.Intf.LocalNetwork ETH.Phys.ethif2 Unknown-00:10:b5:11:32:1a (null) +00:27:10:e9:8e:60 - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 BEAMnrc (null) +58:55:ca:f3:e2:13 - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Unknown-58:55:ca:f3:e2:13 (null) +e8:06:88:98:8a:8b - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Bens-iPad (null) +f0:a2:25:12:d8:f4 - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Unknown-f0:a2:25:12:d8:f4 (null) +00:21:e9:95:ef:fa - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Bens-iPhone (null) +00:22:48:d3:2b:df - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Unknown-00:22:48:d3:2b:df (null) +00:1c:b3:b5:42:58 - Generic IP.Intf.LocalNetwork ETH.Phys.wlif1 Macintosh-195 (null) "; + +my $activecount = 0; + +foreach my $line ( split( m{\n}s, $rtn ) ){ + my( $mac, $ip, $flags ) = $line =~ m{^($macre)\s+(-|$ipre)\s+(\w+)\s+}; + next unless( defined( $ip ) ); + next if( $ip eq '-' ); + + if( $flags =~ m{C} ){ + $activecount++; +# print "Active host: $ip $mac\n"; + } +} + +$p->nagios_exit( + return_code => $p->check_threshold( $activecount ), + message => "$activecount clients connected|clients=$activecount", +);