From 434d97c8f4073e4996be2a46a9dbea1734ef0528 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Wed, 6 Feb 2013 18:01:53 +0000 Subject: [PATCH] 2013-02-06 Sergio Martin * lib/PandoraFMS/NetworkServer.pm lib/PandoraFMS/Tools.pm: Added check to the ping latency modules to difference the fail from the 0 latency. Now when the IP doenst exist or the ping fail, the module doesnt report any data. FIX: 3543467 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7600 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 ++++++++ pandora_server/lib/PandoraFMS/NetworkServer.pm | 5 ++++- pandora_server/lib/PandoraFMS/Tools.pm | 16 ++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index db9fcfe8c2..2f11b03646 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2013-02-06 Sergio Martin + + * lib/PandoraFMS/NetworkServer.pm + lib/PandoraFMS/Tools.pm: Added check to the ping latency + modules to difference the fail from the 0 latency. Now + when the IP doenst exist or the ping fail, the module + doesnt report any data. FIX: 3543467 + 2013-02-05 Sancho Lerena * util/pandora_manage.pl: Added feature for adding diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index 5c3d09371f..49975d8c13 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -456,7 +456,10 @@ sub exec_network_module ($$$$) { } elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms) $module_data = pandora_ping_latency ($pa_config, $ip_target, $timeout, $retries); - $module_result = 0; # Successful + + if (defined($module_data)) { + $module_result = 0; # Successful + } } # ------------------------------------------------------- diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 640121bf3f..9c98513265 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -889,7 +889,7 @@ sub pandora_ping ($$$$) { ######################################################################## =head2 C<< pandora_ping_latency (I<$pa_config>, I<$host>) >> -Ping the given host. Returns the average round-trip time. +Ping the given host. Returns the average round-trip time. Returns undef if fails. =cut ######################################################################## @@ -925,7 +925,7 @@ sub pandora_ping_latency ($$$$) { if ($output =~ m/\=\s([0-9]*)[a-z][a-z]\r/){ return $1; } else { - return 0; + return undef; } } @@ -944,11 +944,11 @@ sub pandora_ping_latency ($$$$) { my @output = `$ping_command -s -n $host 56 $retries 2>/dev/null`; # Something went wrong - return 0 if ($? != 0); + return undef if ($? != 0); # Parse the output my $stats = pop (@output); - return 0 unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); + return undef unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); return $2; } @@ -968,11 +968,11 @@ sub pandora_ping_latency ($$$$) { my @output = `$ping_command -q -n -c $retries $host 2>/dev/null`; # Something went wrong - return 0 if ($? != 0); + return undef if ($? != 0); # Parse the output my $stats = pop (@output); - return 0 unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); + return undef unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); return $2; } @@ -989,11 +989,11 @@ sub pandora_ping_latency ($$$$) { my @output = `$ping_command -q -W $timeout -n -c $retries $host 2>/dev/null`; # Something went wrong - return 0 if ($? != 0); + return undef if ($? != 0); # Parse the output my $stats = pop (@output); - return 0 unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); + return undef unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); return $2; }