2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

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

This commit is contained in:
adrianp 2018-04-12 16:07:32 +03:00
parent c043a89765
commit 83a8cfc77d

View file

@ -15,8 +15,6 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# $Id$
#
# Magic markers (used by munin-node-configure and some installation scripts): # Magic markers (used by munin-node-configure and some installation scripts):
#%# family=auto #%# family=auto
#%# capabilities=autoconf #%# capabilities=autoconf
@ -31,19 +29,21 @@ use WWW::Mechanize;
=head1 NAME =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 =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 =head1 CONFIGURATION
Add this to the relevant munin-node config file. You can specify switch address, username, password and description for each port 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) (the switch management doesn't allow port descriptions)
[tl_sg108e] [tl_sg]
env.switch 192.168.1.12 env.host 192.168.1.12
env.port 80
env.numberOfPorts 8
env.username admin env.username admin
env.password mySecretPassword env.password mySecretPassword
env.p1 'Link to PC1' 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.p7 'Not used'
env.p8 'Uplink' 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: Requires WWW:Mechanize module:
sudo apt-get install libwww-mechanize-perl sudo apt-get install libwww-mechanize-perl
@ -80,15 +83,16 @@ dated June, 1991.
=head1 VERSION =head1 VERSION
$Id$ 1.1
=cut =cut
# read parameters from munin # 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 $username = ( $ENV{username} || 'admin' );
my $password = ( $ENV{password} || 'admin' ); my $password = ( $ENV{password} || 'admin' );
my $numberOfPorts = 8; my $numberOfPorts = ( $ENV{numberOfPorts} || '8' );
#populate the ports and descriptions based on ENV #populate the ports and descriptions based on ENV
my %ports = (); my %ports = ();
@ -99,7 +103,7 @@ for ( 1 .. $numberOfPorts ) {
} }
else { else {
#no description #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 $graphType (qw/Packets Speed/) {
foreach my $port ( sort keys %ports ) { foreach my $port ( sort keys %ports ) {
print "multigraph ${graphType}_if_$port\n", 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_info $graphType graph for port $port $ports{$port}\n",
"graph_args --base 1000 -l 0\n", "graph_args --base 1000 -l 0\n",
"graph_scale yes\n", "graph_scale yes\n",
"graph_category switch\n"; "graph_category network\n";
if ( $graphType eq 'Speed' ) { if ( $graphType eq 'Speed' ) {
print "graph_vlabel speed\n"; print "graph_vlabel speed\n";
print "p${port}.label Port $port Link 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) # 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( my $mech = WWW::Mechanize->new(
autocheck => 0, autocheck => 0,
requests_redirectable => [ 'GET', 'HEAD', 'POST' ], requests_redirectable => [ 'GET', 'HEAD', 'POST' ]
user_agent => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0'
); );
my $result = $mech->post( my $result = $mech->post(
"http://$switch/logon.cgi", "http://$host:$tcpport/logon.cgi",
[ username => $username, password => $password, logon => 'Login' ], [ username => $username, password => $password, logon => 'Login' ],
"Referer" => "http://$switch/" "Referer" => "http://$host:$tcpport/"
); );
my $response = $mech->response(); my $response = $mech->response();
# navigate to the page with the network stats # 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(); $response = $mech->response();
# print STDERR $response->code()."\n"; # print STDERR $response->code()."\n";