diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index a64bb5fc90..3b15eb9b63 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -222,6 +222,12 @@ class Tree { $agent_search_filter = " AND LOWER(ta.alias) LIKE LOWER('%".$this->filter['searchAgent']."%')"; } + //Search hirearchy + $search_hirearchy = false; + if($this->filter['searchHirearchy']){ + $search_hirearchy = true; + } + // Agent status filter $agent_status_filter = ""; if (isset($this->filter['statusAgent']) @@ -344,16 +350,49 @@ class Tree { $group_filter = "AND ta.id_grupo IN ($user_groups_str)"; } + if(!$search_hirearchy && (!empty($agent_search_filter) || !empty($module_search_filter))){ + + if(is_metaconsole()){ + $query_agent_search = " SELECT DISTINCT(ta.id_grupo) + FROM tmetaconsole_agent ta + WHERE ta.disabled = 0 + $agent_search_filter"; + $id_groups_agents = db_get_all_rows_sql($query_agent_search); + } + else{ + $query_agent_search = " SELECT DISTINCT(ta.id_grupo) + FROM tagente ta, tagente_modulo tam + WHERE tam.id_agente = ta.id_agente + AND ta.disabled = 0 + $agent_search_filter + $module_search_filter"; + $id_groups_agents = db_get_all_rows_sql($query_agent_search); + } + + if($id_groups_agents != false){ + foreach ($id_groups_agents as $key => $value) { + $id_groups_agents_array[] = $value['id_grupo']; + } + $user_groups_array = explode(",", $user_groups_str); + $user_groups_array = array_intersect($user_groups_array, $id_groups_agents_array); + $user_groups_str = implode("," , $user_groups_array); + } + else{ + $user_groups_str = false; + } + } + switch ($type) { // Get the agents of a group case 'group': if (empty($rootID) || $rootID == -1) { + if(!$search_hirearchy && (!empty($agent_search_filter) || !empty($module_search_filter))){ + $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.icon'; + } + else{ + $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon'; + } - // Strict acl specifications - /*if ($this->strictACL) - return false;*/ - - $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon'; $order_fields = 'tg.nombre ASC, tg.id_grupo ASC'; if (! is_metaconsole()) { @@ -1180,6 +1219,7 @@ class Tree { !empty($group['counters']['total'])); }); } + usort($groups, array("Tree", "cmpSortNames")); return $groups; } @@ -2646,9 +2686,10 @@ class Tree { protected function getGroupCounters($group_id) { global $config; static $group_stats = false; - # Do not use the group stat cache when using tags or real time group stats. - if ($config['realtimestats'] == 1 || (isset($this->userGroups[$group_id]['tags']) && $this->userGroups[$group_id]['tags'] != "")) { + if ($config['realtimestats'] == 1 || + (isset($this->userGroups[$group_id]['tags']) && $this->userGroups[$group_id]['tags'] != "") || + !empty($this->filter['searchAgent']) ) { return $this->getCounters($group_id); } diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 293e7e8b9e..d65d662fd8 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -16,18 +16,17 @@ global $config; -$pure = get_parameter('pure', 0); -$tab = get_parameter('tab', 'group'); -$search_group = get_parameter('searchGroup', ''); -$search_agent = get_parameter('searchAgent', ''); -$status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL); +$pure = get_parameter('pure', 0); +$tab = get_parameter('tab', 'group'); +$search_group = get_parameter('searchGroup', ''); +$search_agent = get_parameter('searchAgent', ''); +$status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL); $search_module = get_parameter('searchModule', ''); $status_module = get_parameter('statusModule', -1); -$group_id = (int) get_parameter('group_id'); -$tag_id = (int) get_parameter('tag_id'); - -$strict_acl = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); - +$group_id = (int) get_parameter('group_id'); +$tag_id = (int) get_parameter('tag_id'); +$strict_acl = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); +$serach_hirearchy = (bool) get_parameter('searchHirearchy', false); // ---------------------Tabs ------------------------------------------- $enterpriseEnable = false; if (enterprise_include_once('include/functions_policies.php') !== ENTERPRISE_NOT_HOOK) { @@ -126,6 +125,12 @@ $table->data = array(); $table->rowspan = array(); $table->style[0] = 'font-weight: bold;'; $table->style[2] = 'font-weight: bold;'; +$table->size = array(); +$table->size[0] = '10%'; +$table->size[1] = '35%'; +$table->size[2] = '9%'; +$table->size[3] = '10%'; +$table->size[4] = '10%'; // Agent filter $agent_status_arr = array(); $agent_status_arr[AGENT_STATUS_ALL] = __('All'); //default @@ -135,17 +140,19 @@ $agent_status_arr[AGENT_STATUS_CRITICAL] = __('Critical'); $agent_status_arr[AGENT_STATUS_UNKNOWN] = __('Unknown'); $agent_status_arr[AGENT_STATUS_NOT_INIT] = __('Not init'); -if ($tab == 'group' || is_metaconsole()) { - $row = array(); - $row[] = __('Search group'); - $row[] = html_print_input_text("search_group", $search_group, '', is_metaconsole() ? 70 : 40, 30, true); +$row = array(); +$row[] = __('Search group'); +$row[] = html_print_input_text("search_group", $search_group, '', is_metaconsole() ? 70 : 40, 30, true); - $table->data[] = $row; -} +$table->data[] = $row; $row = array(); $row[] = __('Search agent'); $row[] = html_print_input_text("search_agent", $search_agent, '', is_metaconsole() ? 70 : 40, 30, true); + +$row[] = __('Show full hirearchy'); +$row[] = html_print_checkbox("serach_hirearchy", $serach_hirearchy, false, true); + $row[] = __('Agent status'); $row[] = html_print_select($agent_status_arr, "status_agent", $status_agent, '', '', 0, true); @@ -256,6 +263,13 @@ enterprise_hook('close_meta_frame'); parameters['filter']['groupID'] = $("input#hidden-group-id").val(); parameters['filter']['tagID'] = $("input#hidden-tag-id").val(); + if($("#checkbox-serach_hirearchy").is(':checked')){ + parameters['filter']['searchHirearchy'] = 1; + } + else{ + parameters['filter']['searchHirearchy'] = 0; + } + $.ajax({ type: "POST", url: "",