From 131be55be124298e64f9a8e2f1794d2dda91f8be Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 22 Nov 2021 16:18:53 +0100 Subject: [PATCH] #8277 Fixed search by agent --- .../godmode/alerts/alert_list.list.php | 10 ++++- pandora_console/include/functions_agents.php | 41 ++++--------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 9149ef5f87..d3e45b8f4b 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -34,6 +34,7 @@ require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_users.php'; $pure = get_parameter('pure', 0); +$agent_id = get_parameter('agent_id', 0); if (defined('METACONSOLE')) { $sec = 'advanced'; @@ -74,6 +75,11 @@ $params['input_name'] = 'agent_name'; $params['value'] = $agentName; $params['size'] = 24; $params['metaconsole_enabled'] = false; +$params['use_hidden_input_idagent'] = true; +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent'; +$params['hidden_input_idagent_name'] = 'agent_id'; +$params['hidden_input_idagent_value'] = $agent_id; $form_filter .= ui_print_agent_autocomplete_input($params); @@ -234,7 +240,7 @@ if ($searchFlag) { $id_agents = array_keys($agents); $total = agents_get_alerts_simple( - $id_agents, + (empty($agent_id) === false) ? ['0' => $agent_id] : $id_agents, false, false, $where, @@ -412,7 +418,7 @@ if ($id_agente) { $offset = (int) get_parameter('offset'); $simple_alerts = agents_get_alerts_simple( - $id_agents, + (empty($agent_id) === false) ? ['0' => $agent_id] : $id_agents, false, [ 'offset' => $offset, diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4e3765a003..28f563b8e7 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -421,12 +421,13 @@ function agents_get_alerts_simple($id_agent=false, $filter='', $options=false, $ INNER JOIN tagente_modulo t2 ON talert_template_modules.id_agent_module = t2.id_agente_modulo INNER JOIN tagente t3 - ON t2.id_agente = t3.id_agente + ON t2.id_agente = t3.id_agente %s %s INNER JOIN talert_templates t4 ON talert_template_modules.id_alert_template = t4.id WHERE id_agent_module in (%s) %s %s %s', $selectText, + ($id_agent !== false && is_array($id_agent)) ? 'AND t3.id_agente IN ('.implode(',', $id_agent).')' : '', $secondary_join, $subQuery, $where, @@ -434,40 +435,14 @@ function agents_get_alerts_simple($id_agent=false, $filter='', $options=false, $ $orderbyText ); - switch ($config['dbtype']) { - case 'mysql': - $limit_sql = ''; - if (isset($offset) && isset($limit)) { - $limit_sql = " LIMIT $offset, $limit "; - } - - $sql = sprintf('%s %s', $sql, $limit_sql); - $alerts = db_get_all_rows_sql($sql); - break; - - case 'postgresql': - $limit_sql = ''; - if (isset($offset) && isset($limit)) { - $limit_sql = " OFFSET $offset LIMIT $limit "; - } - - $sql = sprintf('%s %s', $sql, $limit_sql); - - $alerts = db_get_all_rows_sql($sql); - - break; - - case 'oracle': - $set = []; - if (isset($offset) && isset($limit)) { - $set['limit'] = $limit; - $set['offset'] = $offset; - } - - $alerts = oracle_recode_query($sql, $set, 'AND', false); - break; + $limit_sql = ''; + if (isset($offset) && isset($limit)) { + $limit_sql = " LIMIT $offset, $limit "; } + $sql = sprintf('%s %s', $sql, $limit_sql); + $alerts = db_get_all_rows_sql($sql); + if ($alerts === false) { return []; }