From 01de64462eb03155f2829ac46ab25214ea93c6bc Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Sat, 17 Nov 2012 16:25:42 +0000 Subject: [PATCH] Adding munin-plugins-local package --- debian/README | 6 ++ debian/changelog | 6 ++ debian/compat | 1 + debian/control | 15 +++++ debian/copyright | 28 +++++++++ debian/docs | 0 debian/rules | 13 ++++ debian/source/format | 1 + plugins/snmp__networkclients | 111 +++++++++++++++++++++++++++++++++++ 9 files changed, 181 insertions(+) create mode 100644 debian/README create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/docs create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100755 plugins/snmp__networkclients diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..e466641 --- /dev/null +++ b/debian/README @@ -0,0 +1,6 @@ +The Debian Package munin-plugins-local +---------------------------- + +This package contains munin plugins for use on michaelhowe.org systems + + -- Michael Howe Sat, 17 Nov 2012 15:44:25 +0000 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..21338b5 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +munin-plugins-local (0.1) unstable; urgency=low + + * Initial Release. + * Single plugin - snmp__networkclients + + -- Michael Howe Sat, 17 Nov 2012 15:44:25 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +8 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9839d60 --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: munin-plugins-local +Section: unknown +Priority: extra +Maintainer: Michael Howe +Build-Depends: debhelper (>= 8.0.0) +Standards-Version: 3.9.3 +Homepage: +#Vcs-Git: git://git.debian.org/collab-maint/munin-plugins-local.git +#Vcs-Browser: http://git.debian.org/?p=collab-maint/munin-plugins-local.git;a=summary + +Package: munin-plugins-local +Architecture: all +Depends: ${misc:Depends} +Description: + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..42fa4c2 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,28 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: munin-plugins-local +Source: none + +Files: * +Copyright: 2012 Michael Howe +License: GPL-3.0+ + +Files: debian/* +Copyright: 2012 Michael Howe +License: GPL-3.0+ + +License: GPL-3.0+ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see . + . + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..b760bee --- /dev/null +++ b/debian/rules @@ -0,0 +1,13 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/plugins/snmp__networkclients b/plugins/snmp__networkclients new file mode 100755 index 0000000..fa1bb66 --- /dev/null +++ b/plugins/snmp__networkclients @@ -0,0 +1,111 @@ +#!/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 Net::Telnet(); +use Regexp::Common qw/net/; + +use Getopt::Long; + +=head1 NAME + +snmp__networkclients - Munin plugin to check the number of clients connected to the gateway + +=head1 APPLICABLE SYSTEMS + +Only O2-provided Thompson routers. + +=head1 CONFIGURATION + +None currently available + +=head1 MAGIC MARKERS + +#%# family=snmpauto +#%# capabilities=snmpconf + +=head1 BUGS + +Uses a lot of code from the nagios plugin check_networkclients; this should +ideally be combined as a module. + +=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.1.254"; + +my ( $verbose ); +GetOptions( "verbose" => \$verbose ); +my $timeout = 15; + +if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') { + exit 0; +} + +if (defined $ARGV[0] and $ARGV[0] eq "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. +users.label devices +users.draw LINE2 +users.info Number of devices +EOC + exit 0; +} + + +my $t = Net::Telnet->new( Timeout => $timeout ); + +if( $verbose ){ + print "Printing entire conversation\n"; + $t->input_log( *STDOUT ); +} +$t->open( $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 $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"; + } +} + +print "hosts.value $activecount\n"; -- 2.39.5