From d3309d2f98335ce15b4f6733f575c26d2e3102b0 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 5 Jan 2015 16:37:41 +0100 Subject: [PATCH] Added support for absolute incremental data. --- .../pandoradb_migrate_5.1_to_6.0.mysql.sql | 6 ++ .../pandoradb_migrate_5.1_to_6.0.oracle.sql | 5 ++ ...andoradb_migrate_5.1_to_6.0.postgreSQL.sql | 5 ++ pandora_console/pandoradb.data.oracle.sql | 2 +- pandora_console/pandoradb.data.postgreSQL.sql | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 72 ++++++++++++++++--- .../lib/PandoraFMS/NetworkServer.pm | 4 +- 8 files changed, 85 insertions(+), 13 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql index 4130bdbb4b..05977d3052 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.mysql.sql @@ -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'); + diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql index 6cd60011d4..dcf223f6cc 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.oracle.sql @@ -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'); diff --git a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql index 851a739872..a0b2640837 100755 --- a/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_5.1_to_6.0.postgreSQL.sql @@ -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'); diff --git a/pandora_console/pandoradb.data.oracle.sql b/pandora_console/pandoradb.data.oracle.sql index 6db0aa3574..a225fd37e5 100644 --- a/pandora_console/pandoradb.data.oracle.sql +++ b/pandora_console/pandoradb.data.oracle.sql @@ -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'); diff --git a/pandora_console/pandoradb.data.postgreSQL.sql b/pandora_console/pandoradb.data.postgreSQL.sql index 7935d0b911..e79a4b661c 100644 --- a/pandora_console/pandoradb.data.postgreSQL.sql +++ b/pandora_console/pandoradb.data.postgreSQL.sql @@ -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'), diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 1406bd84ac..6ac04d679a 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -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'), diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 59425b2dca..131270e4ed 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -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'}; diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index ee98803905..c3544ac76d 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -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