From 376a46a925623923a9f8cfe9a748c2b07e8b5589 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 11 Feb 2021 13:28:13 +0100 Subject: [PATCH 1/8] WIP extra modules for interfaces wizard --- .../include/class/AgentWizard.class.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index d9a42b7cfa..6a852dd6af 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -972,6 +972,16 @@ class AgentWizard extends HTML if (isset($unicastIpReferences[$indexKey]) === true) { $interfaces[$indexKey]['ip'] = ''; } + + // Get interface alias. + $interfaces[$indexKey]['alias'] = $this->snmpgetValue( + '.1.3.6.1.2.1.31.1.1.1.18.'.$indexKey + ); + + // Get interface speed. + $interfaces[$indexKey]['speed'] = $this->snmpgetValue( + '.1.3.6.1.2.1.2.2.1.5.'.$indexKey + ); } // Save the interfaces found for process later. @@ -4291,6 +4301,12 @@ class AgentWizard extends HTML $moduleDescription .= ''; } + if (empty($data['alias']) === false) { + $moduleDescription .= 'Alias: '.$data['alias'].' - '; + } else { + $moduleDescription .= ''; + } + $name = $data['name'].'_'; $value = $data['index']; } @@ -4402,6 +4418,32 @@ class AgentWizard extends HTML $definition = array_merge($definition, $definition_temp); } + // LocIfInCRC. + $moduleName = $name.'locIfInCRC'; + $definition['locIfInCRC'] = [ + 'module_name' => $moduleName, + 'module_type' => MODULE_TYPE_REMOTE_SNMP_INC, + 'module_description' => sprintf( + '(%s%s)', + $moduleDescription, + $moduleName + ), + 'module_info' => 'Number of input packets which had cyclic redundancy checksum errors.', + 'execution_type' => 'network', + 'value' => '1.3.6.1.4.1.9.2.2.1.1.12.'.$value, + 'module_unit' => 'packets/s', + 'default_enabled' => true, + 'module_enabled' => false, + 'module_thresholds' => [ + 'min_warning' => '0', + 'max_warning' => '0', + 'inv_warning' => false, + 'min_critical' => '0', + 'max_critical' => '0', + 'inv_critical' => false, + ], + ]; + // Continue with common x86 and x84 modules. // IfAdminStatus. $moduleName = $name.'ifAdminStatus'; @@ -4559,6 +4601,12 @@ class AgentWizard extends HTML $moduleDescription .= ''; } + if (empty($data['alias']) === false) { + $moduleDescription .= 'Alias: '.$data['alias'].' - '; + } else { + $moduleDescription .= ''; + } + $name = $data['name'].'_'; $value = $data['index']; } @@ -4748,6 +4796,12 @@ class AgentWizard extends HTML $moduleDescription .= ''; } + if (empty($data['alias']) === false) { + $moduleDescription .= 'Alias: '.$data['alias'].' - '; + } else { + $moduleDescription .= ''; + } + $name = $data['name'].'_'; $value = $data['index']; } From 24ed77b5a11bb383c6f2b0fedcf0312f7a547e10 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 12 Feb 2021 15:25:41 +0100 Subject: [PATCH 2/8] Pandora bandwidth server plugin --- .../include/class/AgentWizard.class.php | 165 +++++- pandora_server/lib/PandoraFMS/PluginTools.pm | 25 +- .../util/plugin/pandora_snmp_bandwidth.pl | 508 ++++++++++++++++++ 3 files changed, 656 insertions(+), 42 deletions(-) create mode 100644 pandora_server/util/plugin/pandora_snmp_bandwidth.pl diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 6a852dd6af..35e8d676f7 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -937,8 +937,8 @@ class AgentWizard extends HTML $ipsResult = []; // In this case we need the full information provided by snmpwalk. - $ipsResult = $this->snmpwalkValues($snmpIpDiscover, false, true); - $indexes = $this->snmpwalkValues($snmpIpIndexes, false, true); + $ipsResult = $this->snmpWalkValues($snmpIpDiscover, false, true); + $indexes = $this->snmpWalkValues($snmpIpIndexes, false, true); $unicastIpReferences = []; foreach ($indexes as $k => $v) { @@ -960,11 +960,11 @@ class AgentWizard extends HTML // Set the name of interface. $interfaces[$indexKey]['name'] = $name; // Get the description. - $interfaces[$indexKey]['descr'] = $this->snmpgetValue( + $interfaces[$indexKey]['descr'] = $this->snmpGetValue( '.1.3.6.1.2.1.2.2.1.2.'.$indexKey ); // Get the MAC address. - $interfaces[$indexKey]['mac'] = $this->snmpgetValue( + $interfaces[$indexKey]['mac'] = $this->snmpGetValue( '.1.3.6.1.2.1.2.2.1.6.'.$indexKey ); // Get unicast IP address. @@ -974,12 +974,12 @@ class AgentWizard extends HTML } // Get interface alias. - $interfaces[$indexKey]['alias'] = $this->snmpgetValue( + $interfaces[$indexKey]['alias'] = $this->snmpGetValue( '.1.3.6.1.2.1.31.1.1.1.18.'.$indexKey ); // Get interface speed. - $interfaces[$indexKey]['speed'] = $this->snmpgetValue( + $interfaces[$indexKey]['speed'] = $this->snmpGetValue( '.1.3.6.1.2.1.2.2.1.5.'.$indexKey ); } @@ -1045,7 +1045,7 @@ class AgentWizard extends HTML if ($this->wizardSection === 'snmp_interfaces_explorer') { // Check if thereis x64 counters. $snmp_tmp = '.1.3.6.1.2.1.31.1.1.1.6'; - $check_x64 = $this->snmpwalkValues( + $check_x64 = $this->snmpWalkValues( $snmp_tmp, false, true @@ -1061,7 +1061,7 @@ class AgentWizard extends HTML // Explore interface names. $oidExplore = '.1.3.6.1.2.1.31.1.1.1.1'; - $receivedOid = $this->snmpwalkValues( + $receivedOid = $this->snmpWalkValues( $oidExplore, false, true @@ -1072,7 +1072,7 @@ class AgentWizard extends HTML } // Doc Interfaces de red. - $receivedOid = $this->snmpwalkValues( + $receivedOid = $this->snmpWalkValues( $oidExplore, false, false @@ -1083,7 +1083,7 @@ class AgentWizard extends HTML $oidExplore = '1.3.6.1.2.1.2.2.1.2'; // Doc Interfaces de red. - $receivedOid = $this->snmpwalkValues( + $receivedOid = $this->snmpWalkValues( $oidExplore, false, true @@ -2403,7 +2403,7 @@ class AgentWizard extends HTML } // Get current value. - $currentValue = $this->snmpgetValue($moduleData['value']); + $currentValue = $this->snmpGetValue($moduleData['value']); // It unit of measure have data, attach to current value. if (empty($moduleData['module_unit']) === false) { @@ -2556,7 +2556,7 @@ class AgentWizard extends HTML } // Get current value. - $currentValue = $this->snmpgetValue($moduleData['value']); + $currentValue = $this->snmpGetValue($moduleData['value']); // Format current value with thousands and decimals. if (is_numeric($currentValue) === true) { @@ -2927,7 +2927,7 @@ class AgentWizard extends HTML // Common for FIXED Scan types. // If _nameOID_ macro exists, stablish the name getted. if (empty($module['name_oid']) === false) { - $nameValue = $this->snmpgetValue($module['name_oid']); + $nameValue = $this->snmpGetValue($module['name_oid']); $moduleBlocks[$k]['name'] = str_replace( '_nameOID_', $nameValue, @@ -2941,7 +2941,7 @@ class AgentWizard extends HTML $module['value'] = 0; } - $value = $this->snmpgetValue($module['value']); + $value = $this->snmpGetValue($module['value']); // If the value is missing, we must not show this module. if (empty($value) === true) { unset($moduleBlocks[$k]); @@ -2963,7 +2963,7 @@ class AgentWizard extends HTML // OIDs and get his values. foreach ($macros as $key => $oid) { if (preg_match('/extra_field_/', $key) !== 0) { - $value = (float) $this->snmpgetValue($oid); + $value = (float) $this->snmpGetValue($oid); // If the value not exists, // we must not create a module. @@ -2999,20 +2999,20 @@ class AgentWizard extends HTML } else { if ($module['execution_type'] == EXECUTION_TYPE_NETWORK) { // Get the values of snmpwalk. - $snmpwalkNames = $this->snmpwalkValues($module['name_oid']); - $snmpwalkValues = $this->snmpwalkValues($module['value']); + $snmpwalkNames = $this->snmpWalkValues($module['name_oid']); + $snmpWalkValues = $this->snmpWalkValues($module['value']); $snmpwalkCombined = []; foreach ($snmpwalkNames as $index => $name) { if (isset($name) !== true - || isset($snmpwalkValues[$index]) !== true + || isset($snmpWalkValues[$index]) !== true ) { continue; } $snmpwalkCombined[$index] = [ 'name' => $name, - 'value' => $snmpwalkValues[$index], + 'value' => $snmpWalkValues[$index], ]; } @@ -3062,7 +3062,7 @@ class AgentWizard extends HTML $snmpwalkNamesTmp = []; // Is needed the index and the values of snmpwalk. - $snmpwalkNamesTmp = $this->snmpwalkValues( + $snmpwalkNamesTmp = $this->snmpWalkValues( $module['name_oid'], true ); @@ -3082,7 +3082,7 @@ class AgentWizard extends HTML foreach ($oids as $oidName => $oid) { $currentOid = $oid.'.'.$tmpSecond[0]; $macros['macros'][$oidName] = $currentOid; - $currentOidValue = $this->snmpgetValue($currentOid); + $currentOidValue = $this->snmpGetValue($currentOid); // If for any reason the value comes empty, add 1. if ($currentOidValue == '') { $currentOidValue = 1; @@ -3240,6 +3240,58 @@ class AgentWizard extends HTML } + /** + * Returns associated PEN code of this device. + * + * @return integer|null PEN oid or null if not found. + */ + private function getPEN() + { + $oid = '.1.3.6.1.2.1.1.2.0'; + $output = $this->snmpWalkValues($oid, false, true, true); + + static $pen; + + if (isset($pen) === true) { + return $pen; + } + + if (is_array($output) === true + && isset($output[$oid]) === true + ) { + // Output should be an array with only 1 element. + $pen = (int) explode('.', $output[$oid])[7]; + } + + if ($pen === 0) { + return null; + } + + return $pen; + } + + + /** + * Returns the index oid matching selected expected value. + * + * @param string $oidTree Tree to search in. + * @param string $expectedValue Expected value. + * + * @return string|false Index where expected value is stored or false if not + * found. + */ + private function snmpGetValueInverse($oidTree, $expectedValue) + { + $oidTree = $this->snmpWalkValues($oidTree); + + if (is_array($oidTree) === false) { + return false; + } + + return array_search($expectedValue, $oidTree); + } + + /** * Perform a snmpget for get a value from provided oid. * @@ -3248,13 +3300,13 @@ class AgentWizard extends HTML * * @return mixed String when response, null if error. */ - private function snmpgetValue(string $oid, ?bool $full_output=false) + private function snmpGetValue(string $oid, ?bool $full_output=false) { if ($oid[0] !== '.') { $oid = '.'.$oid; } - $output = $this->snmpwalkValues($oid, false, true, true); + $output = $this->snmpWalkValues($oid, false, true, true); if (is_array($output) === true) { foreach ($output as $k => $v) { @@ -3287,7 +3339,7 @@ class AgentWizard extends HTML * * @return array */ - private function snmpwalkValues( + private function snmpWalkValues( string $oid, bool $full_output=false, bool $pure=false, @@ -4286,7 +4338,7 @@ class AgentWizard extends HTML { $moduleDescription = ''; $name = ''; - $value = '1'; + $value = '_generic_'; // Unpack the array with data. if (empty($data) === false) { if (empty($data['mac']) === false) { @@ -4320,7 +4372,7 @@ class AgentWizard extends HTML // IfOperStatus. $adminStatusValue = 1; if (empty($data) === false) { - $adminStatusValue = $this->snmpgetValue( + $adminStatusValue = $this->snmpGetValue( '1.3.6.1.2.1.2.2.1.7.'.$value ); @@ -4331,7 +4383,7 @@ class AgentWizard extends HTML // IfOperStatus. $operStatusValue = 1; if (empty($data) === false) { - $operStatusValue = $this->snmpgetValue( + $operStatusValue = $this->snmpGetValue( '1.3.6.1.2.1.2.2.1.8.'.$value ); @@ -4408,9 +4460,11 @@ class AgentWizard extends HTML 'ifOutNUcastPkts / ifHCOutNUcastPkts', ]; - if ($name == '') { + if ($name === '') { foreach ($definition_temp as $module => $module_def) { - $definition_temp[$module]['module_name'] = array_shift($general_module_names); + $definition_temp[$module]['module_name'] = array_shift( + $general_module_names + ); } } @@ -4444,6 +4498,59 @@ class AgentWizard extends HTML ], ]; + // Manufacturer specific modules. + $pen = $this->getPEN(); + switch ($pen) { + case 9: + // CISCO. + $valueTranslated = $this->snmpGetValueInverse( + '.1.3.6.1.4.1.9.5.1.4.1.1.11.1', + $value + ); + if ($valueTranslated === false && $value !== '_generic_') { + $duplexMismatchOID = null; + } else { + $duplexMismatchOID = '.1.3.6.1.4.1.9.5.1.4.1.1.10.1'; + $duplexMismatchOID .= $valueTranslated; + $minc = 2.5; + $maxc = 3.5; + } + break; + + // TODO: Add here extra manufacturers. + default: + // Unknown. + $duplexMismatchOID = null; + break; + } + + if (isset($duplexMismatchOID) === true) { + // Duplex mismatch. + $moduleName = $name.'DuplexMismatch'; + $definition['DuplexMismatch'] = [ + 'module_name' => $moduleName, + 'module_type' => MODULE_TYPE_REMOTE_SNMP, + 'module_description' => sprintf( + '(%s%s)', + $moduleDescription, + $moduleName + ), + 'module_info' => 'Indicates whether the port is operating in half-duplex, full-duplex, disagree or auto negotiation mode. If the port could not agree with the far end on port duplex, the port will be in disagree(3) mode.', + 'execution_type' => 'network', + 'value' => $duplexMismatchOID, + 'default_enabled' => true, + 'module_enabled' => false, + 'module_thresholds' => [ + 'min_warning' => '0', + 'max_warning' => '0', + 'inv_warning' => false, + 'min_critical' => $minc, + 'max_critical' => $maxc, + 'inv_critical' => false, + ], + ]; + } + // Continue with common x86 and x84 modules. // IfAdminStatus. $moduleName = $name.'ifAdminStatus'; diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index ded2156f6a..fd6afcdac2 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -2042,19 +2042,18 @@ sub api_create_group { # -> means $context (v3) # # Configuration hash -# -# $snmp{version} -# $snmp{community} -# $snmp{host} -# $snmp{oid} -# $snmp{port} -# $snmp{securityName} -# $snmp{context -# $snmp{securityLevel} -# $snmp{authProtocol} -# $snmp{authKey} -# $snmp{privProtocol} -# $snmp{privKey} +# $snmp{version} +# $snmp{community} +# $snmp{host} +# $snmp{oid} +# $snmp{port} +# $snmp{securityName} +# $snmp{context +# $snmp{securityLevel} +# $snmp{authProtocol} +# $snmp{authKey} +# $snmp{privProtocol} +# $snmp{privKey} ################################################################################ sub snmp_walk { my $snmp = shift; diff --git a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl new file mode 100644 index 0000000000..ff5bbf2af2 --- /dev/null +++ b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl @@ -0,0 +1,508 @@ +#!/usr/bin/perl +# +################################################################################ +# +# Bandwith plugin +# +# Requirements: +# snmpget +# snmpwalk +# +# (c) Fco de Borja Sanchez +# +# 2018/06/27 +# Changes: +# First version +# +################################################################################ + +use strict; +use warnings; + +use POSIX qw(strftime); + +use lib '/usr/lib/perl5'; +use PandoraFMS::PluginTools; + +use Data::Dumper; +$Data::Dumper::Sortkeys = 1; + +# version: Defines actual version of Pandora FMS +my $pandora_version = "7.0NG.752"; +my $pandora_build = "210212"; +our $VERSION = $pandora_version." ".$pandora_build; + +my $HELP=< 0, + HALF_DUPLEX => 2, + FULL_DUPLEX => 3, +}; + +################################################################################ +# Translate argument to config hash key +################################################################################ +sub update_config_key ($) { + my $arg = shift; + if ($arg eq "c"){ + return "community"; + } + if ($arg eq "v"){ + return "version"; + } + if ($arg eq "h"){ + return "host"; + } + if ($arg eq "p"){ + return "port"; + } + if ($arg eq "o"){ + return "oid_base"; + } + if ($arg eq "d"){ + return "datatype"; + } + if ($arg eq "u"){ + return "securityName"; + } + if ($arg eq "n"){ + return "context"; + } + if ($arg eq "l"){ + return "securityLevel"; + } + if ($arg eq "a"){ + return "authProtocol"; + } + if ($arg eq "A"){ + return "authKey"; + } + if ($arg eq "x"){ + return "privProtocol"; + } + if ($arg eq "X"){ + return "privKey"; + } + if ($arg eq "agent") { + return "agent_name"; + } + if ($arg eq "names") { + return "names"; + } + if ($arg eq "branches") { + return "branches"; + } + if ($arg eq 'ifIndex') { + return "ifIndex"; + } +} + +################################################################################ +# Prepare analysis tree +################################################################################ +sub prepare_tree { + my ($config) = @_; + my $tree; + + my %snmp_call = %{$config}; + my $ifIndex = $config->{'ifIndex'}; + $ifIndex = '' if empty($ifIndex); + if (!empty($ifIndex) && $ifIndex !~ /^\./) { + $ifIndex = '.'.$ifIndex; + } + + if (is_enabled($config->{'use_x64'})) { + $snmp_call{'oid'} = $config->{'oid_base'} . $config->{'x64_indexes'}{'__idx__'}.$ifIndex; + } else { + $snmp_call{'oid'} = $config->{'oid_base'} . $config->{'x86_indexes'}{'__idx__'}.$ifIndex; + } + + my $raw = snmp_walk(\%snmp_call); + return $raw if (ref($raw) eq "HASH"); + + my @data = split /\n/, $raw; + foreach my $it (@data) { + my ($key, $value) = split /=/, $it; + $value = trim($value); + $key = trim($key); + $value =~ s/^.*:\ {0,1}//; + + if ($value =~ /No such instance/i) { + return {}; + } + + $ifIndex = $value; + if ($ifIndex !~ /^\./) { + $ifIndex = '.'.$ifIndex; + } + + my %inOctets_call = %{$config}; + if (is_enabled($config->{'use_x64'})) { + $inOctets_call{'oid'} = $config->{'oid_base'}; + $inOctets_call{'oid'} .= $config->{'x64_indexes'}{'inOctets'}.$ifIndex; + } else { + $inOctets_call{'oid'} = $config->{'oid_base'}; + $inOctets_call{'oid'} .= $config->{'x86_indexes'}{'inOctets'}.$ifIndex; + } + + my $inOctets = snmp_get(\%inOctets_call); + if (ref($inOctets) eq "HASH") { + $inOctets = $inOctets->{'data'}; + } else { + # Ignore, cannot retrieve inOctets. + next; + } + + my %outOctets_call = %{$config}; + if (is_enabled($config->{'use_x64'})) { + $outOctets_call{'oid'} = $config->{'oid_base'}; + $outOctets_call{'oid'} .= $config->{'x64_indexes'}{'outOctets'}.$ifIndex; + } else { + $outOctets_call{'oid'} = $config->{'oid_base'}; + $outOctets_call{'oid'} .= $config->{'x86_indexes'}{'outOctets'}.$ifIndex; + } + + my $outOctets = snmp_get(\%outOctets_call); + if (ref($outOctets) eq "HASH") { + $outOctets = $outOctets->{'data'}; + } else { + # Ignore, cannot retrieve inOctets. + next; + } + + my %duplex_call = %{$config}; + if (is_enabled($config->{'use_x64'})) { + $duplex_call{'oid'} = $config->{'oid_base'}; + $duplex_call{'oid'} .= $config->{'x64_indexes'}{'duplex'}.$ifIndex; + } else { + $duplex_call{'oid'} = $config->{'oid_base'}; + $duplex_call{'oid'} .= $config->{'x86_indexes'}{'duplex'}.$ifIndex; + } + + my $duplex = snmp_get(\%duplex_call); + if (ref($duplex) eq "HASH") { + $duplex = $duplex->{'data'}; + } else { + # Ignore, cannot retrieve inOctets. + next; + } + + my %speed = %{$config}; + if (is_enabled($config->{'use_x64'})) { + $speed{'oid'} = $config->{'oid_base'}; + $speed{'oid'} .= $config->{'x64_indexes'}{'ifSpeed'}.$ifIndex; + } else { + $speed{'oid'} = $config->{'oid_base'}; + $speed{'oid'} .= $config->{'x86_indexes'}{'ifSpeed'}.$ifIndex; + } + + my $speed = snmp_get(\%speed); + if (ref($speed) eq "HASH") { + $speed = $speed->{'data'}; + } else { + # Ignore, cannot retrieve inOctets. + next; + } + + $tree->{$value} = { + 'duplex' => int $duplex, + 'speed' => int $speed, + 'now' => { + 'timestamp' => time(), + 'inOctets' => int $inOctets, + 'outOctets' => int $outOctets, + }, + } + } + + load_data($config, $tree); + save_data($config, $tree); + + return $tree; +} + +################################################################################ +# Load previous metrics from temporal file. +################################################################################ +sub load_data { + my ($config, $tree) = @_; + + my $_f; + eval { + open($_f, "<$config->{'tmp_file'}") or die('Cannot open ' . $config->{'tmp_file'}); + }; + if( $@ ) { + foreach my $iface (keys %{$tree}) { + $tree->{$iface}{'old'} = { + 'timestamp' => int $tree->{$iface}{'now'}{'timestamp'}, + 'inOctets' => int $tree->{$iface}{'now'}{'inOctets'}, + 'outOctets' => int $tree->{$iface}{'now'}{'outOctets'}, + }; + } + return; + } + + # File opened, load previous values. + while (my $line =<$_f>) { + $line = trim($line); + my ($timestamp, $iface, $inOctets, $outOctets) = split /$config->{'tmp_separator'}/, $line; + + next if (!defined($tree->{trim($iface)})); + + $tree->{trim($iface)}{'old'} = { + 'timestamp' => int trim($timestamp), + 'inOctets' => int trim($inOctets), + 'outOctets' => int trim($outOctets), + }; + } + + close($_f); + + foreach my $iface (keys %{$tree}) { + if (empty($tree->{trim($iface)}{'old'}{'timestamp'})) { + $tree->{$iface}{'old'} = { + 'timestamp' => int $tree->{$iface}{'now'}{'timestamp'}, + 'inOctets' => int $tree->{$iface}{'now'}{'inOctets'}, + 'outOctets' => int $tree->{$iface}{'now'}{'outOctets'}, + }; + } + } +} + +################################################################################ +# Save metrics to temporal file. +################################################################################ +sub save_data { + my ($config, $tree) = @_; + + my $_f; + eval { + open($_f, ">$config->{'tmp_file'}") or die('Cannot open ' . $config->{'tmp_file'}); + }; + if( $@ ) { + logger($config, 'info', "Cannot save stats, please check writting permissions on [" . $config->{'tmp_file'} . "]"); + return; + } + + # File not available, reset old data. + my $target_oids = 'x86_indexes'; + $target_oids = 'x64_indexes' if is_enabled($config->{'use_x64'}); + + foreach my $iface (keys %{$tree}) { + # Timestamp. + print $_f $tree->{$iface}{'now'}{'timestamp'} . $config->{'tmp_separator'}; + + # Iface. + print $_f $iface . $config->{'tmp_separator'}; + + # InOctets. + print $_f $tree->{$iface}{'now'}{'inOctets'} . $config->{'tmp_separator'}; + + # OutOctets. + print $_f $tree->{$iface}{'now'}{'outOctets'} . $config->{'tmp_separator'}; + + # End. + print $_f "\n"; + } + + close($_f); + +} + +################################################################################ +# Calculate bandwidth +################################################################################ +sub get_bandwidth { + my ($config, $tree) = @_; + + foreach my $iface (keys %{$tree}) { + my $ifIndex = $iface; + if ($ifIndex !~ /^\./) { + $ifIndex = '.'.$ifIndex; + } + + my $speed = $tree->{$iface}{'speed'}; + my $input = $tree->{$iface}{'now'}{'inOctets'} - $tree->{$iface}{'old'}{'inOctets'}; + my $output = $tree->{$iface}{'now'}{'outOctets'} - $tree->{$iface}{'old'}{'outOctets'}; + my $delta = $tree->{$iface}{'now'}{'timestamp'} - $tree->{$iface}{'old'}{'timestamp'}; + my $bandwidth = 0; + + $tree->{$iface}->{'delta'} = { + 'inOctets' => $input, + 'outOctets' => $output, + 'seconds' => $delta, + }; + + $tree->{$iface}->{'speed'} = $speed; + + if (($speed > 0) && ($delta > 0)) { + # Information about bandwidth calculation: https://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/8141-calculate-bandwidth-snmp.html + if ($tree->{$iface}{'duplex'} == HALF_DUPLEX + || $tree->{$iface}{'duplex'} == UNKNOWN_DUPLEX + ) { + $bandwidth = (($input + $output) * 8) / ($delta * $speed); + } + elsif ($tree->{$iface}{'duplex'} == FULL_DUPLEX) { + my $input_bandwidth = ($input * 8) / ($delta * $speed); + my $output_bandwidth = ($output * 8) / ($delta * $speed); + $bandwidth = ($input_bandwidth + $output_bandwidth) / 2; + } + else { + logger($config, 'info', "Failed to calculate bandwidth, unknown duplex mode: [" . $tree->{$iface}{'duplex_mode'} . "]"); + } + } + else { + logger($config, 'info', "Failed to calculate bandwidth, interface [" . $iface . "] speed is 0"); + } + + $tree->{$iface}->{'bandwidth'} = 100 * $bandwidth; + } + +} + + + +################################################################################ +# +# MAIN +# +################################################################################ + +if ($#ARGV < 0) { + print $HELP; + exit 0; +} + +# Base config definition +my $_config = { + 'oid_base' => ".1.3.6.1.2.1", + 'as_agent_plugin' => 1, + 'use_x64' => 0, + 'x86_indexes' => { + '__idx__' => ".2.2.1.1", + 'duplex' => ".10.7.2.1.19", + 'inOctets' => ".2.2.1.16", + 'outOctets' => ".2.2.1.10", + 'ifSpeed' => ".2.2.1.5", + }, + 'x64_indexes' => { + # In x64 there is no 'index' branch. Uses latest 'id' in OID as ID. + '__idx__' => ".2.2.1.1", + 'duplex' => ".10.7.2.1.19", + 'inOctets' => ".31.1.1.1.6", + 'outOctets' => ".31.1.1.1.10", + 'ifSpeed' => ".2.2.1.5", + }, +}; + +$_config = read_configuration($_config); + +if (check_lib_version($pandora_version) == 0){ + print_stderror($_config, "Incorrect PluginTools library version " . get_lib_version() . " != " . $VERSION . " functionality could be affected."); +} + +my $config; + +foreach my $pk (keys %{$_config}) { + my $k = update_config_key($pk); + if (!empty($k)) { + $config->{$k} = $_config->{$pk}; + } + else { + $config->{$pk} = $_config->{$pk}; + } +} + +$config->{'host'} = '127.0.0.1' if empty($config->{'host'}); +$config->{'port'} = '161' if empty($config->{'port'}); +$config->{'tmp_separator'} = ';' if empty($config->{'tmp_separator'}); +$config->{'tmp'} = (($^O =~ /win/)?$ENV{'TMP'}:'/tmp') if empty($config->{'tmp'}); + +# Create unique name for tmp and log file for host +my $filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'host'}; + +# Replace every dot for underscore +$filename =~ tr/./_/; +$config->{'tmp_file'} = $filename.'.idx' if empty($config->{'tmp_file'}); +$config->{'log'} = $filename.'.log' if empty($config->{'log'}); + +my @int_exc = split /,/, trim($config->{'interface_exceptions'}) if (!empty($config->{'interface_exceptions'})); +if ($#int_exc >= 0) { + $config->{'interface_exceptions'} = \@int_exc; +} +my @only_int = split /,/, trim($config->{'only_interfaces'}) if (!empty($config->{'only_interfaces'})); +if ($#only_int >= 0) { + $config->{'only_interfaces'} = \@only_int; +} + +logger($config, 'info', "Plugin starts"); +if (is_enabled($config->{'debug'})) { + eval { + eval "use Data::Dumper;1;";if($@) {} + logger($config, Dumper($config)); + }; + if($@) {} +} + +my $analysis_tree = prepare_tree($config); + +if (!empty($analysis_tree->{'error'})) { + logger($config, 'info', "Failed: " . $analysis_tree->{'error'}); + exit 0; +} +else { + get_bandwidth($config, $analysis_tree); +} + +# Report data +my @modules; +my $bandwidth = 0; +my $i = 0; +foreach my $iface (keys %{$analysis_tree}) { + # Calculate summary; + if (is_enabled($analysis_tree->{$iface}{'bandwidth'})) { + $bandwidth = $analysis_tree->{$iface}{'bandwidth'}; + $i++; + } + +} + +if ($i > 0) { + $bandwidth /= $i; + print sprintf("%.9f\n", $bandwidth); +} + +logger($config, 'info', "Plugin ends"); + From 09b5400023c415e5e557afc9fa414ed892269e58 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Feb 2021 18:56:42 +0100 Subject: [PATCH 3/8] MR info + bandwidth analysis in wizards --- pandora_console/extras/mr/45.sql | 9 + .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 6 + .../include/class/AgentWizard.class.php | 229 +++++++++++++++--- pandora_console/pandoradb_data.sql | 6 + .../util/plugin/pandora_snmp_bandwidth.pl | 59 +++-- 5 files changed, 258 insertions(+), 51 deletions(-) create mode 100644 pandora_console/extras/mr/45.sql diff --git a/pandora_console/extras/mr/45.sql b/pandora_console/extras/mr/45.sql new file mode 100644 index 0000000000..27957b1ef3 --- /dev/null +++ b/pandora_console/extras/mr/45.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + +SET @plugin_name = 'Network bandwidth SNMP'; +SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; +SET @plugin_id = ''; +SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; +INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 2131b619a4..22f06fcdf6 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2874,6 +2874,12 @@ SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,20,0,'/usr/share/pandora_server/util/plugin/wizard_wmi_module',NULL,NULL,NULL,NULL,0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Namespace (Optional)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"User\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Password\",\"help\":\"\",\"value\":\"\",\"hide\":\"1\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"WMI Class\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"Fields list\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"Query filter (Optional)\",\"help\":\"Use single quotes for query conditions\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"Operation\",\"help\":\"Aritmetic operation to get data. Macros _fN_ will be changed by fields in list. Example: ((_f1_ - _f2_) * 100) / _f1_\",\"value\":\"\",\"hide\":\"\"}}','-host '_field1_' -namespace '_field2_' -user '_field3_' -pass '_field4_' -wmiClass '_field5_' -fieldsList '_field6_' -queryFilter "_field7_" -operation '_field8_' -wmicPath /usr/bin/wmic'); +SET @plugin_name = 'Network bandwidth SNMP'; +SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; +SET @plugin_id = ''; +SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; +INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); + SET @main_component_group_name = 'Wizard'; SET @component_id = ''; SELECT @component_id := `id_sg` FROM `tnetwork_component_group` WHERE `name` = @main_component_group_name; diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 35e8d676f7..7c273bf621 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -1337,7 +1337,6 @@ class AgentWizard extends HTML $content .= html_print_table($table, true); echo $content; - return; } @@ -1431,6 +1430,15 @@ class AgentWizard extends HTML $result[$value]['description'] = $data['module-default_description-'.$key]; } else if (empty(preg_match('/module-value/', $k)) === false) { $result[$value]['value'] = $data['module-value-'.$key]; + } else if (empty(preg_match('/module-macros/', $k)) === false) { + $result[$value]['macros'] = $data['module-macros-'.$key]; + continue; + } else if (empty(preg_match('/module-id_plugin/', $k)) === false) { + $result[$value]['id_plugin'] = $data['module-id_plugin-'.$key]; + continue; + } else if (empty(preg_match('/module-id_modulo/', $k)) === false) { + $result[$value]['id_modulo'] = $data['module-id_modulo-'.$key]; + continue; } preg_match('/^(.*)-.*?_(\d+-\d+)$/', $k, $matches); @@ -2062,35 +2070,42 @@ class AgentWizard extends HTML } else { $tmp->ip_target($this->targetIp); $tmp->id_modulo(MODULE_PLUGIN); - $fieldsPlugin = db_get_value_sql( - sprintf( - 'SELECT macros FROM tplugin WHERE id=%d', - (int) $infoMacros['server_plugin'] - ) - ); - if ($fieldsPlugin !== false) { - $fieldsPlugin = json_decode($fieldsPlugin, true); - $i = 1; - foreach ($infoMacros as $key => $value) { - if (empty(preg_match('/_snmp_field/', $key)) === false) { - $new_macros = []; - foreach ($fieldsPlugin as $k => $v) { - if ($v['macro'] === preg_replace('/_snmp_field/', '', $key)) { - $fieldsPlugin[$k]['value'] = $this->replacementMacrosPlugin( - $value, - $infoMacros['macros'] - ); - $i++; - continue; + if (empty($candidate['macros']) === true) { + $fieldsPlugin = db_get_value_sql( + sprintf( + 'SELECT macros FROM tplugin WHERE id=%d', + (int) $infoMacros['server_plugin'] + ) + ); + + if ($fieldsPlugin !== false) { + $fieldsPlugin = json_decode($fieldsPlugin, true); + $i = 1; + foreach ($infoMacros as $key => $value) { + if (empty(preg_match('/_snmp_field/', $key)) === false) { + $new_macros = []; + foreach ($fieldsPlugin as $k => $v) { + if ($v['macro'] === preg_replace('/_snmp_field/', '', $key)) { + $fieldsPlugin[$k]['value'] = $this->replacementMacrosPlugin( + $value, + $infoMacros['macros'] + ); + $i++; + continue; + } } } } } - } - $tmp->id_plugin($infoMacros['server_plugin']); - $tmp->macros(json_encode($fieldsPlugin)); + $tmp->id_plugin($infoMacros['server_plugin']); + $tmp->macros(json_encode($fieldsPlugin)); + } else { + // Use definition provided. + $tmp->id_plugin($candidate['id_plugin']); + $tmp->macros(base64_decode($candidate['macros'])); + } } } } else if ($this->protocol === 'wmi') { @@ -2403,7 +2418,18 @@ class AgentWizard extends HTML } // Get current value. - $currentValue = $this->snmpGetValue($moduleData['value']); + if (in_array( + $moduleData['module_type'], + [ + MODULE_TYPE_REMOTE_SNMP, + MODULE_TYPE_REMOTE_SNMP_INC, + MODULE_TYPE_REMOTE_SNMP_STRING, + MODULE_TYPE_REMOTE_SNMP_PROC, + ] + ) === true + ) { + $currentValue = $this->snmpGetValue($moduleData['value']); + } // It unit of measure have data, attach to current value. if (empty($moduleData['module_unit']) === false) { @@ -2413,6 +2439,7 @@ class AgentWizard extends HTML // Stablish the data for show. $generalInterfaceModulesUpdated[] = [ 'component_id' => $component_id_number++, + 'execution_type' => $moduleData['execution_type'], 'name' => $moduleData['module_name'], 'type' => $moduleData['module_type'], 'description' => $moduleData['module_info'], @@ -2425,6 +2452,9 @@ class AgentWizard extends HTML 'module_enabled' => $moduleData['default_enabled'], 'name_oid' => $moduleData['value'], 'value' => $moduleData['value'], + 'id_plugin' => $moduleData['id_plugin'], + 'macros' => $moduleData['macros'], + 'id_modulo' => $moduleData['id_modulo'], ]; } @@ -2556,7 +2586,20 @@ class AgentWizard extends HTML } // Get current value. - $currentValue = $this->snmpGetValue($moduleData['value']); + $currentValue = ''; + + if (in_array( + $moduleData['module_type'], + [ + MODULE_TYPE_REMOTE_SNMP, + MODULE_TYPE_REMOTE_SNMP_INC, + MODULE_TYPE_REMOTE_SNMP_STRING, + MODULE_TYPE_REMOTE_SNMP_PROC, + ] + ) === true + ) { + $currentValue = $this->snmpGetValue($moduleData['value']); + } // Format current value with thousands and decimals. if (is_numeric($currentValue) === true) { @@ -2572,6 +2615,7 @@ class AgentWizard extends HTML // Stablish the data for show. $interfaceModulesUpdated[] = [ 'component_id' => $component_id_number++, + 'execution_type' => $moduleData['execution_type'], 'name' => $moduleData['module_name'], 'type' => $moduleData['module_type'], 'description' => $moduleData['module_description'], @@ -2585,6 +2629,9 @@ class AgentWizard extends HTML 'current_value' => $currentValue, 'name_oid' => $moduleData['value'], 'value' => $moduleData['value'], + 'id_plugin' => $moduleData['id_plugin'], + 'macros' => $moduleData['macros'], + 'id_modulo' => $moduleData['id_modulo'], ]; } @@ -4189,14 +4236,49 @@ class AgentWizard extends HTML 'form="form-create-modules"' ); - // Macro module. - $data[6] .= html_print_input_hidden( - 'module-macros-'.$uniqueId, - base64_encode($module['macros']), - true, - $md5IdBlock, - 'form="form-create-modules"' - ); + if (empty($module['macros']) === false) { + // Macro module. + $data[6] .= html_print_input_hidden( + 'module-macros-'.$uniqueId, + base64_encode($module['macros']), + true, + $md5IdBlock, + 'form="form-create-modules"' + ); + } + + if (empty($module['execution_type']) === false) { + // Id plugin. + $data[6] .= html_print_input_hidden( + 'module-execution_type-'.$uniqueId, + $module['execution_type'], + true, + $md5IdBlock, + 'form="form-create-modules"' + ); + } + + if (empty($module['id_modulo']) === false) { + // Id module. + $data[6] .= html_print_input_hidden( + 'module-id_modulo-'.$uniqueId, + $module['id_modulo'], + true, + $md5IdBlock, + 'form="form-create-modules"' + ); + } + + if (empty($module['id_plugin']) === false) { + // Id plugin. + $data[6] .= html_print_input_hidden( + 'module-id_plugin-'.$uniqueId, + $module['id_plugin'], + true, + $md5IdBlock, + 'form="form-create-modules"' + ); + } // Macro module. $data[6] .= html_print_input_hidden( @@ -4551,6 +4633,85 @@ class AgentWizard extends HTML ]; } + // Bandwidth plugin. + static $plugin; + if ($plugin === null) { + $plugin = \db_get_row_filter( + 'tplugin', + [ 'name' => 'Network bandwidth SNMP' ] + ); + } + + if ($plugin !== false) { + // Network Bandwidth is installed. + $plugin_id = $plugin['id']; + $macros = json_decode($plugin['macros'], 1); + if (json_last_error() === JSON_ERROR_NONE) { + // SNMP Version. + $macros[1]['value'] = $this->version; + + // Community. + $macros[2]['value'] = $this->community; + + // Host. + $macros[3]['value'] = $this->targetIp; + + // Port. + $macros[4]['value'] = $this->targetPort; + + // Interface index filter. + $macros[5]['value'] = $value; + + // SecurityName. + $macros[6]['value'] = $this->authUserV3; + + // SecurityContext. + $macros[7]['value'] = $this->community; + + // SecurityLevel. + $macros[8]['value'] = $this->securityLevelV3; + + // AuthProtocol. + $macros[9]['value'] = $this->authMethodV3; + + // AuthKey. + $macros[10]['value'] = $this->authPassV3; + + // PrivProtocol. + $macros[11]['value'] = $this->privacyMethodV3; + + // PrivKey. + $macros[11]['value'] = $this->privacyPassV3; + + $moduleName = $name.'Bandwidth'; + $definition['Bandwidth'] = [ + 'module_name' => $moduleName, + 'module_type' => MODULE_TYPE_NUMERIC, + 'module_description' => sprintf( + '(%s%s)', + $moduleDescription, + $moduleName + ), + 'module_info' => 'Amount of digital information sent and received from this inteerface over a particular time (see interval).', + 'execution_type' => EXECUTION_TYPE_PLUGIN, + 'id_plugin' => $plugin_id, + 'id_modulo' => MODULE_PLUGIN, + 'macros' => json_encode($macros), + 'default_enabled' => true, + 'module_enabled' => false, + 'module_unit' => '%', + 'module_thresholds' => [ + 'min_warning' => '0', + 'max_warning' => '0', + 'inv_warning' => false, + 'min_critical' => '85', + 'max_critical' => '0', + 'inv_critical' => false, + ], + ]; + } + } + // Continue with common x86 and x84 modules. // IfAdminStatus. $moduleName = $name.'ifAdminStatus'; diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 57f43c5085..f3f77b80c6 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1739,6 +1739,12 @@ SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,20,0,'/usr/share/pandora_server/util/plugin/wizard_wmi_module',NULL,NULL,NULL,NULL,0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Namespace (Optional)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"User\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Password\",\"help\":\"\",\"value\":\"\",\"hide\":\"1\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"WMI Class\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"Fields list\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"Query filter (Optional)\",\"help\":\"Use single quotes for query conditions\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"Operation\",\"help\":\"Aritmetic operation to get data. Macros _fN_ will be changed by fields in list. Example: ((_f1_ - _f2_) * 100) / _f1_\",\"value\":\"\",\"hide\":\"\"}}','-host '_field1_' -namespace '_field2_' -user '_field3_' -pass '_field4_' -wmiClass '_field5_' -fieldsList '_field6_' -queryFilter "_field7_" -operation '_field8_' -wmicPath /usr/bin/wmic'); +SET @plugin_name = 'Network bandwidth SNMP'; +SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; +SET @plugin_id = ''; +SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; +INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); + SET @main_component_group_name = 'Wizard'; SET @component_id = ''; SELECT @component_id := `id_sg` FROM `tnetwork_component_group` WHERE `name` = @main_component_group_name; diff --git a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl index ff5bbf2af2..100147a905 100644 --- a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl +++ b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl @@ -38,9 +38,6 @@ Pandora FMS Server plugin for bandwidth monitoring $VERSION Where OPTIONS could be: -[OIDS] - -use_x64 Use x64 counters (1) or not (0). - [SNMP] -community community -version SNMP version (1,2c,3) @@ -179,7 +176,11 @@ sub prepare_tree { my $inOctets = snmp_get(\%inOctets_call); if (ref($inOctets) eq "HASH") { - $inOctets = $inOctets->{'data'}; + if ($inOctets->{'data'} eq '') { + $inOctets = 0; + } else { + $inOctets = int $inOctets->{'data'}; + } } else { # Ignore, cannot retrieve inOctets. next; @@ -196,7 +197,11 @@ sub prepare_tree { my $outOctets = snmp_get(\%outOctets_call); if (ref($outOctets) eq "HASH") { - $outOctets = $outOctets->{'data'}; + if ($outOctets->{'data'} eq '') { + $outOctets = 0; + } else { + $outOctets = int $outOctets->{'data'}; + } } else { # Ignore, cannot retrieve inOctets. next; @@ -213,7 +218,12 @@ sub prepare_tree { my $duplex = snmp_get(\%duplex_call); if (ref($duplex) eq "HASH") { - $duplex = $duplex->{'data'}; + if ($duplex->{'data'} eq '') { + $duplex = 0; + } else { + $duplex = int $duplex->{'data'}; + } + } else { # Ignore, cannot retrieve inOctets. next; @@ -230,21 +240,24 @@ sub prepare_tree { my $speed = snmp_get(\%speed); if (ref($speed) eq "HASH") { - $speed = $speed->{'data'}; + $speed = int $speed->{'data'}; } else { # Ignore, cannot retrieve inOctets. next; } - $tree->{$value} = { - 'duplex' => int $duplex, - 'speed' => int $speed, - 'now' => { - 'timestamp' => time(), - 'inOctets' => int $inOctets, - 'outOctets' => int $outOctets, - }, - } + { + no warnings "uninitialized"; + $tree->{$value} = { + 'duplex' => int $duplex, + 'speed' => int $speed, + 'now' => { + 'timestamp' => time(), + 'inOctets' => int $inOctets, + 'outOctets' => int $outOctets, + }, + }; + }; } load_data($config, $tree); @@ -380,6 +393,7 @@ sub get_bandwidth { $bandwidth = ($input_bandwidth + $output_bandwidth) / 2; } else { + no warnings "uninitialized"; logger($config, 'info', "Failed to calculate bandwidth, unknown duplex mode: [" . $tree->{$iface}{'duplex_mode'} . "]"); } } @@ -409,7 +423,6 @@ if ($#ARGV < 0) { my $_config = { 'oid_base' => ".1.3.6.1.2.1", 'as_agent_plugin' => 1, - 'use_x64' => 0, 'x86_indexes' => { '__idx__' => ".2.2.1.1", 'duplex' => ".10.7.2.1.19", @@ -450,6 +463,18 @@ $config->{'port'} = '161' if empty($config->{'port'}); $config->{'tmp_separator'} = ';' if empty($config->{'tmp_separator'}); $config->{'tmp'} = (($^O =~ /win/)?$ENV{'TMP'}:'/tmp') if empty($config->{'tmp'}); +if(snmp_walk({ + %{$config}, + 'oid' => '.1.3.6.1.2.1.31.1.1.1.6' + }) +) { + # x64 counters available. + $config->{'use_x64'} = 1; +} else { + # x64 counters not available. + $config->{'use_x64'} = 1; +} + # Create unique name for tmp and log file for host my $filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'host'}; From 2826f4fd89b813aee9b31edf935edf633098643a Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Feb 2021 19:08:32 +0100 Subject: [PATCH 4/8] Fixes in MR, added uniqid macro to pandora_snmp_bandwidth --- pandora_console/extras/mr/45.sql | 2 +- pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 +- pandora_console/include/class/AgentWizard.class.php | 3 +++ pandora_console/pandoradb_data.sql | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/extras/mr/45.sql b/pandora_console/extras/mr/45.sql index 27957b1ef3..13ce742a8a 100644 --- a/pandora_console/extras/mr/45.sql +++ b/pandora_console/extras/mr/45.sql @@ -4,6 +4,6 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 22f06fcdf6..912d7e9ed5 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2878,7 +2878,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); SET @main_component_group_name = 'Wizard'; SET @component_id = ''; diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 7c273bf621..ebb95cc608 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -4683,6 +4683,9 @@ class AgentWizard extends HTML // PrivKey. $macros[11]['value'] = $this->privacyPassV3; + // Hash identifier. + $macros[12]['value'] = uniqid(); + $moduleName = $name.'Bandwidth'; $definition['Bandwidth'] = [ 'module_name' => $moduleName, diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index f3f77b80c6..a377d4a72d 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1743,7 +1743,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); SET @main_component_group_name = 'Wizard'; SET @component_id = ''; From aca9814e0f3a538d15ba8dc9ec81c63886cbf367 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Feb 2021 19:10:49 +0100 Subject: [PATCH 5/8] uniqid pandora_snmp_bandwidth --- pandora_server/util/plugin/pandora_snmp_bandwidth.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl index 100147a905..d6edf5d897 100644 --- a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl +++ b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl @@ -56,6 +56,7 @@ Where OPTIONS could be: [EXTRA] -ifIndex Target interface to retrieve, if not specified, total bandwith will be reported. + -uniqid Use custom temporary file name. Note: You can also use snmpget/snmpwalk argument notation, e.g. -v is equal to -version, -c to -community, etc. @@ -124,6 +125,9 @@ sub update_config_key ($) { if ($arg eq 'ifIndex') { return "ifIndex"; } +if ($arg eq 'uniqid') { + return "uniqid"; +} } ################################################################################ @@ -478,6 +482,10 @@ if(snmp_walk({ # Create unique name for tmp and log file for host my $filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'host'}; +if (!empty($config->{'uniqid'})) { + $filename = $config->{'tmp'}.'/pandora_bandwith_'.$config->{'uniqid'}; +} + # Replace every dot for underscore $filename =~ tr/./_/; $config->{'tmp_file'} = $filename.'.idx' if empty($config->{'tmp_file'}); From 30755ba256a2ee56597a5a922e37ed576ddcc283 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 15 Feb 2021 19:12:06 +0100 Subject: [PATCH 6/8] minor fixes --- pandora_console/include/class/AgentWizard.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index ebb95cc608..860f8f89f6 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -4681,10 +4681,10 @@ class AgentWizard extends HTML $macros[11]['value'] = $this->privacyMethodV3; // PrivKey. - $macros[11]['value'] = $this->privacyPassV3; + $macros[12]['value'] = $this->privacyPassV3; // Hash identifier. - $macros[12]['value'] = uniqid(); + $macros[13]['value'] = uniqid(); $moduleName = $name.'Bandwidth'; $definition['Bandwidth'] = [ From 74ee4971d0ff6387cf8152ac0849c2e3207fce87 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 16 Feb 2021 12:14:56 +0100 Subject: [PATCH 7/8] Added inUsage and outUsage, added units --- pandora_console/extras/mr/45.sql | 2 +- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 +- .../include/class/AgentWizard.class.php | 87 +++++++++++++- pandora_console/pandoradb_data.sql | 2 +- .../util/plugin/pandora_snmp_bandwidth.pl | 111 +++++++++++++----- 5 files changed, 167 insertions(+), 37 deletions(-) diff --git a/pandora_console/extras/mr/45.sql b/pandora_console/extras/mr/45.sql index 13ce742a8a..50b853ac64 100644 --- a/pandora_console/extras/mr/45.sql +++ b/pandora_console/extras/mr/45.sql @@ -4,6 +4,6 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 912d7e9ed5..c59867ee31 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2878,7 +2878,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); SET @main_component_group_name = 'Wizard'; SET @component_id = ''; diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 860f8f89f6..6810244320 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -1439,6 +1439,9 @@ class AgentWizard extends HTML } else if (empty(preg_match('/module-id_modulo/', $k)) === false) { $result[$value]['id_modulo'] = $data['module-id_modulo-'.$key]; continue; + } else if (empty(preg_match('/module-unit/', $k)) === false) { + $result[$value]['unit'] = $data['module-unit-'.$key]; + continue; } preg_match('/^(.*)-.*?_(\d+-\d+)$/', $k, $matches); @@ -1899,6 +1902,7 @@ class AgentWizard extends HTML { $modules = []; $errorflag = false; + foreach ($modulesCandidates as $candidate) { $tmp = Module::search( [ @@ -2632,6 +2636,7 @@ class AgentWizard extends HTML 'id_plugin' => $moduleData['id_plugin'], 'macros' => $moduleData['macros'], 'id_modulo' => $moduleData['id_modulo'], + 'unit' => ($moduleData['unit'] ?? $moduleData['module_unit']), ]; } @@ -4221,7 +4226,7 @@ class AgentWizard extends HTML // Unit module. $data[6] .= html_print_input_hidden( 'module-unit-'.$uniqueId, - $module['unit'], + ($module['unit'] ?? $module['module_unit']), true, $md5IdBlock, 'form="form-create-modules"' @@ -4686,6 +4691,12 @@ class AgentWizard extends HTML // Hash identifier. $macros[13]['value'] = uniqid(); + // Get input usage. + $macros[14]['value'] = 0; + + // Get output usage. + $macros[15]['value'] = 0; + $moduleName = $name.'Bandwidth'; $definition['Bandwidth'] = [ 'module_name' => $moduleName, @@ -4695,7 +4706,7 @@ class AgentWizard extends HTML $moduleDescription, $moduleName ), - 'module_info' => 'Amount of digital information sent and received from this inteerface over a particular time (see interval).', + 'module_info' => 'Amount of digital information sent and received from this interface over a particular time (see interval).', 'execution_type' => EXECUTION_TYPE_PLUGIN, 'id_plugin' => $plugin_id, 'id_modulo' => MODULE_PLUGIN, @@ -4712,6 +4723,78 @@ class AgentWizard extends HTML 'inv_critical' => false, ], ]; + + // Hash identifier. + $macros[13]['value'] = uniqid(); + + // Get input usage. + $macros[14]['value'] = 1; + + // Get output usage. + $macros[15]['value'] = 0; + + $moduleName = $name.'inUsage'; + $definition['inUsage'] = [ + 'module_name' => $moduleName, + 'module_type' => MODULE_TYPE_NUMERIC, + 'module_description' => sprintf( + '(%s%s)', + $moduleDescription, + $moduleName + ), + 'module_info' => 'Bandwidth usage received into this interface over a particular time (see interval).', + 'execution_type' => EXECUTION_TYPE_PLUGIN, + 'id_plugin' => $plugin_id, + 'id_modulo' => MODULE_PLUGIN, + 'macros' => json_encode($macros), + 'default_enabled' => true, + 'module_enabled' => false, + 'module_unit' => '%', + 'module_thresholds' => [ + 'min_warning' => '0', + 'max_warning' => '0', + 'inv_warning' => false, + 'min_critical' => '0', + 'max_critical' => '0', + 'inv_critical' => false, + ], + ]; + + // Hash identifier. + $macros[13]['value'] = uniqid(); + + // Get input usage. + $macros[14]['value'] = 0; + + // Get output usage. + $macros[15]['value'] = 1; + + $moduleName = $name.'outUsage'; + $definition['outUsage'] = [ + 'module_name' => $moduleName, + 'module_type' => MODULE_TYPE_NUMERIC, + 'module_description' => sprintf( + '(%s%s)', + $moduleDescription, + $moduleName + ), + 'module_info' => 'Bandwidth usage sent from this interface over a particular time (see interval).', + 'execution_type' => EXECUTION_TYPE_PLUGIN, + 'id_plugin' => $plugin_id, + 'id_modulo' => MODULE_PLUGIN, + 'macros' => json_encode($macros), + 'default_enabled' => true, + 'module_enabled' => false, + 'module_unit' => '%', + 'module_thresholds' => [ + 'min_warning' => '0', + 'max_warning' => '0', + 'inv_warning' => false, + 'min_critical' => '0', + 'max_critical' => '0', + 'inv_critical' => false, + ], + ]; } } diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index a377d4a72d..b178702bc0 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1743,7 +1743,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); SET @main_component_group_name = 'Wizard'; SET @component_id = ''; diff --git a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl index d6edf5d897..ad0f6c8899 100644 --- a/pandora_server/util/plugin/pandora_snmp_bandwidth.pl +++ b/pandora_server/util/plugin/pandora_snmp_bandwidth.pl @@ -2,12 +2,12 @@ # ################################################################################ # -# Bandwith plugin -# +# Bandwith usage plugin +# # Requirements: # snmpget # snmpwalk -# +# # (c) Fco de Borja Sanchez # # 2018/06/27 @@ -45,18 +45,20 @@ Where OPTIONS could be: -port target port (161) [SNMPv3] - -securityName - -context - -securityLevel - -authProtocol - -authKey - -privProtocol + -securityName + -context + -securityLevel + -authProtocol + -authKey + -privProtocol -privKey [EXTRA] -ifIndex Target interface to retrieve, if not specified, total bandwith will be reported. -uniqid Use custom temporary file name. + -inUsage Show only input usage (in percentage) - 1, or not 0. + -outUsage Show only output usage (in percentage) - 1, or not 0. Note: You can also use snmpget/snmpwalk argument notation, e.g. -v is equal to -version, -c to -community, etc. @@ -125,9 +127,15 @@ sub update_config_key ($) { if ($arg eq 'ifIndex') { return "ifIndex"; } -if ($arg eq 'uniqid') { - return "uniqid"; -} + if ($arg eq 'uniqid') { + return "uniqid"; + } + if ($arg eq 'inUsage') { + return "inUsage"; + } + if ($arg eq 'outUsage') { + return "outUsage"; + } } ################################################################################ @@ -152,7 +160,7 @@ sub prepare_tree { my $raw = snmp_walk(\%snmp_call); return $raw if (ref($raw) eq "HASH"); - + my @data = split /\n/, $raw; foreach my $it (@data) { my ($key, $value) = split /=/, $it; @@ -227,7 +235,7 @@ sub prepare_tree { } else { $duplex = int $duplex->{'data'}; } - + } else { # Ignore, cannot retrieve inOctets. next; @@ -329,7 +337,7 @@ sub save_data { open($_f, ">$config->{'tmp_file'}") or die('Cannot open ' . $config->{'tmp_file'}); }; if( $@ ) { - logger($config, 'info', "Cannot save stats, please check writting permissions on [" . $config->{'tmp_file'} . "]"); + logger($config, 'info', "Cannot save stats, please check writting permissions on [" . $config->{'tmp_file'} . "]") if (is_enabled($config->{'debug'})); return; } @@ -343,7 +351,7 @@ sub save_data { # Iface. print $_f $iface . $config->{'tmp_separator'}; - + # InOctets. print $_f $tree->{$iface}{'now'}{'inOctets'} . $config->{'tmp_separator'}; @@ -359,9 +367,9 @@ sub save_data { } ################################################################################ -# Calculate bandwidth +# Calculate bandwidth usage ################################################################################ -sub get_bandwidth { +sub get_bandwidth_usage { my ($config, $tree) = @_; foreach my $iface (keys %{$tree}) { @@ -375,6 +383,8 @@ sub get_bandwidth { my $output = $tree->{$iface}{'now'}{'outOctets'} - $tree->{$iface}{'old'}{'outOctets'}; my $delta = $tree->{$iface}{'now'}{'timestamp'} - $tree->{$iface}{'old'}{'timestamp'}; my $bandwidth = 0; + my $inUsage = 0; + my $outUsage = 0; $tree->{$iface}->{'delta'} = { 'inOctets' => $input, @@ -385,7 +395,7 @@ sub get_bandwidth { $tree->{$iface}->{'speed'} = $speed; if (($speed > 0) && ($delta > 0)) { - # Information about bandwidth calculation: https://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/8141-calculate-bandwidth-snmp.html + # Information about bandwidth usage calculation: https://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/8141-calculate-bandwidth-snmp.html if ($tree->{$iface}{'duplex'} == HALF_DUPLEX || $tree->{$iface}{'duplex'} == UNKNOWN_DUPLEX ) { @@ -398,26 +408,40 @@ sub get_bandwidth { } else { no warnings "uninitialized"; - logger($config, 'info', "Failed to calculate bandwidth, unknown duplex mode: [" . $tree->{$iface}{'duplex_mode'} . "]"); + logger($config, 'info', "Failed to calculate bandwidth usage, unknown duplex mode: [" . $tree->{$iface}{'duplex_mode'} . "]") if (is_enabled($config->{'debug'})); } + + $inUsage = ($input * 8) / ($delta * $speed); + $outUsage = ($output * 8) / ($delta * $speed); + + if ($inUsage > 1) { + $inUsage = 1; + logger($config, 'info', "Max input usage exceeded: $inUsage") if (is_enabled($config->{'debug'})); + } + if ($outUsage > 1) { + $outUsage = 1; + logger($config, 'info', "Max output usage exceeded: $outUsage") if (is_enabled($config->{'debug'})); + } + } else { - logger($config, 'info', "Failed to calculate bandwidth, interface [" . $iface . "] speed is 0"); + logger($config, 'info', "Failed to calculate bandwidth usage, interface [" . $iface . "] speed is 0") if (is_enabled($config->{'debug'})); } - $tree->{$iface}->{'bandwidth'} = 100 * $bandwidth; + $tree->{$iface}->{'bandwidth'} = 100 * $bandwidth; + $tree->{$iface}->{'inUsage'} = 100 * $inUsage; + $tree->{$iface}->{'outUsage'} = 100 * $outUsage; + } } - ################################################################################ # # MAIN # ################################################################################ - if ($#ARGV < 0) { print $HELP; exit 0; @@ -500,11 +524,11 @@ if ($#only_int >= 0) { $config->{'only_interfaces'} = \@only_int; } -logger($config, 'info', "Plugin starts"); +logger($config, 'info', "Plugin starts") if (is_enabled($config->{'debug'})); if (is_enabled($config->{'debug'})) { eval { eval "use Data::Dumper;1;";if($@) {} - logger($config, Dumper($config)); + logger($config, Dumper($config)) if (is_enabled($config->{'debug'})); }; if($@) {} } @@ -512,30 +536,53 @@ if (is_enabled($config->{'debug'})) { my $analysis_tree = prepare_tree($config); if (!empty($analysis_tree->{'error'})) { - logger($config, 'info', "Failed: " . $analysis_tree->{'error'}); + logger($config, 'info', "Failed: " . $analysis_tree->{'error'}) if (is_enabled($config->{'debug'})); exit 0; } else { - get_bandwidth($config, $analysis_tree); + get_bandwidth_usage($config, $analysis_tree); } # Report data my @modules; my $bandwidth = 0; +my $inUsage = 0; +my $outUsage = 0; my $i = 0; +my $j = 0; +my $k = 0; foreach my $iface (keys %{$analysis_tree}) { # Calculate summary; if (is_enabled($analysis_tree->{$iface}{'bandwidth'})) { $bandwidth = $analysis_tree->{$iface}{'bandwidth'}; $i++; } + if (is_enabled($analysis_tree->{$iface}{'inUsage'})) { + $inUsage = $analysis_tree->{$iface}{'inUsage'}; + $j++; + } + if (is_enabled($analysis_tree->{$iface}{'outUsage'})) { + $outUsage = $analysis_tree->{$iface}{'outUsage'}; + $k++; + } } -if ($i > 0) { - $bandwidth /= $i; - print sprintf("%.9f\n", $bandwidth); +if ($j > 0 && is_enabled($config->{'inUsage'})) { + $inUsage /= $j; + print sprintf("%.9f\n", $inUsage); +} elsif ($k > 0 && is_enabled($config->{'outUsage'})) { + $outUsage /= $k; + print sprintf("%.9f\n", $outUsage); } -logger($config, 'info', "Plugin ends"); +if ($i > 0 + && !is_enabled($config->{'inUsage'}) + && !is_enabled($config->{'outUsage'}) +) { + $bandwidth /= $i; + print sprintf("%.9f\n", $bandwidth); +} + +logger($config, 'info', "Plugin ends") if (is_enabled($config->{'debug'})); From 416bc8cad49f612a0dcd9331161323be06e6aba7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 16 Feb 2021 12:33:15 +0100 Subject: [PATCH 8/8] Minor fixes and speed out of control --- pandora_console/extras/mr/45.sql | 2 +- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 +- .../include/class/AgentWizard.class.php | 20 +++++++++++++------ pandora_console/pandoradb_data.sql | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pandora_console/extras/mr/45.sql b/pandora_console/extras/mr/45.sql index 50b853ac64..e8c2e1c39b 100644 --- a/pandora_console/extras/mr/45.sql +++ b/pandora_console/extras/mr/45.sql @@ -4,6 +4,6 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_' -inUsage '_field14_' -outUsage '_field15_''); COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index c59867ee31..7c7d7b3d22 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2878,7 +2878,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_' -inUsage '_field14_' -outUsage '_field15_''); SET @main_component_group_name = 'Wizard'; SET @component_id = ''; diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 6810244320..9ba6f4e0f1 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -4458,11 +4458,16 @@ class AgentWizard extends HTML // IfOperStatus. $adminStatusValue = 1; + $speed = 0; if (empty($data) === false) { $adminStatusValue = $this->snmpGetValue( '1.3.6.1.2.1.2.2.1.7.'.$value ); + $speed = $this->snmpGetValue( + '.1.3.6.1.2.1.2.2.1.5.'.$value + ); + preg_match('/\((\d+?)\)/', $adminStatusValue, $match); $adminStatusValue = (int) $match[1]; } @@ -4702,9 +4707,10 @@ class AgentWizard extends HTML 'module_name' => $moduleName, 'module_type' => MODULE_TYPE_NUMERIC, 'module_description' => sprintf( - '(%s%s)', + '(%s%s - Speed:%d)', $moduleDescription, - $moduleName + $moduleName, + $speed ), 'module_info' => 'Amount of digital information sent and received from this interface over a particular time (see interval).', 'execution_type' => EXECUTION_TYPE_PLUGIN, @@ -4738,9 +4744,10 @@ class AgentWizard extends HTML 'module_name' => $moduleName, 'module_type' => MODULE_TYPE_NUMERIC, 'module_description' => sprintf( - '(%s%s)', + '(%s%s - Speed:%d)', $moduleDescription, - $moduleName + $moduleName, + $speed ), 'module_info' => 'Bandwidth usage received into this interface over a particular time (see interval).', 'execution_type' => EXECUTION_TYPE_PLUGIN, @@ -4774,9 +4781,10 @@ class AgentWizard extends HTML 'module_name' => $moduleName, 'module_type' => MODULE_TYPE_NUMERIC, 'module_description' => sprintf( - '(%s%s)', + '(%s%s - Speed:%d)', $moduleDescription, - $moduleName + $moduleName, + $speed ), 'module_info' => 'Bandwidth usage sent from this interface over a particular time (see interval).', 'execution_type' => EXECUTION_TYPE_PLUGIN, diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index b178702bc0..bb67048661 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1743,7 +1743,7 @@ SET @plugin_name = 'Network bandwidth SNMP'; SET @plugin_description = 'Retrieves amount of digital information sent and received from device or filtered interface index over a particular time (agent/module interval).'; SET @plugin_id = ''; SELECT @plugin_id := `id` FROM `tplugin` WHERE `name` = @plugin_name; -INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_'; -inUsage '_field14_' -outUsage '_field15_''); +INSERT IGNORE INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`) VALUES (@plugin_id,@plugin_name,@plugin_description,300,0,'perl /usr/share/pandora_server/util/plugin/pandora_snmp_bandwidth.pl','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"SNMP Version(1,2c,3)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Community\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Host\",\"help\":\"\",\"value\":\"_address_\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Port\",\"help\":\"\",\"value\":\"161\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Interface Index (filter)\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"securityName\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"context\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"8\":{\"macro\":\"_field8_\",\"desc\":\"securityLevel\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"9\":{\"macro\":\"_field9_\",\"desc\":\"authProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"10\":{\"macro\":\"_field10_\",\"desc\":\"authKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"11\":{\"macro\":\"_field11_\",\"desc\":\"privProtocol\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"12\":{\"macro\":\"_field12_\",\"desc\":\"privKey\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"},\"13\":{\"macro\":\"_field13_\",\"desc\":\"UniqId\",\"help\":\"This plugin needs to store information in temporary directory to calculate bandwidth. Set here an unique identifier with no spaces or symbols.\",\"value\":\"\",\"hide\":\"\"},\"14\":{\"macro\":\"_field14_\",\"desc\":\"inUsage\",\"help\":\"Retrieve input usage (%)\",\"value\":\"\",\"hide\":\"\"},\"15\":{\"macro\":\"_field15_\",\"desc\":\"outUsage\",\"help\":\"Retrieve output usage (%)\",\"value\":\"\",\"hide\":\"\"}}','-version '_field1_' -community '_field2_' -host '_field3_' -port '_field4_' -ifIndex '_field5_' -securityName '_field6_' -context '_field7_' -securityLevel '_field8_' -authProtocol '_field9_' -authKey '_field10_' -privProtocol '_field11_' -privKey '_field12_' -uniqid '_field13_' -inUsage '_field14_' -outUsage '_field15_''); SET @main_component_group_name = 'Wizard'; SET @component_id = '';