2009-04-16 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/ProducerConsumerServer.pm: Important fix. Queued
          elements were processed in the wrong order.

        * lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
          lib/PandoraFMS/DataServer.pm: Updated pandora_create_agent to
          reflect the latest changes. Some fixes to Recon Server.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1622 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-04-16 18:19:39 +00:00
parent 6b466febe1
commit 726c1a8ba0
5 changed files with 44 additions and 40 deletions

View File

@ -1,3 +1,13 @@
2009-04-16 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/ProducerConsumerServer.pm: Important fix. Queued
elements were processed in the wrong order.
* lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm: Updated pandora_create_agent to
reflect the latest changes. Some fixes to Recon Server.
2009-04-16 Ramon Novoa <rnovoa@artica.es> 2009-04-16 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/ReconServer.pm: Fixed a typo that made the server go * lib/PandoraFMS/ReconServer.pm: Fixed a typo that made the server go

View File

@ -723,20 +723,14 @@ sub pandora_create_module ($$$$$$$) {
########################################################################## ##########################################################################
# Create a new entry in tagente. # Create a new entry in tagente.
########################################################################## ##########################################################################
sub pandora_create_agent ($$$$$$$$$$) { sub pandora_create_agent ($$$$$$$$$) {
my ($pa_config, $server_name, $agent_name, $address, my ($pa_config, $server_name, $agent_name, $address,
$address_id, $group_id, $server_id, $parent_id, $address_id, $group_id, $parent_id, $os_id, $dbh) = @_;
$os_id, $dbh) = @_;
logger ($pa_config, "$server_name: Creating agent $agent_name ($address)", 1); logger ($pa_config, "$server_name: Creating agent $agent_name ($address)", 1);
if ($server_id eq '') { my $agent_id = db_insert ($dbh, 'INSERT INTO tagente (`nombre`, `direccion`, `comentarios`, `id_grupo`, `id_os`, `server_name`, `intervalo`, `id_parent`, `modo`)
$server_id = get_db_value ($dbh, 'SELECT id_server FROM tserver WHERE network_server = 1 AND master = 1 LIMIT 1'); VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1)', $agent_name, $address, "Created by $server_name", $group_id, $os_id, $server_name, $parent_id);
$server_id = 0 unless defined ($server_id);
}
my $agent_id = db_insert ($dbh, 'INSERT INTO tagente (`nombre`, `direccion`, `comentarios`, `id_grupo`, `id_os`, `id_network_server`, `intervalo`, `id_parent`, `modo`, `id_prediction_server`, `id_wmi_server`, `id_plugin_server`)
VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1, 0, 0, 0)', $agent_name, $address, "Created by $server_name", $group_id, $os_id, $server_id, $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); 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; return $agent_id;
@ -777,8 +771,8 @@ sub pandora_update_module_on_error ($$$) {
my ($pa_config, $id_agent_module, $dbh) = @_; my ($pa_config, $id_agent_module, $dbh) = @_;
# Update last_execution_try # Update last_execution_try
db_do ($dbh, 'UPDATE tagente_estado SET current_interval = ?, last_execution_try = ? db_do ($dbh, 'UPDATE tagente_estado SET last_execution_try = ?
WHERE id_agente_modulo = ?', 300, time (), $id_agent_module); WHERE id_agente_modulo = ?', time (), $id_agent_module);
} }
########################################################################## ##########################################################################

View File

@ -167,7 +167,7 @@ sub process_xml_data {
# Create the agent # Create the agent
my $os = pandora_get_os ($data->{'os'}); 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, 0, $os, $dbh); $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $agent_name, '', 0, $pa_config->{'autocreate_group'}, 0, $os, $dbh);
return unless defined ($agent_id); return unless defined ($agent_id);
} }

View File

@ -147,7 +147,7 @@ sub data_consumer ($$$$$) {
$task_sem->down; $task_sem->down;
$sem->down; $sem->down;
my $task = pop (@{$task_queue}); my $task = shift (@{$task_queue});
$sem->up; $sem->up;
# Execute task # Execute task

View File

@ -90,7 +90,7 @@ sub data_producer ($) {
foreach my $row (@rows) { foreach my $row (@rows) {
# Update task status # Update task status
update_recon_task ($pa_config, $dbh, $row->{'id_rt'}, 0); update_recon_task ($dbh, $row->{'id_rt'}, 0);
push (@tasks, $row->{'id_rt'}); push (@tasks, $row->{'id_rt'});
} }
@ -113,7 +113,7 @@ sub data_consumer ($$) {
my $net_addr = new NetAddr::IP ($task->{'subnet'}); my $net_addr = new NetAddr::IP ($task->{'subnet'});
if (! defined ($net_addr)) { if (! defined ($net_addr)) {
logger ($pa_config, 'Invalid network ' . $task->{'subnet'} . ' for task ' . $task->{'name'}, 2); logger ($pa_config, 'Invalid network ' . $task->{'subnet'} . ' for task ' . $task->{'name'}, 2);
update_recon_task ($pa_config, $dbh, $task_id, -1); update_recon_task ($dbh, $task_id, -1);
return -1; return -1;
} }
@ -122,10 +122,10 @@ sub data_consumer ($$) {
for (my $i = 1, $net_addr++; $net_addr < $net_addr->broadcast; $i++, $net_addr++) { for (my $i = 1, $net_addr++; $net_addr < $net_addr->broadcast; $i++, $net_addr++) {
my $addr = (split(/\//, $net_addr))[0]; my $addr = (split(/\//, $net_addr))[0];
update_recon_task ($pa_config, $dbh, $task_id, $i / ($total_hosts / 100)); update_recon_task ($dbh, $task_id, $i / ($total_hosts / 100));
# Does the host already exist? # Does the host already exist?
next if (addr_exists ($dbh, $addr) == 1); next if (get_agent_from_addr ($dbh, $addr) > 0);
# Is the host alive? (thanks to Evi for the TCP scans) # Is the host alive? (thanks to Evi for the TCP scans)
my $alive = 0; my $alive = 0;
@ -164,13 +164,18 @@ sub data_consumer ($$) {
# Get the parent host # Get the parent host
my $parent_id = get_host_parent ($pa_config, $addr, $dbh); my $parent_id = get_host_parent ($pa_config, $addr, $dbh);
# Add the new address # Add the new address if it does not exist
my $addr_id = add_address ($dbh, $addr); my $addr_id = get_addr_id ($dbh, $addr);
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
next unless ($addr_id > 0);
# Crate a new agent # Crate a new agent
my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'} . '_Recon', my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'},
$host_name, $addr, $addr_id, $host_name, $addr, $addr_id,
$task->{'id_group'}, '', $parent_id, $task->{'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);
# Crate network profile modules for the agent # Crate network profile modules for the agent
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr); create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr);
@ -191,7 +196,7 @@ sub data_consumer ($$) {
} }
# Mark recon task as done # Mark recon task as done
update_recon_task ($pa_config, $dbh, $task_id, -1); update_recon_task ($dbh, $task_id, -1);
} }
############################################################################## ##############################################################################
@ -262,37 +267,32 @@ sub guess_os {
} }
########################################################################## ##########################################################################
# Return 1 if the given IP address already exists in the DB, 0 if not. # Return the ID of the given address, 0 if it does not exist.
########################################################################## ##########################################################################
sub addr_exists ($$) { sub get_addr_id ($$) {
my ($dbh, $ip_address) = @_; my ($dbh, $addr) = @_;
my @addresses = get_db_rows ($dbh, 'SELECT * FROM taddress WHERE ip = ?', $ip_address); my $addr_id = get_db_value ($dbh, 'SELECT id_a FROM taddress WHERE ip = ?', $addr);
return (defined ($addr_id) ? $addr_id : -1);
# Address not found
return 0 if ($#addresses < 0);
return 1;
} }
########################################################################## ##########################################################################
# Return the ID of the agent with the given IP. # Return the ID of the agent with the given IP.
########################################################################## ##########################################################################
sub get_agent_from_addr ($$$) { sub get_agent_from_addr ($$) {
my ($pa_config, $dbh, $ip_address) = @_; my ($dbh, $ip_address) = @_;
return 0 if (! defined ($ip_address) || $ip_address eq ''); return 0 if (! defined ($ip_address) || $ip_address eq '');
my $agent_id = get_db_value ($dbh, 'SELECT id_agent FROM taddress, taddress_agent WHERE taddress_agent.id_a = taddress.id_a AND ip = ?', $ip_address); my $agent_id = get_db_value ($dbh, 'SELECT id_agent FROM taddress, taddress_agent WHERE taddress_agent.id_a = taddress.id_a AND ip = ?', $ip_address);
return (defined ($agent_id)) ? $agent_id : -1; return (defined ($agent_id)) ? $agent_id : -1;
} }
########################################################################## ##########################################################################
# Update recon task status. # Update recon task status.
########################################################################## ##########################################################################
sub update_recon_task { sub update_recon_task ($$$) {
my ($pa_config, $dbh, $id_task, $status) = @_; my ($dbh, $id_task, $status) = @_;
db_do ($dbh, 'UPDATE trecon_task SET utimestamp = ?, status = ? WHERE id_rt = ?', time (), $status, $id_task); db_do ($dbh, 'UPDATE trecon_task SET utimestamp = ?, status = ? WHERE id_rt = ?', time (), $status, $id_task);
} }
@ -375,7 +375,7 @@ sub get_host_parent ($$){
return 0 if ($tr->hops < 2 || $success == 0); return 0 if ($tr->hops < 2 || $success == 0);
my $parent_addr = $tr->hop_query_host($tr->hops - 1, 0); my $parent_addr = $tr->hop_query_host($tr->hops - 1, 0);
return get_agent_from_addr ($pa_config, $dbh, $parent_addr); return get_agent_from_addr ($dbh, $parent_addr);
} }
1; 1;