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:
parent
6c382e5e48
commit
cc0b52a12c
|
@ -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>
|
2012-04-10 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/DataServer.pm: Check for single tag XMLs. Fixes bug #3514207.
|
* lib/PandoraFMS/DataServer.pm: Check for single tag XMLs. Fixes bug #3514207.
|
||||||
|
|
|
@ -173,6 +173,7 @@ our @EXPORT = qw(
|
||||||
pandora_self_monitoring
|
pandora_self_monitoring
|
||||||
pandora_process_policy_queue
|
pandora_process_policy_queue
|
||||||
get_agent_from_addr
|
get_agent_from_addr
|
||||||
|
get_agent_from_name
|
||||||
@ServerTypes
|
@ServerTypes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -194,7 +195,19 @@ sub get_agent_from_addr ($$) {
|
||||||
WHERE tagente.id_agente = taddress_agent.id_agent
|
WHERE tagente.id_agente = taddress_agent.id_agent
|
||||||
AND taddress_agent.id_a = taddress.id_a
|
AND taddress_agent.id_a = taddress.id_a
|
||||||
AND ip = ?', $ip_address);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -43,6 +43,7 @@ our @EXPORT = qw(
|
||||||
db_update
|
db_update
|
||||||
get_action_id
|
get_action_id
|
||||||
get_addr_id
|
get_addr_id
|
||||||
|
get_agent_addr_id
|
||||||
get_agent_id
|
get_agent_id
|
||||||
get_agent_address
|
get_agent_address
|
||||||
get_agent_group
|
get_agent_group
|
||||||
|
@ -578,6 +579,17 @@ sub get_addr_id ($$) {
|
||||||
return (defined ($addr_id) ? $addr_id : -1);
|
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.
|
## Generic SQL sentence.
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -156,13 +156,24 @@ sub data_consumer ($$) {
|
||||||
# Update the recon task or break if it does not exist anymore
|
# 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');
|
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?
|
# Does the host already exist?
|
||||||
my $agent = get_agent_from_addr ($dbh, $addr);
|
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;
|
my $agent_id = defined ($agent) ? $agent->{'id_agente'} : 0;
|
||||||
if ($agent_id > 0) {
|
if ($agent_id > 0) {
|
||||||
|
|
||||||
# Skip if not in learning mode or parent detection is disabled
|
# Skip if not in learning mode
|
||||||
next if ($agent->{'modo'} != 1 || $task->{'parent_detection'} == 0);
|
next if ($agent->{'modo'} != 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Filter by TCP port
|
# Filter by TCP port
|
||||||
|
@ -183,21 +194,6 @@ sub data_consumer ($$) {
|
||||||
$parent_id = get_host_parent ($pa_config, $addr, $dbh, $task->{'id_group'}, $task->{'parent_recursion'}, $task->{'resolve_names'}, $task->{'os_detect'});
|
$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
|
# Add the new address if it does not exist
|
||||||
my $addr_id = get_addr_id ($dbh, $addr);
|
my $addr_id = get_addr_id ($dbh, $addr);
|
||||||
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
|
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
|
||||||
|
@ -206,6 +202,21 @@ sub data_consumer ($$) {
|
||||||
next;
|
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 -----------------------------
|
# GIS Code -----------------------------
|
||||||
|
|
||||||
# If GIS is activated try to geolocate the ip address of the agent
|
# If GIS is activated try to geolocate the ip address of the agent
|
||||||
|
@ -269,10 +280,6 @@ sub data_consumer ($$) {
|
||||||
next;
|
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 for the agent
|
||||||
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue