Révision 83a8cfc7
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 | ||
|---|---|---|
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | 17 |
# |
| 18 |
# $Id$ |
|
| 19 |
# |
|
| 20 | 18 |
# Magic markers (used by munin-node-configure and some installation scripts): |
| 21 | 19 |
#%# family=auto |
| 22 | 20 |
#%# capabilities=autoconf |
| ... | ... | |
| 31 | 29 |
|
| 32 | 30 |
=head1 NAME |
| 33 | 31 |
|
| 34 |
tl_sg108e - Plugin to monitor packets per second and link speed for TP-Link SG108E switches
|
|
| 32 |
tl_sg - Plugin to monitor packets per second and link speed for TP-Link SG108E/SG1016E switches
|
|
| 35 | 33 |
|
| 36 | 34 |
=head1 APPLICABLE SYSTEMS |
| 37 | 35 |
|
| 38 |
TP-Link SG108E switches with web management (http). Tested with software version 1.0.2 Build 20160526 Rel.34615
|
|
| 36 |
TP-Link SG108E/SG1016E switches with web management (http). Tested with software version 1.0.2 Build 20160526 Rel.34615 on TL SG108E
|
|
| 39 | 37 |
|
| 40 | 38 |
=head1 CONFIGURATION |
| 41 | 39 |
|
| 42 | 40 |
Add this to the relevant munin-node config file. You can specify switch address, username, password and description for each port |
| 43 | 41 |
(the switch management doesn't allow port descriptions) |
| 44 | 42 |
|
| 45 |
[tl_sg108e] |
|
| 46 |
env.switch 192.168.1.12 |
|
| 43 |
[tl_sg] |
|
| 44 |
env.host 192.168.1.12 |
|
| 45 |
env.port 80 |
|
| 46 |
env.numberOfPorts 8 |
|
| 47 | 47 |
env.username admin |
| 48 | 48 |
env.password mySecretPassword |
| 49 | 49 |
env.p1 'Link to PC1' |
| ... | ... | |
| 55 | 55 |
env.p7 'Not used' |
| 56 | 56 |
env.p8 'Uplink' |
| 57 | 57 |
|
| 58 |
If you're monitoring multiple switches, create different symlinks in /etc/munin/plugins pointing to this plugin and use the symlink |
|
| 59 |
name as a configuration section as described above. |
|
| 60 |
|
|
| 58 | 61 |
Requires WWW:Mechanize module: |
| 59 | 62 |
sudo apt-get install libwww-mechanize-perl |
| 60 | 63 |
|
| ... | ... | |
| 80 | 83 |
|
| 81 | 84 |
=head1 VERSION |
| 82 | 85 |
|
| 83 |
$Id$
|
|
| 86 |
1.1
|
|
| 84 | 87 |
|
| 85 | 88 |
=cut |
| 86 | 89 |
|
| 87 | 90 |
# read parameters from munin |
| 88 |
my $switch = ( $ENV{switch} || '192.168.1.1' );
|
|
| 91 |
my $host = ( $ENV{host} || '192.168.1.1' );
|
|
| 92 |
my $tcpport = ( $ENV{port} || '80' );
|
|
| 89 | 93 |
my $username = ( $ENV{username} || 'admin' );
|
| 90 | 94 |
my $password = ( $ENV{password} || 'admin' );
|
| 91 |
my $numberOfPorts = 8;
|
|
| 95 |
my $numberOfPorts = ( $ENV{numberOfPorts} || '8' );
|
|
| 92 | 96 |
|
| 93 | 97 |
#populate the ports and descriptions based on ENV |
| 94 | 98 |
my %ports = (); |
| ... | ... | |
| 99 | 103 |
} |
| 100 | 104 |
else {
|
| 101 | 105 |
#no description |
| 102 |
$ports{$i} = "";
|
|
| 106 |
$ports{$i} = "Port $i";
|
|
| 103 | 107 |
} |
| 104 | 108 |
} |
| 105 | 109 |
|
| ... | ... | |
| 112 | 116 |
foreach my $graphType (qw/Packets Speed/) {
|
| 113 | 117 |
foreach my $port ( sort keys %ports ) {
|
| 114 | 118 |
print "multigraph ${graphType}_if_$port\n",
|
| 115 |
"graph_title $graphType for $switch port $port $ports{$port}\n",
|
|
| 119 |
"graph_title $graphType for $host port $port $ports{$port}\n",
|
|
| 116 | 120 |
"graph_info $graphType graph for port $port $ports{$port}\n",
|
| 117 | 121 |
"graph_args --base 1000 -l 0\n", |
| 118 | 122 |
"graph_scale yes\n", |
| 119 |
"graph_category switch\n";
|
|
| 123 |
"graph_category network\n";
|
|
| 120 | 124 |
if ( $graphType eq 'Speed' ) {
|
| 121 | 125 |
print "graph_vlabel speed\n"; |
| 122 | 126 |
print "p${port}.label Port $port Link speed\n";
|
| ... | ... | |
| 138 | 142 |
|
| 139 | 143 |
# extract data from the switch - uses web scraping (tested with 1.0.2 Build 20160526 Rel.34615) |
| 140 | 144 |
|
| 141 |
# print STDERR "Connecting to $switch with user $username";
|
|
| 145 |
# print STDERR "Connecting to $host with user $username";
|
|
| 142 | 146 |
my $mech = WWW::Mechanize->new( |
| 143 | 147 |
autocheck => 0, |
| 144 |
requests_redirectable => [ 'GET', 'HEAD', 'POST' ], |
|
| 145 |
user_agent => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0' |
|
| 148 |
requests_redirectable => [ 'GET', 'HEAD', 'POST' ] |
|
| 146 | 149 |
); |
| 147 | 150 |
my $result = $mech->post( |
| 148 |
"http://$switch/logon.cgi",
|
|
| 151 |
"http://$host:$tcpport/logon.cgi",
|
|
| 149 | 152 |
[ username => $username, password => $password, logon => 'Login' ], |
| 150 |
"Referer" => "http://$switch/"
|
|
| 153 |
"Referer" => "http://$host:$tcpport/"
|
|
| 151 | 154 |
); |
| 152 | 155 |
my $response = $mech->response(); |
| 153 | 156 |
|
| 154 | 157 |
# navigate to the page with the network stats |
| 155 |
$result = $mech->get("http://$switch/PortStatisticsRpm.htm");
|
|
| 158 |
$result = $mech->get("http://$host:$tcpport/PortStatisticsRpm.htm");
|
|
| 156 | 159 |
$response = $mech->response(); |
| 157 | 160 |
|
| 158 | 161 |
# print STDERR $response->code()."\n"; |
Formats disponibles : Unified diff