mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
Merge branch 'ent-fix-pandora_snmp_bandwidth-plugin' into 'develop'
bugfix about pandora_snmp_bandwith.pl See merge request artica/pandorafms!5295
This commit is contained in:
commit
5dab41df36
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Bandwith usage plugin
|
# Bandwidth usage plugin
|
||||||
#
|
#
|
||||||
# Requirements:
|
# Requirements:
|
||||||
# snmpget
|
# snmpget
|
||||||
@ -55,7 +55,7 @@ Where OPTIONS could be:
|
|||||||
|
|
||||||
[EXTRA]
|
[EXTRA]
|
||||||
-ifIndex Target interface to retrieve, if not specified, total
|
-ifIndex Target interface to retrieve, if not specified, total
|
||||||
bandwith will be reported.
|
bandwidth will be reported.
|
||||||
-uniqid Use custom temporary file name.
|
-uniqid Use custom temporary file name.
|
||||||
-inUsage Show only input usage (in percentage) - 1, or not 0.
|
-inUsage Show only input usage (in percentage) - 1, or not 0.
|
||||||
-outUsage Show only output usage (in percentage) - 1, or not 0.
|
-outUsage Show only output usage (in percentage) - 1, or not 0.
|
||||||
@ -66,7 +66,7 @@ e.g. -v is equal to -version, -c to -community, etc.
|
|||||||
EO_HELP
|
EO_HELP
|
||||||
|
|
||||||
use constant {
|
use constant {
|
||||||
UNKNOWN_DUPLEX => 0,
|
UNKNOWN_DUPLEX => 1,
|
||||||
HALF_DUPLEX => 2,
|
HALF_DUPLEX => 2,
|
||||||
FULL_DUPLEX => 3,
|
FULL_DUPLEX => 3,
|
||||||
};
|
};
|
||||||
@ -133,9 +133,9 @@ sub update_config_key ($) {
|
|||||||
if ($arg eq 'inUsage') {
|
if ($arg eq 'inUsage') {
|
||||||
return "inUsage";
|
return "inUsage";
|
||||||
}
|
}
|
||||||
if ($arg eq 'outUsage') {
|
if ($arg eq 'outUsage') {
|
||||||
return "outUsage";
|
return "outUsage";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -188,7 +188,7 @@ sub prepare_tree {
|
|||||||
|
|
||||||
my $inOctets = snmp_get(\%inOctets_call);
|
my $inOctets = snmp_get(\%inOctets_call);
|
||||||
if (ref($inOctets) eq "HASH") {
|
if (ref($inOctets) eq "HASH") {
|
||||||
if ($inOctets->{'data'} eq '') {
|
if (! exists($inOctets->{'data'}) || $inOctets->{'data'} eq '') {
|
||||||
$inOctets = 0;
|
$inOctets = 0;
|
||||||
} else {
|
} else {
|
||||||
$inOctets = int $inOctets->{'data'};
|
$inOctets = int $inOctets->{'data'};
|
||||||
@ -198,18 +198,18 @@ sub prepare_tree {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %outOctets_call = %{$config};
|
my %outOctets_call = %{$config};
|
||||||
if (is_enabled($config->{'use_x64'})) {
|
if (is_enabled($config->{'use_x64'})) {
|
||||||
$outOctets_call{'oid'} = $config->{'oid_base'};
|
$outOctets_call{'oid'} = $config->{'oid_base'};
|
||||||
$outOctets_call{'oid'} .= $config->{'x64_indexes'}{'outOctets'}.$ifIndex;
|
$outOctets_call{'oid'} .= $config->{'x64_indexes'}{'outOctets'}.$ifIndex;
|
||||||
} else {
|
} else {
|
||||||
$outOctets_call{'oid'} = $config->{'oid_base'};
|
$outOctets_call{'oid'} = $config->{'oid_base'};
|
||||||
$outOctets_call{'oid'} .= $config->{'x86_indexes'}{'outOctets'}.$ifIndex;
|
$outOctets_call{'oid'} .= $config->{'x86_indexes'}{'outOctets'}.$ifIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $outOctets = snmp_get(\%outOctets_call);
|
my $outOctets = snmp_get(\%outOctets_call);
|
||||||
if (ref($outOctets) eq "HASH") {
|
if (ref($outOctets) eq "HASH") {
|
||||||
if ($outOctets->{'data'} eq '') {
|
if (! exists($outOctets->{'data'}) || $outOctets->{'data'} eq '') {
|
||||||
$outOctets = 0;
|
$outOctets = 0;
|
||||||
} else {
|
} else {
|
||||||
$outOctets = int $outOctets->{'data'};
|
$outOctets = int $outOctets->{'data'};
|
||||||
@ -220,28 +220,27 @@ sub prepare_tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my %duplex_call = %{$config};
|
my %duplex_call = %{$config};
|
||||||
if (is_enabled($config->{'use_x64'})) {
|
if (is_enabled($config->{'use_x64'})) {
|
||||||
$duplex_call{'oid'} = $config->{'oid_base'};
|
$duplex_call{'oid'} = $config->{'oid_base'};
|
||||||
$duplex_call{'oid'} .= $config->{'x64_indexes'}{'duplex'}.$ifIndex;
|
$duplex_call{'oid'} .= $config->{'x64_indexes'}{'duplex'}.$ifIndex;
|
||||||
} else {
|
} else {
|
||||||
$duplex_call{'oid'} = $config->{'oid_base'};
|
$duplex_call{'oid'} = $config->{'oid_base'};
|
||||||
$duplex_call{'oid'} .= $config->{'x86_indexes'}{'duplex'}.$ifIndex;
|
$duplex_call{'oid'} .= $config->{'x86_indexes'}{'duplex'}.$ifIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $duplex = snmp_get(\%duplex_call);
|
my $duplex = snmp_get(\%duplex_call);
|
||||||
if (ref($duplex) eq "HASH") {
|
if (ref($duplex) eq "HASH") {
|
||||||
if ($duplex->{'data'} eq '') {
|
if (! exists($duplex->{'data'}) || $duplex->{'data'} eq '') {
|
||||||
$duplex = 0;
|
$duplex = 0;
|
||||||
} else {
|
} else {
|
||||||
$duplex = int $duplex->{'data'};
|
$duplex = int $duplex->{'data'};
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
# Ignore, cannot retrieve inOctets.
|
# Ignore, cannot retrieve inOctets.
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %speed = %{$config};
|
my %speed = %{$config};
|
||||||
if (is_enabled($config->{'use_x64'})) {
|
if (is_enabled($config->{'use_x64'})) {
|
||||||
$speed{'oid'} = $config->{'oid_base'};
|
$speed{'oid'} = $config->{'oid_base'};
|
||||||
$speed{'oid'} .= $config->{'x64_indexes'}{'ifSpeed'}.$ifIndex;
|
$speed{'oid'} .= $config->{'x64_indexes'}{'ifSpeed'}.$ifIndex;
|
||||||
@ -492,9 +491,9 @@ $config->{'tmp_separator'} = ';' if empty($config->{'tmp_separator'});
|
|||||||
$config->{'tmp'} = (($^O =~ /win/)?$ENV{'TMP'}:'/tmp') if empty($config->{'tmp'});
|
$config->{'tmp'} = (($^O =~ /win/)?$ENV{'TMP'}:'/tmp') if empty($config->{'tmp'});
|
||||||
|
|
||||||
# Create unique name for tmp and log file for host
|
# Create unique name for tmp and log file for host
|
||||||
my $filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'host'};
|
my $filename = $config->{'tmp'}.'/pandora_bandwidth_'.$config->{'host'};
|
||||||
if (!empty($config->{'uniqid'})) {
|
if (!empty($config->{'uniqid'})) {
|
||||||
$filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'uniqid'};
|
$filename = $config->{'tmp'}.'/pandora_bandwidth_'.$config->{'uniqid'};
|
||||||
}
|
}
|
||||||
# Replace every dot for underscore
|
# Replace every dot for underscore
|
||||||
$filename =~ tr/./_/;
|
$filename =~ tr/./_/;
|
||||||
@ -511,7 +510,7 @@ if ( defined($sysobjectid->{'error'}) || $sysobjectid->{'data'} eq '' ) {
|
|||||||
|
|
||||||
# Check SNMP x64 interfaces
|
# Check SNMP x64 interfaces
|
||||||
my $walk64 = snmp_walk({%{$config}, 'oid' => '.1.3.6.1.2.1.31.1.1.1.6'});
|
my $walk64 = snmp_walk({%{$config}, 'oid' => '.1.3.6.1.2.1.31.1.1.1.6'});
|
||||||
if ( $walk64 =~ 'No Such Instance currently exists at this OID' || $walk64 =~ 'No more variables left in this MIB View') {
|
if ( $walk64 !~ /.*\.[0-9]+ = Counter64: [0-9]+/ ) {
|
||||||
$config->{'use_x64'} = 0;
|
$config->{'use_x64'} = 0;
|
||||||
} else {
|
} else {
|
||||||
$config->{'use_x64'} = 1;
|
$config->{'use_x64'} = 1;
|
||||||
@ -556,35 +555,35 @@ my $j = 0;
|
|||||||
my $k = 0;
|
my $k = 0;
|
||||||
foreach my $iface (keys %{$analysis_tree}) {
|
foreach my $iface (keys %{$analysis_tree}) {
|
||||||
# Calculate summary;
|
# Calculate summary;
|
||||||
if (is_enabled($analysis_tree->{$iface}{'bandwidth'})) {
|
if (is_enabled($analysis_tree->{$iface}{'bandwidth'}) || $analysis_tree->{$iface}{'bandwidth'} == 0) {
|
||||||
$bandwidth = $analysis_tree->{$iface}{'bandwidth'};
|
$bandwidth += $analysis_tree->{$iface}{'bandwidth'};
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
if (is_enabled($analysis_tree->{$iface}{'inUsage'})) {
|
if (is_enabled($analysis_tree->{$iface}{'inUsage'}) || $analysis_tree->{$iface}{'inUsage'} == 0) {
|
||||||
$inUsage = $analysis_tree->{$iface}{'inUsage'};
|
$inUsage += $analysis_tree->{$iface}{'inUsage'};
|
||||||
$j++;
|
$j++;
|
||||||
}
|
}
|
||||||
if (is_enabled($analysis_tree->{$iface}{'outUsage'})) {
|
if (is_enabled($analysis_tree->{$iface}{'outUsage'}) || $analysis_tree->{$iface}{'inUsage'} == 0) {
|
||||||
$outUsage = $analysis_tree->{$iface}{'outUsage'};
|
$outUsage += $analysis_tree->{$iface}{'outUsage'};
|
||||||
$k++;
|
$k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($j > 0 && is_enabled($config->{'inUsage'})) {
|
if ($j > 0 && is_enabled($config->{'inUsage'})) {
|
||||||
$inUsage /= $j;
|
$inUsage /= $j;
|
||||||
print sprintf("%.9f\n", $inUsage);
|
print sprintf("%.9f\n", $inUsage);
|
||||||
} elsif ($k > 0 && is_enabled($config->{'outUsage'})) {
|
} elsif ($k > 0 && is_enabled($config->{'outUsage'})) {
|
||||||
$outUsage /= $k;
|
$outUsage /= $k;
|
||||||
print sprintf("%.9f\n", $outUsage);
|
print sprintf("%.9f\n", $outUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i > 0
|
if ($i > 0
|
||||||
&& !is_enabled($config->{'inUsage'})
|
&& !is_enabled($config->{'inUsage'})
|
||||||
&& !is_enabled($config->{'outUsage'})
|
&& !is_enabled($config->{'outUsage'})
|
||||||
) {
|
) {
|
||||||
$bandwidth /= $i;
|
$bandwidth /= $i;
|
||||||
print sprintf("%.9f\n", $bandwidth);
|
print sprintf("%.9f\n", $bandwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger($config, 'info', "Plugin ends") if (is_enabled($config->{'debug'}));
|
logger($config, 'info', "Plugin ends") if (is_enabled($config->{'debug'}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user