]> git.michaelhowe.org Git - packages/m/munin-plugins-local.git/commitdiff
* Let us track individual MAC addresses
authorMichael Howe <michael@michaelhowe.org>
Tue, 1 Jan 2013 12:50:27 +0000 (12:50 +0000)
committerMichael Howe <michael@michaelhowe.org>
Tue, 1 Jan 2013 12:50:27 +0000 (12:50 +0000)
* Move password into ENV

debian/changelog
plugins/snmp__networkclients

index 186e672ccc577140fe8bee1fbfebc84e3c056b3d..0e235ac662c83dbe5d10ee5c7c46e0961e55ad9d 100644 (file)
@@ -1,3 +1,10 @@
+munin-plugins-local (0.3) unstable; urgency=low
+
+  * Let us track individual MAC addresses
+  * Move password into ENV 
+
+ -- Michael Howe <michael@michaelhowe.org>  Tue, 01 Jan 2013 12:49:27 +0000
+
 munin-plugins-local (0.2) unstable; urgency=low
 
   * Fix inconsistencies in snmp__networkclients
index 0d1934154040eba994e5c23f52f534fe99f86fa0..a2b62ee5f43ae84d5b7df07b643c8cbb3699ad03 100755 (executable)
@@ -55,6 +55,29 @@ my ( $verbose );
 GetOptions( "verbose"   => \$verbose );
 my $timeout = 15;
 
+my $username = $ENV{telnet_user};
+my $password = $ENV{telnet_password};
+
+die "Must define username (in ENV - ie 'env.telnet_user wibble')\n"
+    unless( $username );
+die "Must define password (in ENV - ie 'env.telnet_password wibble')\n"
+    unless( $username );
+
+# Hold individual MAC addresses:
+my %mactypes = (
+    unknown => {
+        addresses => [],
+        count => 0,
+    },
+);
+
+foreach my $type ( grep { /^macs_.+/ } keys( %ENV ) ){
+    my ( $name ) = $type =~ m{^macs_(.+)$};
+    my @values = split( / /, uc( $ENV{$type} ) );
+    $mactypes{$name}->{addresses} = \@values;
+    $mactypes{$name}->{count} = 0;
+}
+
 if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
     exit 0;
 }
@@ -72,6 +95,11 @@ devices.label devices
 devices.draw LINE2
 devices.info Number of devices
 EOC
+    foreach my $type ( keys( %mactypes ) ){
+        print "devices_${type}.label Total devices for ${type}\n";
+        print "devices_${type}.draw LINE2\n";
+        print "devices_${type}.info Number of devices for ${type}\n";
+    }
     exit 0;
 }
 
@@ -84,9 +112,9 @@ if( $verbose ){
 }
 $t->open( $host );
 $t->waitfor('/Username :/');
-$t->print("SuperUser");
+$t->print( $username );
 $t->waitfor('/Password :/');
-$t->print( "O2Br0ad64nd" );
+$t->print( $password );
 
 $t->waitfor( '/{SuperUser}=>/' );
 $t->print( 'hostmgr list' );
@@ -96,6 +124,7 @@ my ( $rtn ) = $t->waitfor( '/{SuperUser}=>/' );
 $t->close();
 
 my $activecount = 0;
+my @activemacs;
 
 foreach my $line ( split( m{\n}s, $rtn ) ){
     my( $mac, $ip, $flags ) = $line =~ m{^($macre)\s+(-|$ipre)\s+(\w+)\s+};
@@ -104,8 +133,24 @@ foreach my $line ( split( m{\n}s, $rtn ) ){
 
     if( $flags =~ m{C} ){
         $activecount++;
+        push @activemacs, uc( $mac );
 #        print "Active host: $ip $mac\n";
     }
 }
 
 print "devices.value $activecount\n";
+my @allocatedmacs;
+foreach my $type ( keys( %mactypes ) ){
+    my $activecount;
+    foreach my $mac ( @activemacs ){
+        if( grep( /$mac/, @{$mactypes{$type}->{addresses}} ) ){
+            $mactypes{$type}->{count}++;
+            push @allocatedmacs, $mac;
+        }
+    }
+}
+$mactypes{unknown}->{count} = ( $#activemacs - $#allocatedmacs );
+
+foreach my $type ( keys( %mactypes ) ){
+    print "devices_${type}.value " . $mactypes{$type}->{count} . "\n";
+}