diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 9e2b537ce4..93bb160a77 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2014-06-17 Ramon Novoa + + * lib/PandoraFMS/Core.pm: Removed an unused module. + + * util/recon_scripts/snmp-recon.pl: Always perform a brute-force network scan. + Connect hosts via traceroute if no L2 information is available. + 2014-06-17 Vanessa Gil * lib/PandoraFMS/Core.pm: Fixed bug diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 39e60c15ae..638127521d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -108,7 +108,6 @@ use Time::Local; use POSIX qw(strftime); use threads; use threads::shared; -use Thread::Semaphore; use JSON qw(decode_json encode_json); use MIME::Base64; diff --git a/pandora_server/util/recon_scripts/snmp-recon.pl b/pandora_server/util/recon_scripts/snmp-recon.pl index ae77e99f2c..75fb159477 100755 --- a/pandora_server/util/recon_scripts/snmp-recon.pl +++ b/pandora_server/util/recon_scripts/snmp-recon.pl @@ -387,6 +387,7 @@ sub arp_cache_discovery { # Mark the device as visited. $VISITED_DEVICES{$device} = { 'addr' => { $device => '' }, + 'connected' => 0, 'type' => $device_type }; # Check if the device responds to SNMP. @@ -780,6 +781,8 @@ sub connect_pandora_agents($$$$) { # Mark the two devices as connected. $CONNECTIONS{"${module_id_1}_${module_id_2}"} = 1; + $VISITED_DEVICES{$dev_1}->{'connected'} = 1; + $VISITED_DEVICES{$dev_2}->{'connected'} = 1; # Connect the modules if they are not already connected. my $connection_id = get_db_value($DBH, 'SELECT id FROM tmodule_relationship WHERE (module_a = ? AND module_b = ?) OR (module_b = ? AND module_a = ?)', $module_id_1, $module_id_2, $module_id_1, $module_id_2); @@ -832,6 +835,56 @@ sub show_help { exit; } +########################################################################## +# Connect the given hosts to its parent using traceroute. +########################################################################## +sub traceroute_connectivity($) { + my ($host) = @_; + + # Get the agent for the first device. + my $agent = get_agent_from_addr($DBH, $host); + if (!defined($agent)) { + $agent = get_agent_from_name($DBH, $host); + } + return unless defined($agent); + + # Perform a traceroute. + my $np = new PandoraFMS::NmapParser; + eval { + $np->parsescan($CONF{'nmap'}, '-nsP --traceroute', ($host)); + }; + return if ($@); + + # Get hops to the host. + my ($h) = $np->all_hosts (); + return unless defined ($h); + my @hops = $h->all_trace_hops (); + + # Skip the target host. + pop(@hops); + + # Reverse the host order (closest hosts first). + @hops = reverse(@hops); + + # Look for parents. + my $parent_id = 0; + foreach my $hop (@hops) { + my $host_addr = $hop->ipaddr (); + + # Check if the parent agent exists. + my $agent = get_agent_from_addr ($DBH, $host_addr); + if (defined ($agent)) { + $parent_id = $agent->{'id_agente'}; + last; + } + } + + # Connect the host to its parent. + if ($parent_id > 0) { + db_do($DBH, 'UPDATE tagente SET id_parent=? WHERE id_agente=?', $parent_id, $agent->{'id_agente'}); + } +} + ########################################################################## ########################################################################## ## Main. @@ -927,6 +980,10 @@ message("[6/6] Finding switch/router to end host connectivity..."); foreach my $device ((@ROUTERS, @SWITCHES)) { host_connectivity($device); } +foreach my $host (keys(%HOSTS)) { + next if ($VISITED_DEVICES{$host}->{'connected'} == 1); + traceroute_connectivity($host); +} update_recon_task($DBH, $TASK_ID, -1); # Print debug information on found devices.