delete $snmpinfo->{$if} if exists $snmpinfo->{$if};
delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if};
return;
}
}
if (defined ($response = $snmpinfo->{$if}->{ifOperStatus})) {
# 1 = up, 2 = down, 7 = lowerLayerDown
if ($response == 2 or $response == 7) {
# Fold recognized down states into one.
$response = $snmpinfo->{$if}->{ifOperStatus} = 2;
} elsif ($response != 1) {
# This interface is fishy, remove and forget.
delete $snmpinfo->{$if} if exists $snmpinfo->{$if};
delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if};
return;
}
}
}
sub do_preprocess {
my $mediatypes = 'ethernetCsmacd';
if (exists( $ENV{'ifTypeOnly'} )) {
$mediatypes = $ENV{'ifTypeOnly'};
}
my @mediatypes = split(/[ ,]+/,$mediatypes);
# Hash of numerical media types the user finds interesting.
my $mediatype={};
if ($mediatypes eq 'ALL') {
$mediatype = undef;
} else {
foreach my $type (@mediatypes) {
if (exists($ifTypes{$type})) {
$mediatype->{$ifTypes{$type}} = 1;
} else {
die "Unknown media type '$type' specified in ifTypeOnly\n";
}
}
}
foreach my $if (keys %{$snmpinfo}) {
do_preprocess_if($mediatype, $if);
}
}
sub do_config_root {
my ($host, $version) = @_;
my $extrainfo="";
if (defined ($snmpinfoX->{0}->{ifHCInOctets})) {
# If we get an answer at the 64 bit OID then this switch
# supports the extended MIB
$extrainfo .= " This switch supports 64 bit byte counters and these are used by this plugin.";
} else {
# If not we only have a 32 bit counter and are lost.
$extrainfo .= " NOTE! This switch supports only 32 bit byte counters which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that for interfaces where much traffic is sent this plugin will report false thruputs and cannot be trusted.";
# unless perhaps the operator can get us snmp version 2c or 3?
$extrainfo .= " I notice that you use SNMP version 1 which does not support 64 bit quantities. You may get better results if you switch to SNMP version 2c or 3. Please refer to the plugin documentation."
if $version == 1;
}
print "graph_title $host interfaces traffic\n";
print "graph_args --base 1000\n";
print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
print "graph_category network\n";
print "graph_info This graph shows the total traffic for $host.$extrainfo\n";
}
sub do_config_if {
my ($host,$version,$if) = @_;
my $alias = $snmpinfo->{$if}->{ifDescr} || "Interface $if";
if (! ($alias =~ /\d+/) ) {
# If there are no numbers in the $alias add the if index
$alias .=" (if $if)";
}
my $warn = undef;
my $speed = 0;
my $extrainfo = "";
if (defined ($speed = $snmpinfoX->{$if}->{ifHighSpeed}) and $speed) {
# Speed in 1,000,000 bits per second
$speed = $speed * 1000000;
$warn = $speed / 75 * 100;
my $textspeed = scaleNumber($speed,'bps','',
'The interface speed is %.1f%s%s.');
$extrainfo .= ' '.$textspeed if $textspeed;
} elsif (defined ($speed = $snmpinfo->{$if}->{ifSpeed}) and $speed) {
# Speed in bits pr. second
$warn = $speed*100/75;
my $textspeed = scaleNumber($speed,'bps','',
'The interface speed is %.1f%s%s.');
$extrainfo .= " ".$textspeed if $textspeed;
}
$response = $snmpinfo->{$if}->{ifType};
print "recv$if.label $alias\n";
print "recv$if.type DERIVE\n";
print "recv$if.graph no\n";
print "recv$if.cdef recv$if,8,*\n";
print "recv$if.max $speed\n" if $speed;
print "recv$if.min 0\n";
print "recv$if.warning ", (-$warn), "\n" if defined $warn;
print "send$if.label $alias\n";
print "send$if.type DERIVE\n";
print "send$if.negative recv$if\n";
print "send$if.cdef send$if,8,*\n";
print "send$if.max $speed\n" if $speed;
print "send$if.min 0\n";
print "send$if.warning $warn\n" if defined $warn;
}
sub do_fetch_if {
my($if) = @_;
my $status = $snmpinfo->{$if}->{ifOperStatus} || 1;
my $response;
# 1 means up
# 2 means set to down
# Everything else we ignore.
if ($status == 2) {
# Interface is down
print "recv$if.value U\n";
print "send$if.value U\n";
print "send$if.extinfo This interface is currently down.\n";
return;
}
if (defined ($response = $snmpinfoX->{$if}->{ifHCInOctets} ||
$snmpinfo->{$if}->{ifInOctets})) {
print "recv$if.value ", $response, "\n";
} else {
# No response...
print "recv$if.value U\n";
}
if (defined ($response = $snmpinfoX->{$if}->{ifHCOutOctets} ||
$snmpinfo->{$if}->{ifOutOctets})) {
print "send$if.value ", $response, "\n";
} else {
# No response...
print "send$if.value U\n";
}
}
sub do_config {
my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();