From e26c81aa6c32d7ce3e734f06aa1f63b198d2829f Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 5 Mar 2019 15:33:27 +0100 Subject: [PATCH 1/2] Fixed images and reset map in networkmap Former-commit-id: d56dc68d542aa1e4d30a3014acc53b44dc07191e --- .../functions_pandora_networkmap.js | 8 ++-- .../include/styles/js/jquery.contextMenu.css | 38 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index 4c9f5b61b7..56e160fe07 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -2571,11 +2571,9 @@ function reset_map_from_form(new_elements) { type: "POST", url: (action = "ajax.php"), success: function(data) { - if (!data["error"]) { - window.location = - "index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" + - networkmap_id; - } + window.location = + "index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" + + networkmap_id; } }); } diff --git a/pandora_console/include/styles/js/jquery.contextMenu.css b/pandora_console/include/styles/js/jquery.contextMenu.css index 64d86cf7bc..7343aa5de1 100644 --- a/pandora_console/include/styles/js/jquery.contextMenu.css +++ b/pandora_console/include/styles/js/jquery.contextMenu.css @@ -107,61 +107,61 @@ background-position: 4px 2px; } .context-menu-item.icon-edit { - background-image: url(../../images/page_white_edit.png); + background-image: url(../../../images/page_white_edit.png); } .context-menu-item.icon-cut { - background-image: url(../../images/cut.png); + background-image: url(../../../images/cut.png); } .context-menu-item.icon-copy { - background-image: url(../../images/page_white_copy.png); + background-image: url(../../../images/page_white_copy.png); } .context-menu-item.icon-paste { - background-image: url(../../images/page_white_paste.png); + background-image: url(../../../images/page_white_paste.png); } .context-menu-item.icon-delete { - background-image: url(../../images/delete.png); + background-image: url(../../../images/delete.png); } .context-menu-item.icon-add { - background-image: url(../../images/page_white_add.png); + background-image: url(../../../images/page_white_add.png); } .context-menu-item.icon-quit { - background-image: url(../../images/door.png); + background-image: url(../../../images/door.png); } .context-menu-item.icon-refresh { - background-image: url(../../images/refresh.png); + background-image: url(../../../images/refresh.png); } .context-menu-item.icon-center { - background-image: url(../../images/set_center.png); + background-image: url(../../../images/set_center.png); } .context-menu-item.icon-details { - background-image: url(../../images/show_details.png); + background-image: url(../../../images/show_details.png); } .context-menu-item.icon-children { - background-image: url(../../images/children.png); + background-image: url(../../../images/children.png); } .context-menu-item.icon-cancel_set_parent { - background-image: url(../../images/link_delete.png); + background-image: url(../../../images/link_delete.png); } .context-menu-item.icon-set_parent { - background-image: url(../../images/father.png); + background-image: url(../../../images/father.png); } .context-menu-item.icon-add_node { - background-image: url(../../images/add.png); + background-image: url(../../../images/add.png); } .context-menu-item.icon-refresh_holding_area { - background-image: url(../../images/refresh_holding_area.png); + background-image: url(../../../images/refresh_holding_area.png); } .context-menu-item.icon-restart_map { - background-image: url(../../images/reset.png); + background-image: url(../../../images/reset.png); } .context-menu-item.icon-interface_link_children { - background-image: url(../../images/icono_link_hijo.png); + background-image: url(../../../images/icono_link_hijo.png); } .context-menu-item.icon-interface_link_parent { - background-image: url(../../images/icono_link_padre.png); + background-image: url(../../../images/icono_link_padre.png); } .context-menu-item.icon-interface_link_cancel { - background-image: url(../../images/link_abortar.png); + background-image: url(../../../images/link_abortar.png); } /* vertically align inside labels */ From 4c0263206e49e4acb60e7fe78ca9be288d82edbb Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 5 Mar 2019 16:12:29 +0100 Subject: [PATCH 2/2] WIP: Networkmap & recon improvements Former-commit-id: 25e6fb140f4cf52e919eed941b6659ed377ac26c --- .../include/functions_networkmap.php | 76 +++++++++---------- .../include/functions_pandora_networkmap.php | 60 +++++++-------- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 12 ++- .../lib/PandoraFMS/DiscoveryServer.pm | 10 ++- pandora_server/lib/PandoraFMS/Tools.pm | 2 +- 6 files changed, 81 insertions(+), 81 deletions(-) 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