1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

network/snmp__ifx_: encode UTF-8 and with Unix newlines

This commit is contained in:
Kenyon Ralph 2012-05-04 02:03:34 -07:00
parent dd6dcd8728
commit b084f05b70

View file

@ -1,164 +1,164 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Copyright (C) 2008 François Borlet-Hote # Copyright (C) 2008 François Borlet-Hote
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June, # as published by the Free Software Foundation; version 2 dated June,
# 1991. # 1991.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
# $Log$ # $Log$
# #
# Based on snmp_if from the Revision 1.18 2004/12/10 18:51:43 by jimmyo # Based on snmp_if from the Revision 1.18 2004/12/10 18:51:43 by jimmyo
# #
# Revision 1.0 2008/05/29 16:10:00 fbh # Revision 1.0 2008/05/29 16:10:00 fbh
# Created by fbh # Created by fbh
# #
# #
#%# family=snmpauto #%# family=snmpauto
#%# capabilities=snmpconf #%# capabilities=snmpconf
use strict; use strict;
use Net::SNMP; use Net::SNMP;
my $DEBUG = 0; my $DEBUG = 0;
my $host = $ENV{host} || undef; my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161; my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public"; my $community = $ENV{community} || "public";
my $iface = $ENV{interface} || undef; my $iface = $ENV{interface} || undef;
my $version = $ENV{version} || "2c"; my $version = $ENV{version} || "2c";
my $response; my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{ {
print "number 1.3.6.1.2.1.2.1.0\n"; print "number 1.3.6.1.2.1.2.1.0\n";
print "index 1.3.6.1.2.1.2.2.1.1.\n"; print "index 1.3.6.1.2.1.2.2.1.1.\n";
print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type
print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
exit 0; exit 0;
} }
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_ifX_(.+)$/) if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_ifX_(.+)$/)
{ {
$host = $1; $host = $1;
$iface = $2; $iface = $2;
if ($host =~ /^([^:]+):(\d+)$/) if ($host =~ /^([^:]+):(\d+)$/)
{ {
$host = $1; $host = $1;
$port = $2; $port = $2;
} }
} }
elsif (!defined($host)) elsif (!defined($host))
{ {
print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor."; die "# Error: couldn't understand what I'm supposed to monitor.";
} }
my $ifEntryDescr = "1.3.6.1.2.1.2.2.1.2.$iface"; my $ifEntryDescr = "1.3.6.1.2.1.2.2.1.2.$iface";
my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface"; my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface";
my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface"; my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryInOctets = "1.3.6.1.2.1.31.1.1.1.6.$iface"; my $ifEntryInOctets = "1.3.6.1.2.1.31.1.1.1.6.$iface";
my $ifEntryOutOctets = "1.3.6.1.2.1.31.1.1.1.10.$iface"; my $ifEntryOutOctets = "1.3.6.1.2.1.31.1.1.1.10.$iface";
my ($session, $error) = Net::SNMP->session( my ($session, $error) = Net::SNMP->session(
-hostname => $host, -hostname => $host,
-community => $community, -community => $community,
-port => $port, -port => $port,
-version => $version -version => $version
); );
if (!defined ($session)) if (!defined ($session))
{ {
die "Croaking: $error"; die "Croaking: $error";
} }
if ($ARGV[0] and $ARGV[0] eq "config") if ($ARGV[0] and $ARGV[0] eq "config")
{ {
print "host_name $host\n"; print "host_name $host\n";
if (!defined ($response = $session->get_request($ifEntryDescr))) if (!defined ($response = $session->get_request($ifEntryDescr)))
{ {
die "Croaking: " . $session->error(); die "Croaking: " . $session->error();
} }
my $name = $response->{$ifEntryDescr}; my $name = $response->{$ifEntryDescr};
$name =~ s/[^\w\s]//g; $name =~ s/[^\w\s]//g;
my $warn = undef; my $warn = undef;
my $max = 1000000000; my $max = 1000000000;
if (defined ($response = $session->get_request($ifEntrySpeed))) if (defined ($response = $session->get_request($ifEntrySpeed)))
{ {
$max = $response->{$ifEntrySpeed}; $max = $response->{$ifEntrySpeed};
$warn = $response->{$ifEntrySpeed}*0.8; $warn = $response->{$ifEntrySpeed}*0.8;
} }
if (length ($name) > 15) if (length ($name) > 15)
{ {
print "graph_title Interface $iface traffic\n"; print "graph_title Interface $iface traffic\n";
} }
else else
{ {
print "graph_title Interface $name traffic\n"; print "graph_title Interface $name traffic\n";
} }
print "graph_order recv send\n"; print "graph_order recv send\n";
print "graph_args --base 1000\n"; print "graph_args --base 1000\n";
print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n"; print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
print "graph_category network\n"; print "graph_category network\n";
print "graph_info This graph shows traffic for the \"$name\" network interface.\n"; print "graph_info This graph shows traffic for the \"$name\" network interface.\n";
print "send.info Bits sent/received by this interface.\n"; print "send.info Bits sent/received by this interface.\n";
print "recv.label recv\n"; print "recv.label recv\n";
print "recv.type DERIVE\n"; print "recv.type DERIVE\n";
print "recv.graph no\n"; print "recv.graph no\n";
print "recv.cdef recv,8,*\n"; print "recv.cdef recv,8,*\n";
print "recv.max ",$max,"\n"; print "recv.max ",$max,"\n";
print "recv.min 0\n"; print "recv.min 0\n";
print "recv.warn ", (-$warn), "\n" if defined $warn; print "recv.warn ", (-$warn), "\n" if defined $warn;
print "send.label bps\n"; print "send.label bps\n";
print "send.type DERIVE\n"; print "send.type DERIVE\n";
print "send.negative recv\n"; print "send.negative recv\n";
print "send.cdef send,8,*\n"; print "send.cdef send,8,*\n";
print "send.max ",$max,"\n"; print "send.max ",$max,"\n";
print "send.min 0\n"; print "send.min 0\n";
print "send.warn $warn\n" if defined $warn; print "send.warn $warn\n" if defined $warn;
exit 0; exit 0;
} }
my $status = 1; my $status = 1;
if (defined ($response = $session->get_request($ifEntryStatus))) if (defined ($response = $session->get_request($ifEntryStatus)))
{ {
$status = $response->{$ifEntryStatus}; $status = $response->{$ifEntryStatus};
} }
if ($status == 2) if ($status == 2)
{ {
print "recv.value U\n"; print "recv.value U\n";
print "send.value U\n"; print "send.value U\n";
exit 0; exit 0;
} }
if (defined ($response = $session->get_request($ifEntryInOctets))) if (defined ($response = $session->get_request($ifEntryInOctets)))
{ {
print "recv.value ", $response->{$ifEntryInOctets}, "\n"; print "recv.value ", $response->{$ifEntryInOctets}, "\n";
} }
else else
{ {
print "recv.value U\n"; print "recv.value U\n";
} }
if (defined ($response = $session->get_request($ifEntryOutOctets))) if (defined ($response = $session->get_request($ifEntryOutOctets)))
{ {
print "send.value ", $response->{$ifEntryOutOctets}, "\n"; print "send.value ", $response->{$ifEntryOutOctets}, "\n";
} }
else else
{ {
print "send.value U\n"; print "send.value U\n";
} }