From 83a8cfc77d37d6fa2d39513c497243c08debbef0 Mon Sep 17 00:00:00 2001 From: adrianp Date: Thu, 12 Apr 2018 16:07:32 +0300 Subject: [PATCH] Cleaned-up documentation, added config option for number of ports, renamed switch ip to hostname, added optional TCP port, changed category from switch to network --- plugins/tplink/tl_sg | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/plugins/tplink/tl_sg b/plugins/tplink/tl_sg index d76d4212..fd333106 100755 --- a/plugins/tplink/tl_sg +++ b/plugins/tplink/tl_sg @@ -15,8 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# $Id$ -# # Magic markers (used by munin-node-configure and some installation scripts): #%# family=auto #%# capabilities=autoconf @@ -31,19 +29,21 @@ use WWW::Mechanize; =head1 NAME -tl_sg108e - Plugin to monitor packets per second and link speed for TP-Link SG108E switches +tl_sg - Plugin to monitor packets per second and link speed for TP-Link SG108E/SG1016E switches =head1 APPLICABLE SYSTEMS -TP-Link SG108E switches with web management (http). Tested with software version 1.0.2 Build 20160526 Rel.34615 +TP-Link SG108E/SG1016E switches with web management (http). Tested with software version 1.0.2 Build 20160526 Rel.34615 on TL SG108E =head1 CONFIGURATION Add this to the relevant munin-node config file. You can specify switch address, username, password and description for each port (the switch management doesn't allow port descriptions) - [tl_sg108e] - env.switch 192.168.1.12 + [tl_sg] + env.host 192.168.1.12 + env.port 80 + env.numberOfPorts 8 env.username admin env.password mySecretPassword env.p1 'Link to PC1' @@ -55,6 +55,9 @@ Add this to the relevant munin-node config file. You can specify switch address, env.p7 'Not used' env.p8 'Uplink' +If you're monitoring multiple switches, create different symlinks in /etc/munin/plugins pointing to this plugin and use the symlink +name as a configuration section as described above. + Requires WWW:Mechanize module: sudo apt-get install libwww-mechanize-perl @@ -80,15 +83,16 @@ dated June, 1991. =head1 VERSION - $Id$ + 1.1 =cut # read parameters from munin -my $switch = ( $ENV{switch} || '192.168.1.1' ); +my $host = ( $ENV{host} || '192.168.1.1' ); +my $tcpport = ( $ENV{port} || '80' ); my $username = ( $ENV{username} || 'admin' ); my $password = ( $ENV{password} || 'admin' ); -my $numberOfPorts = 8; +my $numberOfPorts = ( $ENV{numberOfPorts} || '8' ); #populate the ports and descriptions based on ENV my %ports = (); @@ -99,7 +103,7 @@ for ( 1 .. $numberOfPorts ) { } else { #no description - $ports{$i} = ""; + $ports{$i} = "Port $i"; } } @@ -112,11 +116,11 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { foreach my $graphType (qw/Packets Speed/) { foreach my $port ( sort keys %ports ) { print "multigraph ${graphType}_if_$port\n", - "graph_title $graphType for $switch port $port $ports{$port}\n", + "graph_title $graphType for $host port $port $ports{$port}\n", "graph_info $graphType graph for port $port $ports{$port}\n", "graph_args --base 1000 -l 0\n", "graph_scale yes\n", - "graph_category switch\n"; + "graph_category network\n"; if ( $graphType eq 'Speed' ) { print "graph_vlabel speed\n"; print "p${port}.label Port $port Link speed\n"; @@ -138,21 +142,20 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { # extract data from the switch - uses web scraping (tested with 1.0.2 Build 20160526 Rel.34615) -# print STDERR "Connecting to $switch with user $username"; +# print STDERR "Connecting to $host with user $username"; my $mech = WWW::Mechanize->new( autocheck => 0, - requests_redirectable => [ 'GET', 'HEAD', 'POST' ], - user_agent => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0' + requests_redirectable => [ 'GET', 'HEAD', 'POST' ] ); my $result = $mech->post( - "http://$switch/logon.cgi", + "http://$host:$tcpport/logon.cgi", [ username => $username, password => $password, logon => 'Login' ], - "Referer" => "http://$switch/" + "Referer" => "http://$host:$tcpport/" ); my $response = $mech->response(); # navigate to the page with the network stats -$result = $mech->get("http://$switch/PortStatisticsRpm.htm"); +$result = $mech->get("http://$host:$tcpport/PortStatisticsRpm.htm"); $response = $mech->response(); # print STDERR $response->code()."\n";