From a478cb3951bef749da28fa8c1eb067fa30e6fc96 Mon Sep 17 00:00:00 2001 From: jsatoh Date: Wed, 28 Jul 2010 01:10:27 +0000 Subject: [PATCH] 2010-07-28 Junichi Satoh * lib/PandoraFMS/PredictionServer.pm: Fixed problem that pandora server daemon is aborted by division by zero, if numeric data to predict are mostly 0. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3071 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 ++++++ pandora_server/lib/PandoraFMS/PredictionServer.pm | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 371f2b0a24..ff41b94000 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2010-07-28 Junichi Satoh + + * lib/PandoraFMS/PredictionServer.pm: Fixed problem that pandora + server daemon is aborted by division by zero, if numeric data to + predict are mostly 0. + 2010-07-27 Ramon Novoa * lib/PandoraFMS/Core.pm: Make sure delete_pending is set to 0 diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index 933d9ab55f..51f9879c5e 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -205,7 +205,7 @@ sub exec_prediction_module ($$$$) { next unless defined ($first_data); $sum_data++ if ($last_data != 0); $sum_data++ if ($first_data != 0); - $week_data[$i] = (($last_data + $first_data) / $sum_data); + $week_data[$i] = ($sum_data > 0) ? (($last_data + $first_data) / $sum_data) : 0; } else { $week_data[$i] = $average_interval; } @@ -232,7 +232,7 @@ sub exec_prediction_module ($$$$) { $typical_deviation = $typical_deviation + (($week_data[$i] - $average)**2); } } - $typical_deviation = sqrt ($typical_deviation / ($n-1)); + $typical_deviation = ($n > 1) ? sqrt ($typical_deviation / ($n-1)) : 0; my $current_value = get_db_value ($dbh, 'SELECT datos FROM tagente_estado WHERE id_agente_modulo = ?', $target_module->{'id_agente_modulo'}); if ( ($current_value > ($average - $typical_deviation)) && ($current_value < ($average + $typical_deviation)) ){