From 04d255f7f809fbf5232e814b5b59977138cf1597 Mon Sep 17 00:00:00 2001 From: slerena Date: Mon, 19 Oct 2009 10:42:42 +0000 Subject: [PATCH] 2009-10-20 Sancho Lerena * tools.pm, core.pm: Float data with "," will be replace this character with "." and manage it properly as float. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2035 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 ++++++ pandora_server/lib/PandoraFMS/Core.pm | 7 ++++++- pandora_server/lib/PandoraFMS/Tools.pm | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index e46c4b4733..bd4f874d1c 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2009-10-20 Sancho Lerena + + * tools.pm, core.pm: Float data with "," will be replace this + character with "." and manage it properly as float. + + 2009-10-16 Sancho Lerena * util/pandora_server: Updated error string when service cannot startup diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 0f0a223210..2cc278e14a 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1010,10 +1010,13 @@ sub process_data ($$$$$) { return undef; } + # If is a number, we need to replace "," for "." + $data =~ s/\,/\./; + # Out of bounds return undef if (($module->{'max'} != $module->{'min'}) && ($data > $module->{'max'} || $data < $module->{'min'})); - + # Process INC modules if ($module_type =~ m/_inc$/) { $data = process_inc_data ($data, $module, $utimestamp, $dbh); @@ -1027,6 +1030,8 @@ sub process_data ($$$$$) { $data = $data * $module->{'post_process'}; } + # TODO: Float precission should be adjusted here in the future with a global + # config parameter # Format data $data = sprintf("%.2f", $data); diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 378647edcd..011f314a60 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -191,15 +191,17 @@ sub is_numeric { if (!defined($val)){ return 0; } + # Replace "," for "." + $val =~ s/\,/\./; - my $DIGITS = qr{ \d+ (?: [.] \d*)? | [.] \d+ }xms; - my $SIGN = qr{ [+-] }xms; - my $NUMBER = qr{ ($SIGN?) ($DIGITS) }xms; - if ( $val !~ /^${NUMBER}$/ ) { - return 0; #Non-numeric - } else { - return 1; #Numeric - } + my $DIGITS = qr{ \d+ (?: [.] \d*)? | [.] \d+ }xms; + my $SIGN = qr{ [+-] }xms; + my $NUMBER = qr{ ($SIGN?) ($DIGITS) }xms; + if ( $val !~ /^${NUMBER}$/ ) { + return 0; #Non-numeric + } else { + return 1; #Numeric + } } ##########################################################################