diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 93b248b206..e5fe48973d 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -373,20 +373,7 @@ function networkmap_generate_dot( $agents = false; } else if (!empty($ip_mask)) { $agents = networkmap_get_new_nodes_from_ip_mask( - $ip_mask, - [ - 'id_grupo', - 'nombre', - 'id_os', - 'id_parent', - 'id_agente', - 'normal_count', - 'warning_count', - 'critical_count', - 'unknown_count', - 'total_count', - 'notinit_count', - ] + $ip_mask ); } else { $agents = agents_get_agents( @@ -454,7 +441,6 @@ function networkmap_generate_dot( // Get agent modules data $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true); - if ($modules === false) { $modules = []; } @@ -1654,40 +1640,46 @@ function networkmap_get_new_nodes_from_ip_mask( ) { $list_ip_masks = explode(',', $ip_mask); - $list_address = db_get_all_rows_in_table('taddress'); - if (empty($address)) { - $address = []; - } - $agents = []; - foreach ($list_address as $address) { - foreach ($list_ip_masks as $ip_mask) { - if (networkmap_cidr_match($address['ip'], $ip_mask)) { - $id_agent = db_get_value_filter( - 'id_agent', - 'taddress_agent', - ['id_a' => $address['id_a']] - ); + foreach ($list_ip_masks as $subnet) { + $net = explode('/', $subnet); - // Orphan address. Ignore. - if (empty($id_agent)) { - continue; - } + $sql = sprintf( + 'SELECT * + FROM `tagente` + INNER JOIN + (SELECT DISTINCT `id_agent` FROM + (SELECT `id_agente` AS "id_agent", `direccion` AS "ip" + FROM `tagente` + UNION + SELECT ag.`id_agent`, a.`ip` + FROM `taddress_agent` ag + INNER JOIN `taddress` a + ON ag.id_a=a.id_a + ) t_tmp + WHERE (-1 << %d) & INET_ATON(t_tmp.ip) = INET_ATON("%s") + ) t_res + ON t_res.`id_agent` = `tagente`.`id_agente`', + (32 - $net[1]), + $net[0] + ); - if (empty($fields)) { - $target_agent = db_get_value_filter('id_agent', 'taddress_agent', ['id_a' => $address['id_a']]); - } else { - $target_agent = db_get_row('tagente', 'id_agente', $id_agent, $fields); - } + $subnet_agents = db_get_all_rows_sql($sql); - // Agent exists. Add to pool. - if ($target_agent !== false) { - $agents[$id_agent] = $target_agent; - } - } + if ($subnet_agents !== false) { + $agents = array_merge($agents, $subnet_agents); } } + $agents = array_reduce( + $agents, + function ($carry, $item) { + $carry[$item['id_agente']] = $item; + return $carry; + }, + [] + ); + return $agents; } diff --git a/pandora_console/include/functions_pandora_networkmap.php b/pandora_console/include/functions_pandora_networkmap.php index c1eb630d52..a31fa659ae 100644 --- a/pandora_console/include/functions_pandora_networkmap.php +++ b/pandora_console/include/functions_pandora_networkmap.php @@ -593,41 +593,43 @@ function networkmap_db_node_to_js_node($node, &$count, &$count_item_holding_area function get_status_color_networkmap($id, $color=true) { - $status = agents_get_status($id); + // $status = agents_get_status($id); + $agent_data = db_get_row_sql('SELECT * FROM tagente WHERE id_agente = '.$id); + + if ($agent_data === false) { + return COL_UNKNOWN; + } + + $status = agents_get_status_from_counts($agent_data); if (!$color) { return $status; } - // Set node status - switch ($status) { - case 0: - $status_color = COL_NORMAL; - // Normal monitor - break; - - case 1: - $status_color = COL_CRITICAL; - // Critical monitor - break; - - case 2: - $status_color = COL_WARNING; - // Warning monitor - break; - - case 4: - $status_color = COL_ALERTFIRED; - // Alert fired - break; - - default: - $status_color = COL_UNKNOWN; - // Unknown monitor - break; + if ($agent_data['fired_count'] > 0) { + return COL_ALERTFIRED; } - return $status_color; + // Select node color by checking status. + switch ($status) { + case AGENT_MODULE_STATUS_NORMAL: + return COL_NORMAL; + + case AGENT_MODULE_STATUS_NOT_INIT: + return COL_NOTINIT; + + case AGENT_MODULE_STATUS_CRITICAL_BAD: + return COL_CRITICAL; + + case AGENT_MODULE_STATUS_WARNING: + return COL_WARNING; + + case AGENT_MODULE_STATUS_UNKNOWN: + default: + return COL_UNKNOWN; + } + + return COL_UNKNOWN; } @@ -2126,5 +2128,3 @@ function show_networkmap($id=0, $user_readonly=false, $nodes_and_relations=[], $ optionaly with position information =cut ########################################################################## -sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$) { +sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) { + # If parameter event_id is not undef, then create an extended event + # related to it instead launch new event. my ($pa_config, $server_name, $agent_name, $address, $group_id, $parent_id, $os_id, $description, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description, - $custom_id, $url_address, $agent_mode, $alias) = @_; + $custom_id, $url_address, $agent_mode, $alias, $event_id) = @_; logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10); @@ -3125,7 +3127,11 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$) { } logger ($pa_config, "Server '$server_name' CREATED agent '$agent_name' address '$address'.", 10); - pandora_event ($pa_config, "Agent [" . safe_output($alias) . "] created by $server_name", $group_id, $agent_id, 2, 0, 0, 'new_agent', 0, $dbh); + if (!defined($event_id)) { + pandora_event ($pa_config, "Agent [" . safe_output($alias) . "] created by $server_name", $group_id, $agent_id, 2, 0, 0, 'new_agent', 0, $dbh); + } else { + pandora_extended_event($pa_config, $dbh, $event_id, "Agent [" . safe_output($alias) . "][#".$agent_id."] created by $server_name"); + } return $agent_id; } diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index bc4e1caa73..d250c36988 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -469,10 +469,12 @@ sub PandoraFMS::Recon::Base::create_agent($$) { # Are we filtering hosts by TCP port? return if ($self->{'recon_ports'} ne '' && $self->tcp_scan($device) == 0); my $location = get_geoip_info($self->{'pa_config'}, $device); - $agent_id = pandora_create_agent($self->{'pa_config'}, $self->{'pa_config'}->{'servername'}, $host_name, $device, - $self->{'group_id'}, 0, $id_os, - '', 300, $self->{'dbh'}, undef, - $location->{'longitude'}, $location->{'latitude'} + $agent_id = pandora_create_agent( + $self->{'pa_config'}, $self->{'pa_config'}->{'servername'}, + $host_name, $device, $self->{'group_id'}, 0, $id_os, + '', 300, $self->{'dbh'}, undef, $location->{'longitude'}, + $location->{'latitude'}, undef, undef, undef, undef, + undef, undef, $self->{'main_event_id'} ); return undef unless defined ($agent_id) and ($agent_id > 0); diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index aababebd69..b086ab1fbd 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -1774,7 +1774,7 @@ sub api_call_url { my $ua = LWP::UserAgent->new(); - $ua->timeout($options->{lwp_timeout}); + $ua->timeout($pa_config->{'tcp_timeout'}); # Enable environmental proxy settings $ua->env_proxy; # Enable in-memory cookie management