]> git.michaelhowe.org Git - packages/m/munin-plugins-local.git/commitdiff
New snmp__sky_router_ plugin, for sky router querying
authorMichael Howe <michael@michaelhowe.org>
Sat, 14 Sep 2013 17:24:24 +0000 (17:24 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sat, 14 Sep 2013 17:24:24 +0000 (17:24 +0000)
Makefile
debian/changelog
debian/control
plugins/snmp__sky_router_ [new file with mode: 0755]

index f4615591845cadd0bbd607fcbbbe39d07224f15d..6af094aa1b0fb8e5f7ced6c2e1da8e0f80b346d4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,5 @@ build:
 install:
        $(INSTALL) -d $(DSTPLUGINDIR)
        $(INSTALL) -m 0755 $(PLUGINDIR)/* $(DSTPLUGINDIR)
-       $(INSTALL) -m 0755 $(PLUGINDIR)/nv_gpu_ $(DSTPLUGINDIR)
-       $(INSTALL) -m 0755 $(PLUGINDIR)/unbound_munin_ $(DSTPLUGINDIR)
 
 .PHONY: install
index 548f2436520b57cdff3ec49a1139c450a1cc5b35..9cabb83fb6d9c4eee2348510b190af1377fd5f88 100644 (file)
@@ -1,3 +1,9 @@
+munin-plugins-local (0.8) UNRELEASED; urgency=low
+
+  * Add snmp__sky_router_ for network clients and bandwidth usage 
+
+ -- Michael Howe <michael@michaelhowe.org>  Sat, 14 Sep 2013 18:20:35 +0100
+
 munin-plugins-local (0.7) unstable; urgency=low
 
   * Make libxml-fast-perl a recommends not depends, since it's not in squeeze 
index cd2cca90ddd43c612a35ab9ee99e5db0adcd8ff9..6da35c134d8b37ae01d84eabfd9b4d5bc4407cbe 100644 (file)
@@ -10,7 +10,7 @@ Standards-Version: 3.9.3
 Package: munin-plugins-local
 Architecture: all
 Depends: munin-node, ${misc:Depends}
-Recommends: nvidia-smi, smartctl, libxml-fast-perl
+Recommends: nvidia-smi, smartctl, libxml-fast-perl, libhtml-tree-perl
 Suggests: python
 Description: network-wide graphing framework (local plugins for node)
  Extra plugins for munin-node, for use on michaelhowe.org machines.
diff --git a/plugins/snmp__sky_router_ b/plugins/snmp__sky_router_
new file mode 100755 (executable)
index 0000000..402f815
--- /dev/null
@@ -0,0 +1,198 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+#
+# $HeadURL$
+# $LastChangedRevision$
+# $LastChangedDate$
+# $LastChangedBy$
+#
+
+# Not actually an SNMP plugin, but instead a horrible hack to pretend to be
+use Munin::Plugin;
+use Munin::Plugin::SNMP;
+use Regexp::Common qw/net/;
+use WWW::Mechanize;
+use HTML::TreeBuilder;
+
+use Getopt::Long;
+
+=head1 NAME
+
+snmp__sky_router_ - Munin plugin to check the number of clients connected to the gateway
+
+=head1 APPLICABLE SYSTEMS
+
+Only Sky-provided routers
+
+=head1 CONFIGURATION
+
+None currently available
+
+=head1 MAGIC MARKERS
+
+#%# family=snmpauto
+#%# capabilities=snmpconf
+
+=head1 BUGS
+
+=head1 AUTHORS
+
+Michael Howe
+
+=cut
+
+my $macre = $RE{net}{MAC};
+my $ipre = $RE{net}{IPv4};
+
+# All we care about is the host:
+#my ( $host ) = Munin::Plugin::SNMP->config_session();
+my $host = "192.168.5.1";
+
+my ( $verbose );
+GetOptions( "verbose"   => \$verbose );
+my $user = $ENV{user};
+my $pass = $ENV{password};
+
+# Multiple options:
+# * Traffic rate
+# * Connected devices
+
+my $basename = $0;
+$basename =~ m{.*_[^_]+$};
+
+$basename = 'devices';
+
+my $config = ( defined $ARGV[0] and $ARGV[0] eq 'config' );
+
+if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
+    exit 0;
+}
+
+if( $basename eq 'rate' ){
+    get_rate();
+} elsif( $basename eq 'devices' ){
+    get_devices();
+} else {
+    die "Incorrect option: '$basename'\n";
+}
+
+sub get_rate {
+    my $url = "http://$host/sky_system.html";
+    my $mech = WWW::Mechanize->new();
+    my %rates;
+
+    $mech->credentials($user, $pass);
+    $mech->get( $url );
+    my $root = HTML::TreeBuilder->new_from_content( $mech->content() );
+    my $table = $root->look_down('_tag', 'table');
+    foreach my $row ( $table->look_down('_tag', 'tr') ){
+        my $title = $row->look_down('_tag', 'th')->as_text;
+        next if( $title eq 'Port ' );
+
+        my ( $tx, $rx ) = ( $row->look_down('_tag', 'td') )[4,5];
+        $rates{$title} = {
+            tx => $tx->as_text,
+            rx => $rx->as_text,
+        };
+    }
+
+    if( $config ){
+        print "host_name $host\n" unless $host eq 'localhost';
+        print <<"EOC";
+graph_title Network rate
+graph_args --base 1024 -l 0
+graph_vlabel bandwidth
+graph_category network
+graph_info This graph shows the traffic of the interfaces
+EOC
+        foreach my $rate ( keys( %rates ) ){
+            print <<"EOC";
+rate_${rate}_rx.label $rate rx
+rate_${rate}_rx.draw LINE2
+rate_${rate}_rx.info Rx b/s for $rate
+rate_${rate}_tx.label $rate tx
+rate_${rate}_tx.draw LINE2
+rate_${rate}_tx.info Tx b/s for $rate
+EOC
+        }
+    } else {
+        foreach my $rate ( keys( %rates ) ){
+            print <<"EOC";
+rate_${rate}_rx.value $rates{$rate}->{rx}
+rate_${rate}_tx.value $rates{$rate}->{tx}
+EOC
+        }
+    }
+}
+
+
+sub get_devices {
+    my $url = "http://$host/sky_index.html";
+    my $mech = WWW::Mechanize->new();
+
+    # 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( $config ){
+
+        print "host_name $host\n" unless $host eq 'localhost';
+        print <<"EOC";
+graph_title Number of devices
+graph_args --base 1000 -l 0 
+graph_vlabel number of devices
+graph_scale no
+graph_category system
+graph_info This graph shows the number of devices currently connected to the system.
+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";
+        }
+    } else {
+
+        my @activemacs;
+
+        $mech->get( $url );
+        my ( $devices_text ) = $mech->content() =~ m{var i,j,k,attach_dev='([^']+)';};
+        my @devices = split( /<lf>/, $devices_text );
+
+        foreach my $device ( @devices ){
+            my ( $name, $mac, $connection ) = split( /,/, $device );
+            push @activemacs, $mac;
+        }
+
+        
+        my @allocatedmacs;
+        foreach my $type ( keys( %mactypes ) ){
+            my $activecount;
+            foreach my $mac ( @activemacs ){
+                if( grep( /$mac/i, @{$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";
+        }
+    }
+}