From 0b04ba44f2e9fcec9ec2d3b1912c285192eee5c9 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 12:15:39 +0100 Subject: [PATCH] wip reports alert actions --- .../reporting_builder.item_editor.php | 6 --- .../godmode/reporting/reporting_builder.php | 5 --- pandora_console/include/functions_modules.php | 42 ++++++++++++++++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index fe1ba14bf3..cc641891e6 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -753,10 +753,6 @@ switch ($action) { $description = $item['description']; $es = json_decode($item['external_source'], true); - hd($es); - - hd(base64_decode($es['id_agents'])); - // Decode agents and modules. $id_agents = json_decode( io_safe_output(base64_decode($es['id_agents'])), @@ -4878,8 +4874,6 @@ $(document).ready (function () { case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); - console.log(agents_multiple); - console.log(modules_multiple); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); $('#id_agents2').val(''); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index f429cc6c06..26be0e954d 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1725,8 +1725,6 @@ switch ($action) { $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; - hd($es); - $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); @@ -2518,9 +2516,6 @@ switch ($action) { $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; - - hd($es); - $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index eaa44fe741..7d02fc3d63 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1435,6 +1435,45 @@ function modules_get_agentmodule_name($id_agente_modulo) } +/** + * Get the module names of an agent module. + * + * @param array $array_ids Agents module ids. + * + * @return array Id => name. + */ +function modules_get_agentmodule_name_array($array_ids) +{ + if (is_array($array_ids) === false || empty($array_ids) === true) { + return []; + } + + $sql = sprintf( + 'SELECT id_agente_modulo as id, nombre as `name` + FROM tagente_modulo + WHERE id_agente_modulo IN (%s)', + implode(',', $array_ids) + ); + + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = []; + } + + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + return $result; +} + + /** * Get the module descripcion of an agent module. * @@ -3471,10 +3510,11 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) function get_same_modules($agents, $modules) { + $name_modules = modules_get_agentmodule_name_array(array_values($modules)); $modules_to_report = []; if ($modules != '') { foreach ($modules as $m) { - $module_name = modules_get_agentmodule_name($m); + $module_name = $name_modules[$m]; foreach ($agents as $a) { $module_in_agent = db_get_value_filter( 'id_agente_modulo',