diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql index 02a88c4d61..cd6bdc0933 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql @@ -88,6 +88,7 @@ ALTER TABLE tusuario ADD CONSTRAINT fk_id_filter FOREIGN KEY (id_filter) REFEREN -- --------------------------------------------------------------------- ALTER TABLE tagente_modulo ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0'; ALTER TABLE tagente_modulo ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0'; +ALTER TABLE tagente_modulo ADD COLUMN `parent_module_id` int(10) unsigned NOT NULL; -- --------------------------------------------------------------------- -- Table `tagente_datos` diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql index ceb6b8a414..20941d72af 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql @@ -76,6 +76,7 @@ ALTER TABLE tagente_modulo ADD COLUMN dynamic_max bigint(20) default '0'; ALTER TABLE tagente_modulo ADD COLUMN dynamic_min bigint(20) default '0'; ALTER TABLE tagente_modulo ADD COLUMN dynamic_next bigint(20) NOT NULL default '0'; ALTER TABLE tagente_modulo ADD COLUMN dynamic_two_tailed tinyint(1) unsigned default '0'; +ALTER TABLE tagente_modulo ADD COLUMN parent_module_id NUMBER(10, 0); -- --------------------------------------------------------------------- -- Table `tnetwork_component` diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index d912c120ee..8ee3810d8a 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -290,6 +290,7 @@ CREATE TABLE tagente_modulo ( prediction_sample_window INTEGER default 0, prediction_samples INTEGER default 0, prediction_threshold INTEGER default 0, + parent_module_id NUMBER(10, 0), CONSTRAINT t_agente_modulo_wizard_cons CHECK (wizard_level IN ('basic','advanced','nowizard')) ); CREATE INDEX tagente_modulo_id_agente_idx ON tagente_modulo(id_agente); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b97ac02b05..398f05dc87 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -252,6 +252,7 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` ( `prediction_sample_window` int(10) default 0, `prediction_samples` int(4) default 0, `prediction_threshold` int(4) default 0, + `parent_module_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id_agente_modulo`), KEY `main_idx` (`id_agente_modulo`,`id_agente`), KEY `tam_agente` (`id_agente`), diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 02b16bcdc3..a9883ea605 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -563,6 +563,27 @@ sub process_xml_data ($$$$$) { } } + # Link modules + foreach my $module_data (@{$data->{'module'}}) { + + my $module_name = get_tag_value ($module_data, 'name', ''); + $module_name =~ s/\r//g; + $module_name =~ s/\n//g; + + # Unnamed module + next if ($module_name eq ''); + + # No parent module defined + my $parent_module_name = get_tag_value ($module_data, 'module_parent', undef); + if (! defined ($parent_module_name)) { + use Data::Dumper; + print Dumper($module_data); + next; + } + + link_modules($pa_config, $dbh, $agent_id, $module_name, $parent_module_name); + } + # Process inventory modules enterprise_hook('process_inventory_data', [$pa_config, $data, $server_id, $agent_name, $interval, $timestamp, $dbh]); @@ -884,5 +905,25 @@ sub process_xml_server ($$$$) { pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version, $data->{'keepalive'}); } + +############################################################################### +# Link two modules +############################################################################### +sub link_modules { + my ($pa_config, $dbh, $agent_id, $child_name, $parent_name) = @_; + + # Get the child module ID. + my $child_id = get_agent_module_id ($dbh, $child_name, $agent_id); + return unless ($child_id != -1); + + # Get the parent module ID. + my $parent_id = get_agent_module_id ($dbh, $parent_name, $agent_id); + return unless ($parent_id != -1); + + # Link them. + logger($pa_config, "Linking module $child_name to module $parent_name for agent ID $agent_id", 10); + db_do($dbh, "UPDATE tagente_modulo SET parent_module_id = ? WHERE id_agente_modulo = ?", $parent_id, $child_id); +} + 1; __END__