diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 8377ba681a..881eaccdd6 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-08-04 Ramon Novoa + + * lib/PandoraFMS/Core.pm, + lib/PandoraFMS/ReconServer.pm, + lib/PandoraFMS/DataServer.pm: Set group, description and post_process + when auto-creating an agent/module. + 2009-08-03 Ramon Novoa * lib/PandoraFMS/Core.pm: Add id_agente to tagente_estado when diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index c0006bfba7..85924b0210 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -709,17 +709,18 @@ sub pandora_audit ($$$$$) { # Create a new entry in tagente_modulo and the corresponding entry in # tagente_estado. ########################################################################## -sub pandora_create_module ($$$$$$$$) { +sub pandora_create_module ($$$$$$$$$) { my ($agent_id, $module_type_id, $module_name, $max, - $min, $description, $interval, $dbh) = @_; + $min, $post_process, $description, $interval, $dbh) = @_; # Provide some default values $max = 0 if ($max eq ''); $min = 0 if ($min eq ''); + $post_process = 0 if ($post_process eq ''); $description = 'N/A' if ($description eq ''); - my $module_id = db_insert($dbh, 'INSERT INTO tagente_modulo (`id_agente`, `id_tipo_modulo`, `nombre`, `max`, `min`, `descripcion`, `module_interval`, `id_modulo`) - VALUES (?, ?, ?, ?, ?, ?, ?, 1)', $agent_id, $module_type_id, $module_name, $max, $min, $description, $interval); + my $module_id = db_insert($dbh, 'INSERT INTO tagente_modulo (`id_agente`, `id_tipo_modulo`, `nombre`, `max`, `min`, `post_process`, `descripcion`, `module_interval`, `id_modulo`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', $agent_id, $module_type_id, $module_name, $max, $min, $post_process, $description, $interval); db_do ($dbh, 'INSERT INTO tagente_estado (`id_agente_modulo`, `id_agente`, `last_try`) VALUES (?, ?, \'0000-00-00 00:00:00\')', $module_id, $agent_id); return $module_id; } @@ -727,14 +728,16 @@ sub pandora_create_module ($$$$$$$$) { ########################################################################## # Create a new entry in tagente. ########################################################################## -sub pandora_create_agent ($$$$$$$$$) { +sub pandora_create_agent ($$$$$$$$$$) { my ($pa_config, $server_name, $agent_name, $address, - $address_id, $group_id, $parent_id, $os_id, $dbh) = @_; + $address_id, $group_id, $parent_id, $os_id, + $description, $dbh) = @_; logger ($pa_config, "$server_name: Creating agent $agent_name ($address)", 1); + $description = "Created by $server_name" unless ($description ne ''); my $agent_id = db_insert ($dbh, 'INSERT INTO tagente (`nombre`, `direccion`, `comentarios`, `id_grupo`, `id_os`, `server_name`, `intervalo`, `id_parent`, `modo`) - VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1)', $agent_name, $address, "Created by $server_name", $group_id, $os_id, $server_name, $parent_id); + VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1)', $agent_name, $address, $description, $group_id, $os_id, $server_name, $parent_id); pandora_event ($pa_config, "Agent '$agent_name' created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh); return $agent_id; diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 9e552b39c4..f583725992 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -173,9 +173,16 @@ sub process_xml_data ($$$$) { return; } - # Create the agent + # Get OS, group and description my $os = pandora_get_os ($data->{'os'}); - $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $agent_name, '', 0, $pa_config->{'autocreate_group'}, 0, $os, $dbh); + my $group_id = undef; + $group_id = get_db_value ($dbh, 'SELECT id_grupo FROM tgrupo WHERE nombre = ?', $data->{'group'}) if (defined ($data->{'group'})); + $group_id = $pa_config->{'autocreate_group'} unless defined ($group_id); + my $description = ''; + $description = $data->{'description'} if (defined ($data->{'description'})); + + # Create the agent + $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $agent_name, '', 0, $group_id, 0, $os, $description, $dbh); return unless defined ($agent_id); } @@ -246,14 +253,18 @@ sub process_module_data ($$$$$$$$$) { my $module_id = get_module_id ($dbh, $module_type); return unless ($module_id > 0); - # Get min/max/description + # Get min/max/description/post process my $max = get_tag_value ($data, 'max', 0); my $min = get_tag_value ($data, 'min', 0); my $description = get_tag_value ($data, 'description', ''); + my $post_process = get_tag_value ($data, 'post_process', 0); + + # Allow , as a decimal separator + $post_process =~ s/,/./; # Create the module pandora_create_module ($agent->{'id_agente'}, $module_id, $module_name, - $max, $min, $description, $interval, $dbh); + $max, $min, $post_process, $description, $interval, $dbh); $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name); return unless defined $module; } diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index ef6195600b..ae44ff2924 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -174,7 +174,7 @@ sub data_consumer ($$) { # Crate a new agent my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $host_name, $addr, $addr_id, - $task->{'id_group'}, $parent_id, $id_os, $dbh); + $task->{'id_group'}, $parent_id, $id_os, '', $dbh); # Assign the new address to the agent db_insert ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`) VALUES (?, ?)', $addr_id, $agent_id);