From 9519e00992bc64ebc93a49575456550cf32fc063 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 11 Jan 2022 16:06:58 +0100 Subject: [PATCH] Fix issues with select agents modules control --- pandora_console/include/constants.php | 1 + pandora_console/include/functions_html.php | 17 +++------- pandora_console/include/functions_modules.php | 12 +++++-- .../include/javascript/pandora_dashboards.js | 2 +- .../lib/Dashboard/Widgets/agent_module.php | 34 +++++++++---------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index b0bedf04aa..f2b73b332d 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -113,6 +113,7 @@ define('SECONDS_3YEARS', 94608000); // Separator constats. define('SEPARATOR_COLUMN', ';'); define('SEPARATOR_ROW', chr(10)); +define('SEPARATOR_META_MODULE', '|-|-|-|'); // Chr(10) is \n. define('SEPARATOR_COLUMN_CSV', '#'); define('SEPARATOR_ROW_CSV', "@\n"); diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 44536cb843..0873ba072a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1555,33 +1555,24 @@ function html_print_select_multiple_modules_filtered(array $data):string ); if ($data['mAgents'] !== null) { - $all_modules = select_modules_for_agent_group( + $all_modules = get_modules_agents( $data['mModuleGroup'], explode(',', $data['mAgents']), $data['mShowCommonModules'], - false + false, + true ); } else { $all_modules = []; } - if (isset($data['mShowSelectedOtherGroups']) === true) { - $selected_modules_ids = explode(',', $data['mModules']); - foreach ($selected_modules_ids as $id) { - if (array_key_exists($id, $all_modules) === false) { - $module_data = modules_get_agentmodule($id); - $all_modules[$id] = $module_data['nombre']; - } - } - } - $output .= html_print_input( [ 'label' => __('Modules'), 'type' => 'select', 'fields' => $all_modules, 'name' => 'filtered-module-modules-'.$uniqId, - 'selected' => explode(',', $data['mModules']), + 'selected' => explode((is_metaconsole() === true) ? SEPARATOR_META_MODULE : ',', $data['mModules']), 'return' => true, 'multiple' => true, 'style' => 'min-width: 200px;max-width:200px;', diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 4f27b17896..6aafccd762 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3555,7 +3555,7 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) } -function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true) +function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true, $useName=false) { if ((bool) is_metaconsole() === true) { if ($select_mode === true) { @@ -3675,8 +3675,14 @@ function get_modules_agents($id_module_group, $id_agents, $selection, $select_mo $modules = array_reduce( $modules, - function ($carry, $item) { - $carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre']; + function ($carry, $item) use ($useName) { + // Only works in select mode. + if ($useName === true) { + $carry[io_safe_input($item['nombre'])] = io_safe_input($item['nombre']); + } else { + $carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre']; + } + return $carry; }, [] diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 71893c1f62..a3cc3b24fc 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -388,7 +388,7 @@ function initialiceLayout(data) { dashboardId: data.dashboardId, widgetId: widgetId }, - width: widgetId == 14 || widgetId == 2 ? 750 : 450, + width: widgetId == 14 || widgetId == 2 || widgetId == 23 ? 750 : 450, maxHeight: 600, minHeight: 400 }, diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index 097ab7f5f7..7e43b064b2 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -35,7 +35,6 @@ use PandoraFMS\Module; */ class AgentModuleWidget extends Widget { - const MODULE_SEPARATOR = '|-|-|-|'; /** * Name widget. @@ -309,16 +308,12 @@ class AgentModuleWidget extends Widget if (is_metaconsole() === true) { $values['mModules'] = implode( - self::MODULE_SEPARATOR, + SEPARATOR_META_MODULE, array_reduce( $values['mModules'], function ($carry, $item) { $d = explode('|', $item); - if (isset($d[1]) === true) { - $carry[] = \io_safe_output($d[1]); - } else { - $carry[] = \io_safe_output($item); - } + $carry[] = (isset($d[1]) === true) ? $d[1] : $item; return $carry; }, @@ -639,7 +634,7 @@ class AgentModuleWidget extends Widget $target_modules = $this->values['mModules']; if (is_metaconsole() === true) { $target_modules = explode( - self::MODULE_SEPARATOR, + SEPARATOR_META_MODULE, $this->values['mModules'] ); @@ -674,14 +669,7 @@ class AgentModuleWidget extends Widget if (is_object($item) === true) { $carry[$item->name()] = null; } else { - if ((is_metaconsole() === true - && $this->values['mShowCommonModules'] !== '1') - || is_metaconsole() === false - ) { - $carry[$item] = null; - } - - $carry[] = $item; + $carry[io_safe_output($item)] = null; } return $carry; @@ -721,8 +709,20 @@ class AgentModuleWidget extends Widget ) { // MC should connect to nodes and retrieve information // from targets. + $reduceAllModules = []; + $tmpModules = array_reduce( + $target_modules, + function ($carry, $item) { + // In this case, the modules come with 'ยป ' chain. + $tmpCarry = explode('» ', $item); + $carry[trim($tmpCarry[1])] = null; + + return $carry; + } + ); + $modules = $agent->searchModules( - ['id_agente_modulo' => $target_modules] + ['nombre' => array_keys($tmpModules)] ); foreach ($modules as $module) {