From 362c1d2a510ad698c5bc8698158980845b1cecc8 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 11 Feb 2022 13:22:35 +0100 Subject: [PATCH 1/3] fix module name finish % pandora_enterprise#8570 --- .../godmode/reporting/visual_console_builder.php | 15 +++++++-------- pandora_console/include/functions_agents.php | 3 +++ pandora_console/include/lib/Agent.php | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 83b9e94998..0d36c636d4 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -31,6 +31,7 @@ global $config; global $statusProcessInDB; +use PandoraFMS\Agent; use PandoraFMS\User; check_login(); @@ -705,15 +706,13 @@ switch ($activeTab) { } else { foreach ($name_modules as $mod) { foreach ($id_agents as $ag) { - $id_module = agents_get_modules( - $ag, - ['id_agente_modulo'], - ['nombre' => $mod] - ); + $agent = new Agent($ag); + $id_module = $agent->searchModules( + ['nombre' => $mod], + 1 + )->id_agente_modulo(); - - - if (empty($id_module)) { + if (empty($id_module) === true) { continue; } else { $id_module = reset($id_module); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 91bdfd2fe1..56b9031e77 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1430,6 +1430,9 @@ function agents_get_group_agents( /** + * @deprecated use \PandoraFMS\Agent::searchModules + * + * * Get all the modules in an agent. If an empty list is passed it will select all * * @param mixed Agent id to get modules. It can also be an array of agent id's, by default is null and this mean that use the ids of agents in user's groups. diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php index 56a46fe70f..5b32d4c1c6 100644 --- a/pandora_console/include/lib/Agent.php +++ b/pandora_console/include/lib/Agent.php @@ -549,7 +549,8 @@ class Agent extends Entity * @param array $filter Filters. * @param integer $limit Limit search results. * - * @return array Of PandoraFMS\Module Modules found. + * @return array|Module Of PandoraFMS\Module Modules + * found or Module found is limit 1. */ public function searchModules(array $filter, int $limit=0) { From bc9bb070dfe1da5b17e82980aaa01598587169c0 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 14 Feb 2022 08:55:14 +0100 Subject: [PATCH 2/3] fix module name finish % pandora_enterprise#8570 --- pandora_console/godmode/reporting/visual_console_builder.php | 2 +- pandora_console/include/lib/Agent.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 0d36c636d4..4f1dbaff1b 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -710,7 +710,7 @@ switch ($activeTab) { $id_module = $agent->searchModules( ['nombre' => $mod], 1 - )->id_agente_modulo(); + )->toArray(); if (empty($id_module) === true) { continue; diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php index 5b32d4c1c6..76c7113398 100644 --- a/pandora_console/include/lib/Agent.php +++ b/pandora_console/include/lib/Agent.php @@ -578,7 +578,10 @@ class Agent extends Entity } else { // Search in db. $return = Module::search($filter, $limit); - if (is_array($return) === false) { + + if (is_array($return) === false + && is_object($return) === false + ) { return []; } From c8daf0a977efd8add19d6b666cedfafbdee5878c Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 14 Feb 2022 11:13:33 +0100 Subject: [PATCH 3/3] fix module name finish % pandora_enterprise#8570 --- .../reporting/visual_console_builder.php | 57 +++++++------------ .../visual_console_builder.wizard.php | 2 +- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 4f1dbaff1b..4939102d39 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -631,44 +631,30 @@ switch ($activeTab) { 'message' => $message, ]; } else { - // One item per module - if (empty($name_modules)) { - $statusProcessInDB = [ - 'flag' => true, - 'message' => ui_print_error_message( - __('No modules selected'), - '', - true - ), - ]; - } else { - if (defined('METACONSOLE')) { - $agents_ids = []; - foreach ($id_agents as $id_agent_id) { - $server_and_agent = explode('|', $id_agent_id); + if (is_metaconsole() === true) { + $agents_ids = []; + foreach ($id_agents as $id_agent_id) { + $server_and_agent = explode('|', $id_agent_id); - $agents_ids[] = $server_and_agent[1]; - } - - $rows = db_get_all_rows_filter( - 'tmetaconsole_agent', - ['id_tagente' => $agents_ids] - ); - - $agents = []; - foreach ($rows as $row) { - $agents[$row['id_tmetaconsole_setup']][] = $row['id_tagente']; - } - } else { - $agents[0] = $id_agents; + $agents_ids[] = $server_and_agent[1]; } + + $rows = db_get_all_rows_filter( + 'tmetaconsole_agent', + ['id_tagente' => $agents_ids] + ); + + $agents = []; + foreach ($rows as $row) { + $agents[$row['id_tmetaconsole_setup']][] = $row['id_tagente']; + } + } else { + $agents[0] = $id_agents; } - - foreach ($agents as $id_server => $id_agents) { - // Any module - if ($name_modules[0] == '0') { + // Any module. + if (empty($name_modules) === true || $name_modules[0] === '0') { $message .= visual_map_process_wizard_add_agents( $id_agents, $image, @@ -710,13 +696,10 @@ switch ($activeTab) { $id_module = $agent->searchModules( ['nombre' => $mod], 1 - )->toArray(); + )->toArray()['id_agente_modulo']; if (empty($id_module) === true) { continue; - } else { - $id_module = reset($id_module); - $id_module = $id_module['id_agente_modulo']; } $id_modules[] = $id_module; diff --git a/pandora_console/godmode/reporting/visual_console_builder.wizard.php b/pandora_console/godmode/reporting/visual_console_builder.wizard.php index 122b40416f..2468214dff 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.wizard.php +++ b/pandora_console/godmode/reporting/visual_console_builder.wizard.php @@ -533,7 +533,7 @@ echo ''; echo ''; // Trick for it have a traduct text for javascript. -echo ''; +echo ''; echo ''; echo ''; ?>