From 694d82e522cc73d37ce403168327ed8ace9150d6 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 13 May 2020 12:37:08 +0200 Subject: [PATCH] avoid div by 0 error while scanning networks with no hosts --- .../lib/PandoraFMS/DiscoveryServer.pm | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 1b9c433700..5942be2ee6 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -1502,28 +1502,31 @@ sub PandoraFMS::Recon::Base::apply_monitoring($) { my @hosts = keys %{$self->{'agents_found'}}; - $self->{'step'} = STEP_MONITORING; - # From 80% to 90%. - my ($progress, $step) = (80, 10.0 / scalar(@hosts)); - my ($partial, $sub_step) = (0, 100 / scalar(@hosts)); + if (scalar @hosts > 0) { + $self->{'step'} = STEP_MONITORING; + # From 80% to 90%. + my ($progress, $step) = (80, 10.0 / scalar(@hosts)); + my ($partial, $sub_step) = (0, 100 / scalar(@hosts)); - foreach my $label (keys %{$self->{'agents_found'}}) { - $self->{'c_network_percent'} = $partial; - $self->{'c_network_name'} = $label; - $self->call('update_progress', $progress); - $progress += $step; - $partial += $sub_step; - $self->call('message', "Checking modules for $label", 5); + foreach my $label (keys %{$self->{'agents_found'}}) { + $self->{'c_network_percent'} = $partial; + $self->{'c_network_name'} = $label; + $self->call('update_progress', $progress); + $progress += $step; + $partial += $sub_step; + $self->call('message', "Checking modules for $label", 5); - # Monitorization selected. - $self->call('create_network_profile_modules', $label); + # Monitorization selected. + $self->call('create_network_profile_modules', $label); - # Monitorization - interfaces - $self->call('create_interface_modules', $label); + # Monitorization - interfaces + $self->call('create_interface_modules', $label); - # Monitorization - WMI modules. - $self->call('create_wmi_modules', $label); + # Monitorization - WMI modules. + $self->call('create_wmi_modules', $label); + } + } $self->{'c_network_percent'} = 100;