From 042362991de4260201d1ec506867f5dedb91f517 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 28 Sep 2022 15:34:45 +0200 Subject: [PATCH] implemented option to skip inoperative interfaces on demand --- pandora_console/extras/mr/58.sql | 5 ++++ .../godmode/wizards/HostDevices.class.php | 23 +++++++++++++++++++ pandora_console/pandoradb.sql | 1 + .../lib/PandoraFMS/DiscoveryServer.pm | 10 +++++--- pandora_server/lib/PandoraFMS/Recon/Base.pm | 2 ++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 pandora_console/extras/mr/58.sql diff --git a/pandora_console/extras/mr/58.sql b/pandora_console/extras/mr/58.sql new file mode 100644 index 0000000000..059089c3df --- /dev/null +++ b/pandora_console/extras/mr/58.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `trecon_task` ADD COLUMN `snmp_skip_non_enabled_ifs` TINYINT UNSIGNED DEFAULT 1; + +COMMIT; diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index cf4f6fe87b..0e147db456 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -509,6 +509,7 @@ class HostDevices extends Wizard $snmp_privacy_pass = get_parameter('snmp_privacy_pass', null); $snmp_auth_method = get_parameter('snmp_auth_method', null); $snmp_security_level = get_parameter('snmp_security_level', null); + $snmp_skip_non_enabled_ifs = get_parameter_switch('snmp_skip_non_enabled_ifs'); $auth_strings = get_parameter('auth_strings', []); if ($snmp_version == 3) { @@ -556,6 +557,7 @@ class HostDevices extends Wizard $this->task['snmp_privacy_pass'] = $snmp_privacy_pass; $this->task['snmp_auth_method'] = $snmp_auth_method; $this->task['snmp_security_level'] = $snmp_security_level; + $this->task['snmp_skip_non_enabled_ifs'] = $snmp_skip_non_enabled_ifs; $this->task['auth_strings'] = ''; if (is_array($auth_strings) === true) { $this->task['auth_strings'] = join( @@ -1213,6 +1215,24 @@ class HostDevices extends Wizard ], ]; + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_skip_non_enabled_ifs', + 'class' => 'indented', + 'block_content' => [ + [ + 'label' => __('Skip non-enabled interfaces'), + 'arguments' => [ + 'name' => 'snmp_skip_non_enabled_ifs', + 'type' => 'switch', + 'value' => (isset($this->task['snmp_enabled']) === true) ? $this->task['snmp_skip_non_enabled_ifs'] : 1, + 'size' => 25, + 'return' => true, + ], + ], + ], + ]; + // SNMP Options pack v1. $form['inputs'][] = [ 'hidden' => 1, @@ -1485,6 +1505,7 @@ class HostDevices extends Wizard function SNMPExtraShow(target) { $("#snmp_options_basic").hide(); + $("#snmp_options_skip_non_enabled_ifs").hide(); $("#snmp_options_v3").hide(); if (document.getElementsByName("snmp_enabled")[0].checked) { $("#snmp_extra").show(); @@ -1492,6 +1513,7 @@ class HostDevices extends Wizard $("#snmp_options_v3").show(); } else { $("#snmp_options_basic").show(); + $("#snmp_options_skip_non_enabled_ifs").show(); } } } @@ -1517,6 +1539,7 @@ class HostDevices extends Wizard // Hide unusable sections $("#snmp_extra").hide(); $("#snmp_options_basic").hide(); + $("#snmp_options_skip_non_enabled_ifs").hide(); $("#snmp_options_v3").hide(); // Disable snmp dependant checks diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index f3c3e61472..46b24a20c9 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -874,6 +874,7 @@ CREATE TABLE IF NOT EXISTS `trecon_task` ( `summary` TEXT, `type` INT NOT NULL DEFAULT 0, `subnet_csv` TINYINT UNSIGNED DEFAULT 0, + `snmp_skip_non_enabled_ifs` TINYINT UNSIGNED DEFAULT 1, PRIMARY KEY (`id_rt`), KEY `recon_task_daemon` (`id_recon_server`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 0d9660b733..e6c42fab34 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -273,6 +273,7 @@ sub data_consumer ($$) { snmp_security_level => $task->{'snmp_security_level'}, snmp_timeout => $task->{'snmp_timeout'}, snmp_version => $task->{'snmp_version'}, + snmp_skip_non_enabled_ifs => $task->{'snmp_skip_non_enabled_ifs'}, subnets => \@subnets, task_id => $task->{'id_rt'}, vlan_cache_enabled => $task->{'vlan_enabled'}, @@ -723,9 +724,12 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { foreach my $if_index (@output) { next unless ($if_index =~ /^[0-9]+$/); - # Check the status of the interface. - my $if_status = $self->snmp_get_value($device, "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index"); - next unless $if_status == 1; + if ($self->{'task_data'}{'snmp_skip_non_enabled_ifs'} == 1) { + # Check the status of the interface. + my $if_status = $self->snmp_get_value($device, "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index"); + + next unless $if_status == 1; + } # Fill the module description with the IP and MAC addresses. my $mac = $self->get_if_mac($device, $if_index); diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 5fa1dd8d1c..216c26b663 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -212,6 +212,7 @@ sub new { snmp_security_level => '', snmp_timeout => 2, snmp_version => 1, + snmp_skip_non_enabled_ifs => 1, subnets => [], autoconfiguration_enabled => 0, @@ -309,6 +310,7 @@ sub new { $self->{'snmp_privacy_method'} = ''; $self->{'snmp_privacy_pass'} = ''; $self->{'snmp_security_level'} = ''; + $self->{'snmp_skip_non_enabled_ifs'} = ''; } return $self;