]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
Added new check_networkclients script
authorMichael Howe <michael@michaelhowe.org>
Tue, 20 Mar 2012 21:34:29 +0000 (21:34 +0000)
committerMichael Howe <michael@michaelhowe.org>
Tue, 20 Mar 2012 21:34:29 +0000 (21:34 +0000)
Makefile
debian/changelog
debian/control
plugins/check_networkclients [new file with mode: 0755]

index c40c57a803996d20cae15dcbd56289bf7a420159..346b3edb97b172e587defc03fd983fa2ca5e7792 100644 (file)
--- 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
index 2543a01ae472a17d79d3b06fb8f1d4fa19ebe836..6ba7bc0aa51741fe368a6bdaea1b1e07614b1702 100644 (file)
@@ -1,3 +1,9 @@
+nagios-plugins-local (0.6) unstable; urgency=low
+
+  * Added check_networkclients plugin 
+
+ -- Michael Howe <michael@michaelhowe.org>  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
index 9d9ee3f92b3071b8806dddab38f9c762fc3d36c6..82ca05bb4c026d8e8f8cbc841e335fd80771387a 100644 (file)
@@ -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 (executable)
index 0000000..44bfb11
--- /dev/null
@@ -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 <host>] [-t <timeout>]
+    [ -c|--critical=<critical threshold>]
+    [ -w|--warning=<warning threshold>]",
+    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",
+);