Added support for absolute incremental data.
This commit is contained in:
parent
489b5ed490
commit
d3309d2f98
|
@ -43,3 +43,9 @@ CREATE TABLE IF NOT EXISTS `tuser_double_auth` (
|
|||
UNIQUE (`id_user`),
|
||||
FOREIGN KEY (`id_user`) REFERENCES tusuario(`id_user`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `ttipo_modulo`
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO `ttipo_modulo` VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png');
|
||||
|
||||
|
|
|
@ -31,3 +31,8 @@ CREATE TABLE tuser_double_auth (
|
|||
);
|
||||
CREATE SEQUENCE tuser_double_auth_s INCREMENT BY 1 START WITH 1;
|
||||
CREATE OR REPLACE TRIGGER tuser_double_auth_inc BEFORE INSERT ON tuser_double_auth REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tuser_double_auth_s.nextval INTO :NEW.ID FROM dual; END tuser_double_auth_inc;;
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `ttipo_modulo`
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO ttipo_modulo VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png');
|
||||
|
|
|
@ -29,3 +29,8 @@ CREATE TABLE "tuser_double_auth" (
|
|||
"id_user" varchar(60) NOT NULL UNIQUE REFERENCES "tusuario"("id_user") ON DELETE CASCADE,
|
||||
"secret" varchar(20) NOT NULL
|
||||
);
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `ttipo_modulo`
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO "ttipo_modulo" VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png');
|
||||
|
|
|
@ -269,7 +269,7 @@ INSERT INTO ttipo_modulo VALUES (1,'generic_data',0,'Generic data','mod_data.png
|
|||
INSERT INTO ttipo_modulo VALUES (2,'generic_proc',1,'Generic boolean','mod_proc.png');
|
||||
INSERT INTO ttipo_modulo VALUES (3,'generic_data_string',2,'Generic string','mod_string.png');
|
||||
INSERT INTO ttipo_modulo VALUES (4,'generic_data_inc',0,'Generic data incremental','mod_data_inc.png');
|
||||
|
||||
INSERT INTO ttipo_modulo VALUES (5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png');
|
||||
INSERT INTO ttipo_modulo VALUES (6,'remote_icmp_proc',4,'Remote ICMP network agent, boolean data','mod_icmp_proc.png');
|
||||
INSERT INTO ttipo_modulo VALUES (7,'remote_icmp',3,'Remote ICMP network agent (latency)','mod_icmp_data.png');
|
||||
INSERT INTO ttipo_modulo VALUES (8,'remote_tcp',3,'Remote TCP network agent, numeric data','mod_tcp_data.png');
|
||||
|
|
|
@ -251,7 +251,7 @@ INSERT INTO "ttipo_modulo" VALUES
|
|||
(2,'generic_proc',1,'Generic boolean','mod_proc.png'),
|
||||
(3,'generic_data_string',2,'Generic string','mod_string.png'),
|
||||
(4,'generic_data_inc',0,'Generic data incremental','mod_data_inc.png'),
|
||||
|
||||
(5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png'),
|
||||
(6,'remote_icmp_proc',4,'Remote ICMP network agent, boolean data','mod_icmp_proc.png'),
|
||||
(7,'remote_icmp',3,'Remote ICMP network agent (latency)','mod_icmp_data.png'),
|
||||
(8,'remote_tcp',3,'Remote TCP network agent, numeric data','mod_tcp_data.png'),
|
||||
|
|
|
@ -241,7 +241,7 @@ INSERT INTO `ttipo_modulo` VALUES
|
|||
(2,'generic_proc',1,'Generic boolean','mod_proc.png'),
|
||||
(3,'generic_data_string',2,'Generic string','mod_string.png'),
|
||||
(4,'generic_data_inc',0,'Generic numeric incremental','mod_data_inc.png'),
|
||||
|
||||
(5,'generic_data_inc_abs',0,'Generic numeric incremental (absolute)','mod_data_inc_abs.png'),
|
||||
(6,'remote_icmp_proc',4,'Remote ICMP network agent, boolean data','mod_icmp_proc.png'),
|
||||
(7,'remote_icmp',3,'Remote ICMP network agent (latency)','mod_icmp_data.png'),
|
||||
(8,'remote_tcp',3,'Remote TCP network agent, numeric data','mod_tcp_data.png'),
|
||||
|
|
|
@ -1114,9 +1114,8 @@ sub pandora_process_module ($$$$$$$$$;$) {
|
|||
}
|
||||
|
||||
# Process data
|
||||
my $processed_data = process_data ($pa_config, $data_object, $module, $module_type, $utimestamp, $dbh);
|
||||
my $processed_data = process_data ($pa_config, $data_object, $agent, $module, $module_type, $utimestamp, $dbh);
|
||||
if (! defined ($processed_data)) {
|
||||
logger($pa_config, "Received invalid data '" . $data_object->{'data'} . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
|
||||
pandora_update_module_on_error ($pa_config, $module, $dbh);
|
||||
return;
|
||||
}
|
||||
|
@ -3267,8 +3266,9 @@ sub on_demand_macro($$$$$$) {
|
|||
##########################################################################
|
||||
# Process module data.
|
||||
##########################################################################
|
||||
sub process_data ($$$$$$) {
|
||||
my ($pa_config, $data_object, $module, $module_type, $utimestamp, $dbh) = @_;
|
||||
sub process_data ($$$$$$$) {
|
||||
my ($pa_config, $data_object, $agent, $module,
|
||||
$module_type, $utimestamp, $dbh) = @_;
|
||||
|
||||
if ($module_type eq "log4x") {
|
||||
return log4x_get_severity_num($data_object);
|
||||
|
@ -3280,13 +3280,17 @@ sub process_data ($$$$$$) {
|
|||
if ($module_type =~ m/_string$/) {
|
||||
|
||||
# Empty strings are not allowed
|
||||
return undef if ($data eq '');
|
||||
if ($data eq '') {
|
||||
logger($pa_config, "Received invalid data '" . $data_object->{'data'} . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
# Not a number
|
||||
if (! is_numeric ($data)) {
|
||||
logger($pa_config, "Received invalid data '" . $data_object->{'data'} . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -3294,8 +3298,10 @@ sub process_data ($$$$$$) {
|
|||
$data =~ s/\,/\./;
|
||||
|
||||
# Out of bounds
|
||||
return undef if (($module->{'max'} != $module->{'min'}) &&
|
||||
($data > $module->{'max'} || $data < $module->{'min'}));
|
||||
if (($module->{'max'} != $module->{'min'}) && ($data > $module->{'max'} || $data < $module->{'min'})) {
|
||||
logger($pa_config, "Received invalid data '" . $data_object->{'data'} . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Process INC modules
|
||||
if ($module_type =~ m/_inc$/) {
|
||||
|
@ -3304,6 +3310,13 @@ sub process_data ($$$$$$) {
|
|||
# No previous data or error.
|
||||
return undef unless defined ($data);
|
||||
}
|
||||
# Process absolute INC modules
|
||||
elsif ($module_type =~ m/_inc_abs$/) {
|
||||
$data = process_inc_abs_data ($pa_config, $data, $module, $utimestamp, $dbh);
|
||||
|
||||
# No previous data or error.
|
||||
return undef unless defined ($data);
|
||||
}
|
||||
|
||||
# Post process
|
||||
if (is_numeric ($module->{'post_process'}) && $module->{'post_process'} != 0) {
|
||||
|
@ -3348,7 +3361,10 @@ sub process_inc_data ($$$$$) {
|
|||
}
|
||||
|
||||
# Should not happen
|
||||
return undef if ($utimestamp == $data_inc->{'utimestamp'});
|
||||
if ($utimestamp == $data_inc->{'utimestamp'}) {
|
||||
logger($pa_config, "Duplicate timestamp for incremental module " . $module->{'nombre'} . "(module id " . $module->{'id_agente_modulo'} . ").", 10);
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Update inc data
|
||||
db_do ($dbh, 'UPDATE tagente_datos_inc SET datos = ?, utimestamp = ? WHERE id_agente_modulo = ?', $data, $utimestamp, $module->{'id_agente_modulo'});
|
||||
|
@ -3356,6 +3372,46 @@ sub process_inc_data ($$$$$) {
|
|||
return ($data - $data_inc->{'datos'}) / ($utimestamp - $data_inc->{'utimestamp'});
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Process data of type *_inc_abs.
|
||||
##########################################################################
|
||||
sub process_inc_abs_data ($$$$$) {
|
||||
my ($pa_config, $data, $module, $utimestamp, $dbh) = @_;
|
||||
|
||||
my $data_inc = get_db_single_row ($dbh, 'SELECT * FROM tagente_datos_inc WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'});
|
||||
|
||||
# No previous data
|
||||
if (! defined ($data_inc)) {
|
||||
db_do ($dbh, 'INSERT INTO tagente_datos_inc
|
||||
(id_agente_modulo, datos, utimestamp)
|
||||
VALUES (?, ?, ?)', $module->{'id_agente_modulo'}, $data, $utimestamp);
|
||||
logger($pa_config, "Discarding first data for incremental module " . $module->{'nombre'} . "(module id " . $module->{'id_agente_modulo'} . ").", 10);
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Negative increment, reset inc data
|
||||
if ($data < $data_inc->{'datos'}) {
|
||||
db_do ($dbh, 'UPDATE tagente_datos_inc SET datos = ?, utimestamp = ? WHERE id_agente_modulo = ?', $data, $utimestamp, $module->{'id_agente_modulo'});
|
||||
logger($pa_config, "Discarding data and resetting counter for incremental module " . $module->{'nombre'} . "(module id " . $module->{'id_agente_modulo'} . ").", 10);
|
||||
|
||||
# Prevent the module from becoming unknown!
|
||||
db_do ($dbh, 'UPDATE tagente_estado SET utimestamp = ? WHERE id_agente_modulo = ?', time(), $module->{'id_agente_modulo'});
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Should not happen
|
||||
if ($utimestamp == $data_inc->{'utimestamp'}) {
|
||||
logger($pa_config, "Duplicate timestamp for incremental module " . $module->{'nombre'} . "(module id " . $module->{'id_agente_modulo'} . ").", 10);
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Update inc data
|
||||
db_do ($dbh, 'UPDATE tagente_datos_inc SET datos = ?, utimestamp = ? WHERE id_agente_modulo = ?', $data, $utimestamp, $module->{'id_agente_modulo'});
|
||||
|
||||
return ($data - $data_inc->{'datos'});
|
||||
}
|
||||
|
||||
sub log4x_get_severity_num($) {
|
||||
my ($data_object) = @_;
|
||||
my $data = $data_object->{'severity'};
|
||||
|
|
|
@ -102,7 +102,7 @@ sub data_producer ($) {
|
|||
WHERE server_name = ?
|
||||
AND tagente_modulo.id_agente = tagente.id_agente
|
||||
AND tagente.disabled = 0
|
||||
AND tagente_modulo.id_tipo_modulo > 4
|
||||
AND tagente_modulo.id_tipo_modulo > 5
|
||||
AND tagente_modulo.id_tipo_modulo < 19 '
|
||||
. (defined ($network_filter) ? $network_filter : ' ') .
|
||||
'AND tagente_modulo.disabled = 0
|
||||
|
@ -116,7 +116,7 @@ sub data_producer ($) {
|
|||
AND tagente_modulo.id_agente = tagente.id_agente
|
||||
AND tagente.disabled = 0
|
||||
AND tagente_modulo.disabled = 0
|
||||
AND tagente_modulo.id_tipo_modulo > 4
|
||||
AND tagente_modulo.id_tipo_modulo > 5
|
||||
AND tagente_modulo.id_tipo_modulo < 19 '
|
||||
. (defined ($network_filter) ? $network_filter : ' ') .
|
||||
'AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
|
||||
|
|
Loading…
Reference in New Issue