2012-04-12 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/DB.pm,
	  lib/PandoraFMS/Core.pm,
	  lib/PandoraFMS/ReconServer.pm: Improved Recon Server to detect
	  hostnames that resolve to multiple IP addresses. Fixes bug #3052350.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5952 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2012-04-12 10:04:35 +00:00
parent 6c382e5e48
commit cc0b52a12c
4 changed files with 64 additions and 25 deletions

View File

@ -1,3 +1,10 @@
2012-04-12 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DB.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm: Improved Recon Server to detect
hostnames that resolve to multiple IP addresses. Fixes bug #3052350.
2012-04-10 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DataServer.pm: Check for single tag XMLs. Fixes bug #3514207.

View File

@ -173,6 +173,7 @@ our @EXPORT = qw(
pandora_self_monitoring
pandora_process_policy_queue
get_agent_from_addr
get_agent_from_name
@ServerTypes
);
@ -194,7 +195,19 @@ sub get_agent_from_addr ($$) {
WHERE tagente.id_agente = taddress_agent.id_agent
AND taddress_agent.id_a = taddress.id_a
AND ip = ?', $ip_address);
return $agent
return $agent;
}
##########################################################################
# Return the agent given the agent name.
##########################################################################
sub get_agent_from_name ($$) {
my ($dbh, $name) = @_;
return 0 if (! defined ($name) || $name eq '');
my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE tagente.nombre = ?', $name);
return $agent;
}
##########################################################################

View File

@ -43,6 +43,7 @@ our @EXPORT = qw(
db_update
get_action_id
get_addr_id
get_agent_addr_id
get_agent_id
get_agent_address
get_agent_group
@ -578,6 +579,17 @@ sub get_addr_id ($$) {
return (defined ($addr_id) ? $addr_id : -1);
}
##########################################################################
# Return the agent address ID for the given agent ID and address ID, -1 if
# it does not exist.
##########################################################################
sub get_agent_addr_id ($$$) {
my ($dbh, $addr_id, $agent_id) = @_;
my $agent_addr_id = get_db_value ($dbh, 'SELECT id_ag FROM taddress_agent WHERE id_a = ? AND id_agent = ?', $addr_id, $agent_id);
return (defined ($agent_addr_id) ? $agent_addr_id : -1);
}
##########################################################################
## Generic SQL sentence.
##########################################################################

View File

@ -152,19 +152,30 @@ sub data_consumer ($$) {
# Get agent address
my $addr = $host->addr();
next unless ($addr ne '0');
# Update the recon task or break if it does not exist anymore
last if (update_recon_task ($dbh, $task_id, ceil ($progress / ($total_up / 100))) eq '0E0');
# Resolve hostnames
my $host_name = undef;
if ($task->{'resolve_names'} == 1){
$host_name = gethostbyaddr (inet_aton($addr), AF_INET);
}
$host_name = $addr unless defined ($host_name);
# Does the host already exist?
my $agent = get_agent_from_addr ($dbh, $addr);
if (! defined ($agent)) {
$agent = get_agent_from_name ($dbh, $host_name);
}
my $agent_id = defined ($agent) ? $agent->{'id_agente'} : 0;
if ($agent_id > 0) {
# Skip if not in learning mode or parent detection is disabled
next if ($agent->{'modo'} != 1 || $task->{'parent_detection'} == 0);
# Skip if not in learning mode
next if ($agent->{'modo'} != 1);
}
# Filter by TCP port
if ((defined ($task->{'recon_ports'})) && ($task->{'recon_ports'} ne "")) {
next unless (tcp_scan ($pa_config, $addr, $task->{'recon_ports'}) > 0);
@ -182,21 +193,6 @@ sub data_consumer ($$) {
if ($task->{'parent_detection'} == 1) {
$parent_id = get_host_parent ($pa_config, $addr, $dbh, $task->{'id_group'}, $task->{'parent_recursion'}, $task->{'resolve_names'}, $task->{'os_detect'});
}
# If the agent already exists update parent and continue
if ($agent_id > 0) {
if ($parent_id > 0) {
db_do ($dbh, 'UPDATE tagente SET id_parent = ? WHERE id_agente = ?', $parent_id, $agent_id );
}
next;
}
# Resolve hostnames
my $host_name = undef;
if ($task->{'resolve_names'} == 1){
$host_name = gethostbyaddr (inet_aton($addr), AF_INET);
}
$host_name = $addr unless defined ($host_name);
# Add the new address if it does not exist
my $addr_id = get_addr_id ($dbh, $addr);
@ -206,6 +202,21 @@ sub data_consumer ($$) {
next;
}
# Assign the new address to the agent
my $agent_addr_id = get_agent_addr_id ($dbh, $addr_id, $agent_id);
if ($agent_addr_id <= 0) {
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id);
}
# If the agent already exists update parent and continue
if ($agent_id > 0) {
if ($parent_id > 0) {
db_do ($dbh, 'UPDATE tagente SET id_parent = ? WHERE id_agente = ?', $parent_id, $agent_id );
}
next;
}
# GIS Code -----------------------------
# If GIS is activated try to geolocate the ip address of the agent
@ -269,10 +280,6 @@ sub data_consumer ($$) {
next;
}
# Assign the new address to the agent
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id);
# Create network profile modules for the agent
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});