2007-05-18 Sancho Lerena <slerena@gmail.com>
* pandora_tools.pm, pandora_config.pm, pandora_db.pm: Many small fixes. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@458 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
abe8fa0c5f
commit
1247536ebc
|
@ -163,11 +163,14 @@ sub pandora_loadconfig {
|
|||
}
|
||||
}
|
||||
close (CFG);
|
||||
|
||||
# Process this array with commandline like options
|
||||
# Process input parameters
|
||||
|
||||
my @args = @command_line;
|
||||
my $parametro;
|
||||
my $ltotal=$#args; my $ax;
|
||||
my $ltotal=$#args;
|
||||
my $ax;
|
||||
|
||||
# Has read setup file ok ?
|
||||
if ( $ltotal == 0 ) {
|
||||
|
@ -304,7 +307,7 @@ sub pandora_loadconfig {
|
|||
# Dump all errors to errorlog
|
||||
# DISABLED in DEBUGMODE
|
||||
# ENABLE FOR PRODUCTION
|
||||
# open STDERR, ">>$pa_config->{'errorlogfile'}" or die "Can't write to Errorlog : $!";
|
||||
#open STDERR, ">>$pa_config->{'errorlogfile'}" or die "Can't write to Errorlog : $!";
|
||||
}
|
||||
|
||||
# End of function declaration
|
||||
|
|
|
@ -601,18 +601,17 @@ sub module_generic_data_inc (%$$$$$) {
|
|||
my $a_desc = $datos->{description}->[0];
|
||||
my $m_data = $datos->{data}->[0];
|
||||
my $a_max = $datos->{max}->[0];
|
||||
my $a_min = $datos->{min}->[0];
|
||||
|
||||
if (ref($m_data) ne "HASH"){
|
||||
my $a_min = $datos->{min}->[0];
|
||||
if (is_numeric($m_data)){
|
||||
$m_data =~ s/\,/\./g; # replace "," by "."
|
||||
$m_data = sprintf("%.2f", $m_data); # Two decimal float. We cannot store more
|
||||
# to change this, you need to change mysql structure
|
||||
$m_data =~ s/\,/\./g; # replace "," by "."
|
||||
|
||||
if (ref($a_max) eq "HASH") {
|
||||
if (!is_numeric($a_max)) {
|
||||
$a_max = "";
|
||||
}
|
||||
if (ref($a_min) eq "HASH") {
|
||||
if (!is_numeric($a_min)) {
|
||||
$a_min = "";
|
||||
}
|
||||
# my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
||||
|
@ -650,8 +649,16 @@ sub module_generic_data_inc (%$$$$$) {
|
|||
my $s_idag = $dbh->prepare($query_idag);
|
||||
$s_idag->execute;
|
||||
my @data_row = $s_idag->fetchrow_array();
|
||||
$data_anterior = $data_row[2];
|
||||
$timestamp_anterior = $data_row[4];
|
||||
if (is_numeric($data_row[2])){
|
||||
$data_anterior = $data_row[2];
|
||||
} else {
|
||||
$data_anterior = 0;
|
||||
}
|
||||
if (is_numeric($data_row[4])){
|
||||
$timestamp_anterior = $data_row[4];
|
||||
} else {
|
||||
$timestamp_anterior = 0;
|
||||
}
|
||||
|
||||
$diferencia = $m_data - $data_anterior;
|
||||
$timestamp_diferencia = $m_utimestamp - $timestamp_anterior;
|
||||
|
@ -667,12 +674,12 @@ sub module_generic_data_inc (%$$$$$) {
|
|||
|
||||
# Update of tagente_datos_inx (AUX TABLE)
|
||||
if ($no_existe == 1){
|
||||
my $query = "INSERT INTO tagente_datos_inc (id_agente_modulo,datos, timestamp) VALUES ($id_agente_modulo, '$m_data', '$m_timestamp', $m_utimestamp)";
|
||||
my $query = "INSERT INTO tagente_datos_inc (id_agente_modulo,datos, timestamp, utimestamp) VALUES ($id_agente_modulo, '$m_data', '$m_timestamp', $m_utimestamp)";
|
||||
$dbh->do($query);
|
||||
} else {
|
||||
# Data exists previously
|
||||
if ($diferencia != 0) {
|
||||
my $query2 = "UPDATE tagente_datos_inc SET utimestamp = $m_utimestamp, datos = '$m_data' WHERE id_agente_modulo = $id_agente_modulo";
|
||||
my $query2 = "UPDATE tagente_datos_inc SET timestamp='$m_timestamp', utimestamp = $m_utimestamp, datos = '$m_data' WHERE id_agente_modulo = $id_agente_modulo";
|
||||
$dbh->do($query2);
|
||||
}
|
||||
}
|
||||
|
@ -855,14 +862,14 @@ sub pandora_writedata (%$$$$$$$$$$){
|
|||
$timestamp = $dbh->quote($timestamp);
|
||||
# Parse data entry for adecuate SQL representation.
|
||||
$query = "INSERT INTO tagente_datos_string (id_agente_modulo, datos, timestamp, utimestamp, id_agente) VALUES ($id_agente_modulo, $datos, $timestamp, $utimestamp, $id_agente)";
|
||||
} else {
|
||||
} elsif (is_numeric($datos)){
|
||||
if ($max != $min) {
|
||||
if ($datos > $max) {
|
||||
if (int($datos) > $max) {
|
||||
$datos = $max;
|
||||
$outlimit=1;
|
||||
logger($pa_config,"DEBUG: MAX Value reached ($max) for agent $nombre_agente / $nombre_modulo",6);
|
||||
}
|
||||
if ($datos < $min) {
|
||||
if (int($datos) < $min) {
|
||||
$datos = $min;
|
||||
$outlimit = 1;
|
||||
logger($pa_config, "DEBUG: MIN Value reached ($min) for agent $nombre_agente / $nombre_modulo",6);
|
||||
|
|
|
@ -63,21 +63,25 @@ sub daemonize {
|
|||
# Return TRUE if given argument is numeric
|
||||
##########################################################################
|
||||
|
||||
sub getnum {
|
||||
use POSIX qw(strtod);
|
||||
my $str = shift;
|
||||
$str =~ s/^\s+//;
|
||||
$str =~ s/\s+$//;
|
||||
$! = 0;
|
||||
my($num, $unparsed) = strtod($str);
|
||||
if (($str eq '') || ($unparsed != 0) || $!) {
|
||||
return undef;
|
||||
} else {
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
|
||||
sub is_numeric { defined getnum($_[0]) }
|
||||
sub is_numeric {
|
||||
$x = $_[0];
|
||||
if (!defined ($x)){
|
||||
return 0;
|
||||
}
|
||||
if ($x eq ""){
|
||||
return 0;
|
||||
}
|
||||
# Integer ?
|
||||
if ($x =~ /^-?\d/) {
|
||||
return 1;
|
||||
}
|
||||
# Float ?
|
||||
if ($x =~ /^-?\d*\./){
|
||||
return 1;
|
||||
}
|
||||
# If not, this thing is not a number
|
||||
return 0;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# SUB md5check (param_1, param_2)
|
||||
|
|
Loading…
Reference in New Issue