From 8a92b39eee596013fc4b95eedd425e5fe599999e Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 4 Dec 2023 11:59:31 +0100 Subject: [PATCH 1/2] add new filters widget modules status pandora_enterprise#12267 --- pandora_console/include/ajax/module.php | 33 +++ .../lib/Dashboard/Widgets/ModulesByStatus.php | 278 +++++++----------- 2 files changed, 145 insertions(+), 166 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index e4eba79858..c3e099f0cb 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1851,6 +1851,8 @@ if (check_login()) { $table_id = get_parameter('table_id', ''); $search = get_parameter('search', ''); + $search_agent = get_parameter('search_agent', ''); + $groupId = (int) get_parameter('groupId', 0); $module_name = get_parameter('module_name', ''); $status = get_parameter('status', ''); $start = get_parameter('start', 0); @@ -1862,13 +1864,36 @@ if (check_login()) { $nodes = get_parameter('nodes', 0); $disabled_modules = (bool) get_parameter('disabled_modules', false); + $groups_array = []; + if ($groupId === 0) { + if (users_can_manage_group_all('AR') === false) { + $groups_array = users_get_groups(false, 'AR', false); + } + } else { + $groups_array = [$groupId]; + } + $where = '1=1'; $recordsTotal = 0; + if (empty($groups_array) === false) { + $where .= sprintf( + ' AND (tagente.id_grupo IN (%s) + OR tagent_secondary_group.id_group IN(%s))', + implode(',', $groups_array), + implode(',', $groups_array) + ); + } + + if (empty($search) === false) { $where .= ' AND tagente_modulo.nombre LIKE "%%'.$search.'%%"'; } + if (empty($search_agent) === false) { + $where .= ' AND tagente.alias LIKE "%%'.$search_agent.'%%"'; + } + if (str_contains($status, '6') === true) { $expl = explode(',', $status); $exist = array_search('6', $expl); @@ -1943,6 +1968,8 @@ if (check_login()) { ON tagente_modulo.id_agente = tagente.id_agente INNER JOIN tagente_estado ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent WHERE %s ORDER BY %s LIMIT %d, %d', @@ -1960,6 +1987,8 @@ if (check_login()) { ON tagente_modulo.id_agente = tagente.id_agente INNER JOIN tagente_estado ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent WHERE %s', $where ); @@ -1987,6 +2016,8 @@ if (check_login()) { ON tagente_modulo.id_agente = tagente.id_agente INNER JOIN tagente_estado ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent WHERE %s', $where ); @@ -2019,6 +2050,8 @@ if (check_login()) { ON tagente_modulo.id_agente = tagente.id_agente INNER JOIN tagente_estado ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent WHERE %s', $where ); diff --git a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php index e490135734..86a6cde7ed 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php +++ b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php @@ -200,6 +200,14 @@ class ModulesByStatus extends Widget // Retrieve global - common inputs. $values = parent::decoders($decoder); + if (isset($decoder['groupId']) === true) { + $values['groupId'] = $decoder['groupId']; + } + + if (isset($decoder['search_agent']) === true) { + $values['search_agent'] = $decoder['search_agent']; + } + if (isset($decoder['search']) === true) { $values['search'] = $decoder['search']; } @@ -240,9 +248,39 @@ class ModulesByStatus extends Widget // Retrieve global - common inputs. $inputs = parent::getFormInputs(); + $return_all_group = false; + if (users_can_manage_group_all('RM') || $values['groupId'] == 0) { + $return_all_group = true; + } + + // Groups. + $inputs[] = [ + 'label' => __('Group'), + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groupId', + 'returnAllGroup' => $return_all_group, + 'privilege' => 'AR', + 'selected' => $values['groupId'], + 'return' => true, + ], + ]; + + // Search Agent. + $inputs[] = [ + 'label' => __('Search agent').ui_print_help_tip(__('Search filter by Agent name field content'), true), + 'arguments' => [ + 'name' => 'search_agent', + 'type' => 'text', + 'value' => $values['search_agent'], + 'return' => true, + 'size' => 0, + ], + ]; + // Search. $inputs[] = [ - 'label' => __('Free search').ui_print_help_tip(__('Search filter by Module name field content'), true), + 'label' => __('Search module').ui_print_help_tip(__('Search filter by Module name field content'), true), 'arguments' => [ 'name' => 'search', 'type' => 'text', @@ -373,7 +411,9 @@ class ModulesByStatus extends Widget // Retrieve global - common inputs. $values = parent::getPost(); + $values['groupId'] = \get_parameter('groupId', 0); $values['search'] = \get_parameter('search', ''); + $values['search_agent'] = \get_parameter('search_agent', ''); $values['status'] = \get_parameter('status', ''); $values['limit'] = \get_parameter('limit', ''); $values['nodes'] = \get_parameter('nodes', ''); @@ -386,173 +426,73 @@ class ModulesByStatus extends Widget /** * Draw widget. * - * @return string; + * @return void Html output; */ public function load() { - $this->size = parent::getSize(); + // Datatables list. + try { + $info_columns = $this->columns(); + $column_names = $info_columns['column_names']; + $columns = $info_columns['columns']; + $hash = get_parameter('auth_hash', ''); + $id_user = get_parameter('id_user', ''); - global $config; - - $output = ''; - - if (is_metaconsole() === true) { - $modules = []; - - $servers_ids = array_column(metaconsole_get_servers(), 'id'); - - foreach ($servers_ids as $server_id) { - try { - $node = new Node((int) $server_id); - - $node->connect(); - $modules_tmp = $this->getInfoModules( - $this->values['search'], - $this->values['status'], - $this->values['nodes'] - ); - $modules[$node->id()] = $modules_tmp[0]; - $node->disconnect(); - } catch (\Exception $e) { - // Unexistent modules. - $node->disconnect(); - } - } - } else { - $modules = $this->getInfoModules( - $this->values['search'], - $this->values['status'] + $tableId = 'ModuleByStatus_'.$this->dashboardId.'_'.$this->cellId; + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table align-left-important', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => 'include/ajax/module', + 'ajax_data' => [ + 'get_data_ModulesByStatus' => 1, + 'table_id' => $tableId, + 'search_agent' => $this->values['search_agent'], + 'search' => $this->values['search'], + 'groupId' => $this->values['groupId'], + 'status' => $this->values['status'], + 'nodes' => $this->values['nodes'], + 'disabled_modules' => $this->values['disabled_modules'], + 'auth_hash' => $hash, + 'auth_class' => 'PandoraFMS\Dashboard\Manager', + 'id_user' => $id_user, + ], + 'default_pagination' => $this->values['limit'], + 'order' => [ + 'field' => 'last_status_change', + 'direction' => 'desc', + ], + 'csv' => 0, + 'pagination_options' => [ + [ + 5, + 10, + 25, + 100, + 200, + 500, + 1000, + ], + [ + 5, + 10, + 25, + 100, + 200, + 500, + 1000, + ], + ], + 'dom_elements' => 'frtilp', + ] ); + } catch (\Exception $e) { + echo $e->getMessage(); } - - if ($modules !== false && empty($modules) === false) { - // Datatables list. - try { - $info_columns = $this->columns(); - $column_names = $info_columns['column_names']; - $columns = $info_columns['columns']; - $hash = get_parameter('auth_hash', ''); - $id_user = get_parameter('id_user', ''); - - $tableId = 'ModuleByStatus_'.$this->dashboardId.'_'.$this->cellId; - // Load datatables user interface. - ui_print_datatable( - [ - 'id' => $tableId, - 'class' => 'info_table align-left-important', - 'style' => 'width: 100%', - 'columns' => $columns, - 'column_names' => $column_names, - 'ajax_url' => 'include/ajax/module', - 'ajax_data' => [ - 'get_data_ModulesByStatus' => 1, - 'table_id' => $tableId, - 'search' => $this->values['search'], - 'status' => $this->values['status'], - 'nodes' => $this->values['nodes'], - 'disabled_modules' => $this->values['disabled_modules'], - 'auth_hash' => $hash, - 'auth_class' => 'PandoraFMS\Dashboard\Manager', - 'id_user' => $id_user, - ], - 'default_pagination' => $this->values['limit'], - 'order' => [ - 'field' => 'last_status_change', - 'direction' => 'desc', - ], - 'csv' => 0, - 'pagination_options' => [ - [ - 5, - 10, - 25, - 100, - 200, - 500, - 1000, - ], - [ - 5, - 10, - 25, - 100, - 200, - 500, - 1000, - ], - ], - 'dom_elements' => 'frtilp', - ] - ); - } catch (\Exception $e) { - echo $e->getMessage(); - } - } else { - $output = ''; - $output .= '
'; - $output .= \ui_print_info_message( - __('Not found modules'), - '', - true - ); - $output .= '
'; - - return $output; - } - } - - - /** - * Get info modules. - * - * @param string $search Free search. - * @param string $status Modules status. - * - * @return array Data. - */ - private function getInfoModules(string $search, string $status): array - { - if (empty($search) === false) { - $where = 'tagente_modulo.nombre LIKE "%%'.$search.'%%" AND '; - } - - if (str_contains($status, '6') === true) { - $expl = explode(',', $status); - $exist = array_search('6', $expl); - if (isset($exist) === true) { - unset($expl[$exist]); - } - - array_push($expl, '1', '2'); - - $status = implode(',', $expl); - } - - $where .= sprintf( - 'tagente_estado.estado IN (%s) - AND tagente_modulo.delete_pending = 0', - $status - ); - - $sql = sprintf( - 'SELECT - COUNT(*) AS "modules" - FROM tagente_modulo - INNER JOIN tagente - ON tagente_modulo.id_agente = tagente.id_agente - INNER JOIN tagente_estado - ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - WHERE %s', - $where - ); - - $modules = db_get_all_rows_sql($sql); - - if ($modules === false) { - $modules = []; - } - - return $modules; } @@ -579,7 +519,10 @@ class ModulesByStatus extends Widget 'nombre', 'alias', 'server_name', - 'last_status_change', + [ + 'text' => 'last_status_change', + 'class' => 'flex-column', + ], 'estado', ]; } else { @@ -593,7 +536,10 @@ class ModulesByStatus extends Widget $columns = [ 'nombre', 'alias', - 'last_status_change', + [ + 'text' => 'last_status_change', + 'class' => 'flex-column', + ], 'estado', ]; } @@ -642,12 +588,12 @@ class ModulesByStatus extends Widget $height_counter = (((int) count($nodes_fields)) * 20); $size = [ - 'width' => 450, + 'width' => 470, 'height' => (520 + $height_counter), ]; } else { $size = [ - 'width' => 450, + 'width' => 470, 'height' => 480, ]; } From 65385f36c18eb24ac62613350ffdc19304e712b4 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 26 Jan 2024 09:18:47 +0100 Subject: [PATCH 2/2] fix visual errors in widgets dashboard pandora_enterprise#12267 --- pandora_console/include/functions_ui.php | 6 +++--- .../lib/Dashboard/Widgets/ModulesByStatus.php | 4 ++-- pandora_console/include/styles/dashboards.css | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d6078c56a7..0062b52e70 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -4257,15 +4257,15 @@ function ui_print_datatable(array $parameters) // * END JAVASCRIPT. $info_msg_arr = []; $info_msg_arr['message'] = $emptyTable; - $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id; + $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-info-massage datatable-msg-info-'.$table_id; $info_msg_arr_filter = []; $info_msg_arr_filter['message'] = __('Please apply a filter to display the data.'); - $info_msg_arr_filter['div_class'] = 'info_box_container invisible_important datatable-msg-info-filter-'.$table_id; + $info_msg_arr_filter['div_class'] = 'info_box_container invisible_important datatable-info-massage datatable-msg-info-filter-'.$table_id; $spinner = ''; - $info_msg = '
'.ui_print_info_message($info_msg_arr, '', true).'
'; + $info_msg = '
'.ui_print_info_message($info_msg_arr, '', true).'
'; $info_msg_filter = '
'.ui_print_info_message($info_msg_arr_filter, true).'
'; diff --git a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php index 86a6cde7ed..69c0a36f44 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php +++ b/pandora_console/include/lib/Dashboard/Widgets/ModulesByStatus.php @@ -521,7 +521,7 @@ class ModulesByStatus extends Widget 'server_name', [ 'text' => 'last_status_change', - 'class' => 'flex-column', + 'class' => '', ], 'estado', ]; @@ -538,7 +538,7 @@ class ModulesByStatus extends Widget 'alias', [ 'text' => 'last_status_change', - 'class' => 'flex-column', + 'class' => '', ], 'estado', ]; diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index 8786faa843..00a780be6d 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -977,3 +977,19 @@ input.resize_button { .event-cardboard-widget td { cursor: pointer; } + +.datatable-container-info-massage:not(:has(.invisible_important)) { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + height: 100%; + width: 100%; +} + +.info_box_information.datatable-info-massage.info_box_container + .info_box.info.textodialogo { + display: flex; + width: 100%; + justify-content: center; +}