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);
|
close (CFG);
|
||||||
|
|
||||||
# Process this array with commandline like options
|
# Process this array with commandline like options
|
||||||
# Process input parameters
|
# Process input parameters
|
||||||
|
|
||||||
my @args = @command_line;
|
my @args = @command_line;
|
||||||
my $parametro;
|
my $parametro;
|
||||||
my $ltotal=$#args; my $ax;
|
my $ltotal=$#args;
|
||||||
|
my $ax;
|
||||||
|
|
||||||
# Has read setup file ok ?
|
# Has read setup file ok ?
|
||||||
if ( $ltotal == 0 ) {
|
if ( $ltotal == 0 ) {
|
||||||
|
@ -304,7 +307,7 @@ sub pandora_loadconfig {
|
||||||
# Dump all errors to errorlog
|
# Dump all errors to errorlog
|
||||||
# DISABLED in DEBUGMODE
|
# DISABLED in DEBUGMODE
|
||||||
# ENABLE FOR PRODUCTION
|
# 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
|
# End of function declaration
|
||||||
|
|
|
@ -601,18 +601,17 @@ sub module_generic_data_inc (%$$$$$) {
|
||||||
my $a_desc = $datos->{description}->[0];
|
my $a_desc = $datos->{description}->[0];
|
||||||
my $m_data = $datos->{data}->[0];
|
my $m_data = $datos->{data}->[0];
|
||||||
my $a_max = $datos->{max}->[0];
|
my $a_max = $datos->{max}->[0];
|
||||||
my $a_min = $datos->{min}->[0];
|
my $a_min = $datos->{min}->[0];
|
||||||
|
if (is_numeric($m_data)){
|
||||||
if (ref($m_data) ne "HASH"){
|
|
||||||
$m_data =~ s/\,/\./g; # replace "," by "."
|
$m_data =~ s/\,/\./g; # replace "," by "."
|
||||||
$m_data = sprintf("%.2f", $m_data); # Two decimal float. We cannot store more
|
$m_data = sprintf("%.2f", $m_data); # Two decimal float. We cannot store more
|
||||||
# to change this, you need to change mysql structure
|
# to change this, you need to change mysql structure
|
||||||
$m_data =~ s/\,/\./g; # replace "," by "."
|
$m_data =~ s/\,/\./g; # replace "," by "."
|
||||||
|
|
||||||
if (ref($a_max) eq "HASH") {
|
if (!is_numeric($a_max)) {
|
||||||
$a_max = "";
|
$a_max = "";
|
||||||
}
|
}
|
||||||
if (ref($a_min) eq "HASH") {
|
if (!is_numeric($a_min)) {
|
||||||
$a_min = "";
|
$a_min = "";
|
||||||
}
|
}
|
||||||
# my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
# 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);
|
my $s_idag = $dbh->prepare($query_idag);
|
||||||
$s_idag->execute;
|
$s_idag->execute;
|
||||||
my @data_row = $s_idag->fetchrow_array();
|
my @data_row = $s_idag->fetchrow_array();
|
||||||
$data_anterior = $data_row[2];
|
if (is_numeric($data_row[2])){
|
||||||
$timestamp_anterior = $data_row[4];
|
$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;
|
$diferencia = $m_data - $data_anterior;
|
||||||
$timestamp_diferencia = $m_utimestamp - $timestamp_anterior;
|
$timestamp_diferencia = $m_utimestamp - $timestamp_anterior;
|
||||||
|
@ -667,12 +674,12 @@ sub module_generic_data_inc (%$$$$$) {
|
||||||
|
|
||||||
# Update of tagente_datos_inx (AUX TABLE)
|
# Update of tagente_datos_inx (AUX TABLE)
|
||||||
if ($no_existe == 1){
|
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);
|
$dbh->do($query);
|
||||||
} else {
|
} else {
|
||||||
# Data exists previously
|
# Data exists previously
|
||||||
if ($diferencia != 0) {
|
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);
|
$dbh->do($query2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -855,14 +862,14 @@ sub pandora_writedata (%$$$$$$$$$$){
|
||||||
$timestamp = $dbh->quote($timestamp);
|
$timestamp = $dbh->quote($timestamp);
|
||||||
# Parse data entry for adecuate SQL representation.
|
# 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)";
|
$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 ($max != $min) {
|
||||||
if ($datos > $max) {
|
if (int($datos) > $max) {
|
||||||
$datos = $max;
|
$datos = $max;
|
||||||
$outlimit=1;
|
$outlimit=1;
|
||||||
logger($pa_config,"DEBUG: MAX Value reached ($max) for agent $nombre_agente / $nombre_modulo",6);
|
logger($pa_config,"DEBUG: MAX Value reached ($max) for agent $nombre_agente / $nombre_modulo",6);
|
||||||
}
|
}
|
||||||
if ($datos < $min) {
|
if (int($datos) < $min) {
|
||||||
$datos = $min;
|
$datos = $min;
|
||||||
$outlimit = 1;
|
$outlimit = 1;
|
||||||
logger($pa_config, "DEBUG: MIN Value reached ($min) for agent $nombre_agente / $nombre_modulo",6);
|
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
|
# Return TRUE if given argument is numeric
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
sub getnum {
|
sub is_numeric {
|
||||||
use POSIX qw(strtod);
|
$x = $_[0];
|
||||||
my $str = shift;
|
if (!defined ($x)){
|
||||||
$str =~ s/^\s+//;
|
return 0;
|
||||||
$str =~ s/\s+$//;
|
}
|
||||||
$! = 0;
|
if ($x eq ""){
|
||||||
my($num, $unparsed) = strtod($str);
|
return 0;
|
||||||
if (($str eq '') || ($unparsed != 0) || $!) {
|
}
|
||||||
return undef;
|
# Integer ?
|
||||||
} else {
|
if ($x =~ /^-?\d/) {
|
||||||
return $num;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
# Float ?
|
||||||
|
if ($x =~ /^-?\d*\./){
|
||||||
sub is_numeric { defined getnum($_[0]) }
|
return 1;
|
||||||
|
}
|
||||||
|
# If not, this thing is not a number
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SUB md5check (param_1, param_2)
|
# SUB md5check (param_1, param_2)
|
||||||
|
|
Loading…
Reference in New Issue