From 890cfe68aac1cb8c2e4040215b3ef3f505604bf5 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 6 Apr 2020 18:04:53 +0200 Subject: [PATCH] multiple fixes --- pandora_server/lib/PandoraFMS/Core.pm | 10 ++++++++-- pandora_server/lib/PandoraFMS/DB.pm | 6 ++++++ pandora_server/lib/PandoraFMS/DiscoveryServer.pm | 12 ++++++++---- pandora_server/lib/PandoraFMS/Recon/Base.pm | 16 +++++++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 96777fe158..1bb16f5db6 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -6276,7 +6276,10 @@ sub notification_get_users { safe_input($source) ); - @results = map { $_->{'id_user'} } @results; + @results = map { + if(ref($_) eq 'HASH') { $_->{'id_user'} } + else {} + } @results; return @results; } @@ -6301,7 +6304,10 @@ sub notification_get_groups { safe_input($source) ); - @results = map { $_->{'id_group'} } @results; + @results = map { + if(ref($_) eq 'HASH') { $_->{'id_group'} } + else {} + } @results; return @results; } diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 48c42477ca..e5c63615e0 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -675,6 +675,12 @@ sub get_pen_templates($$) { $pen ); + @results = map { + if (ref($_) eq 'HASH') { $_->{'id_np'} } + else {} + } @results; + + return @results; } diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index ad71eb829f..cee5efe451 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -545,7 +545,8 @@ sub PandoraFMS::Recon::Base::test_module($$) { $test->{'id_tipo_modulo'} ) ) { - # Numeric. + # Numeric. Remove " symbols if any. + $value =~ s/\"//g; return 0 unless is_numeric($value); if (is_in_array([2,6,9,18,21,31,35], $test->{'id_tipo_modulo'})) { @@ -842,7 +843,9 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$) { if (is_enabled($self->{'task_data'}{'auto_monitor'})) { # Apply PEN monitoring template (HW). - push @template_ids, get_pen_templates($self->{'dbh'}, $self->get_pen($device)); + my @pen_templates= get_pen_templates($self->{'dbh'}, $self->get_pen($device)); + # Join. + @template_ids = (@template_ids, @pen_templates); } else { # Return if no specific templates are selected. return if is_empty($self->{'id_network_profile'}); @@ -861,7 +864,7 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$) { if (defined($template->{'pen'})) { my @penes = split(',', $template->{'pen'}); - next unless (is_in_array(\@penes, $data->{'pen'})); + next unless (is_in_array(\@penes, $self->get_pen($device))); } # 3. Retrieve module list from target template. @@ -1595,8 +1598,9 @@ sub PandoraFMS::Recon::Base::update_progress ($$) { my $stats = {}; if (defined($self->{'summary'}) && $self->{'summary'} ne '') { - $stats->{'summary'} = $self->{'task_data'}{'summary'}; + $stats->{'summary'} = $self->{'summary'}; } + $stats->{'step'} = $self->{'step'}; $stats->{'c_network_name'} = $self->{'c_network_name'}; $stats->{'c_network_percent'} = $self->{'c_network_percent'}; diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 7966e97de0..9130fccb6a 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1360,8 +1360,11 @@ sub add_module($$$) { return unless ref($data) eq 'HASH' && defined($data->{'name'}) && $data->{'name'} ne ''; - # Test module. Is it success? + # Test module. Is it success? Some components have MIB name instead OID. + $self->{'translate_snmp'} = 1; my $rs = $self->call('test_module', $agent, $data); + $self->{'translate_snmp'} = 0; + return unless is_enabled($rs); $self->{'agents_found'}->{$agent}->{'modules'}{$data->{'name'}} = $data; @@ -2059,10 +2062,17 @@ sub snmp_get_command { sub snmp_get_value($$$) { my ($self, $device, $oid) = @_; - my @output = $self->snmp_get($device, $oid); + my $effective_oid = $oid; + if (is_enabled($self->{'translate_snmp'})) { + $effective_oid = `snmptranslate $oid -On 2>$DEVNULL`; + chomp($effective_oid); + } + + my @output = $self->snmp_get($device, $effective_oid); + foreach my $line (@output) { chomp($line); - return $1 if ($line =~ /^$oid\s+=\s+\S+:\s+(.*)$/); + return $1 if ($line =~ /^$effective_oid\s+=\s+\S+:\s+(.*)$/); } return undef;