From: Michael Howe Date: Tue, 1 Jan 2013 12:50:27 +0000 (+0000) Subject: * Let us track individual MAC addresses X-Git-Tag: 0.3~1 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=e6637e353e1fad1218f5c5f114c5ad13d94757f0;p=packages%2Fm%2Fmunin-plugins-local.git * Let us track individual MAC addresses * Move password into ENV --- diff --git a/debian/changelog b/debian/changelog index 186e672..0e235ac 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +munin-plugins-local (0.3) unstable; urgency=low + + * Let us track individual MAC addresses + * Move password into ENV + + -- Michael Howe Tue, 01 Jan 2013 12:49:27 +0000 + munin-plugins-local (0.2) unstable; urgency=low * Fix inconsistencies in snmp__networkclients diff --git a/plugins/snmp__networkclients b/plugins/snmp__networkclients index 0d19341..a2b62ee 100755 --- a/plugins/snmp__networkclients +++ b/plugins/snmp__networkclients @@ -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"; +}