From 90013603a78d58c04d1d4ae285b9e8a9e33596e5 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 13 Jun 2022 17:06:09 +0200 Subject: [PATCH] refactor events meta pandora_enterprise#9086 --- pandora_console/include/functions_config.php | 4 + pandora_console/include/functions_events.php | 125 +++++++++++-------- pandora_console/operation/events/events.php | 5 +- 3 files changed, 78 insertions(+), 56 deletions(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 855bc67a7d..73fab7a130 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -2054,6 +2054,10 @@ function config_process_config() config_update_value('max_execution_event_response', 10); } + if (!isset($config['max_number_of_events_per_node'])) { + config_update_value('max_number_of_events_per_node', 100000); + } + if (!isset($config['max_macro_fields'])) { config_update_value('max_macro_fields', 10); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 66f096d7bd..13e39c6806 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1338,13 +1338,18 @@ function events_get_all( $id_server = 0; if (empty($filter['id_server']) === false) { $id_server = $filter['id_server']; + } else if (empty($filter['server_id']) === false) { + $id_server = $filter['server_id']; } // Pagination. $pagination = ''; - if (is_metaconsole() === true) { - // TODO: XXX TOTAL 10000 - 10000000. settins meta 300000; TIP. capturra el error. - $pagination = ' LIMIT 100000 '; + if (is_metaconsole() === true && empty($id_server) === true) { + // TODO: XXX TIP. capturra el error. + $pagination = sprintf( + ' LIMIT %d', + $config['max_number_of_events_per_node'] + ); } else if (isset($limit, $offset) === true && $limit > 0) { $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); } @@ -1512,63 +1517,70 @@ function events_get_all( ('.$sql.') tbase'; } - if ($count !== true) { - if (is_metaconsole() === true) { - $result_meta = []; - $metaconsole_connections = metaconsole_get_names(); - if (isset($metaconsole_connections) === true - && is_array($metaconsole_connections) === true - ) { - try { - if (empty($id_server) === true) { - $metaconsole_connections = array_flip($metaconsole_connections); - $metaconsole_connections['meta'] = 0; - } else { - $only_id_server[$metaconsole_connections[$id_server]] = $id_server; - $metaconsole_connections = $only_id_server; - } + if ($count === true + && (is_metaconsole() !== false + || (is_metaconsole() === true && empty($filter['server_id']) === false)) + ) { + $sql = 'SELECT count(*) as nitems FROM ('.$sql.') tt'; + } - $result_meta = Promise\wait( - parallelMap( - $metaconsole_connections, - function ($node) use ($sql) { - if ($node !== 0) { - $node = new Node((int) $node); - $node->connect(); - } + if (is_metaconsole() === true) { + $result_meta = []; + $metaconsole_connections = metaconsole_get_names(); + if (isset($metaconsole_connections) === true + && is_array($metaconsole_connections) === true + ) { + try { + if (empty($id_server) === true) { + $metaconsole_connections = array_flip($metaconsole_connections); + $metaconsole_connections['meta'] = 0; + } else { + $only_id_server[$metaconsole_connections[$id_server]] = $id_server; + $metaconsole_connections = $only_id_server; + } - $res = db_get_all_rows_sql($sql); - if ($res === false) { - $res = []; - } - - if ($node !== 0) { - $node->disconnect(); - } - - return $res; + $result_meta = Promise\wait( + parallelMap( + $metaconsole_connections, + function ($node) use ($sql) { + if ($node !== 0) { + $node = new Node((int) $node); + $node->connect(); } - ) - ); - } catch (\Exception $e) { - $e->getReasons(); - } - } - $data = []; - if (empty($result_meta) === false) { - foreach ($result_meta as $node => $value) { - if (empty($value) === false) { - foreach ($value as $k => $v) { - $value[$k]['server_id'] = $metaconsole_connections[$node]; - $value[$k]['server_name'] = $node; + $res = db_get_all_rows_sql($sql); + if ($res === false) { + $res = []; + } + + if ($node !== 0) { + $node->disconnect(); + } + + return $res; } + ) + ); + } catch (\Exception $e) { + $e->getReasons(); + } + } - $data = array_merge($data, $value); + $data = []; + if (empty($result_meta) === false) { + foreach ($result_meta as $node => $value) { + if (empty($value) === false) { + foreach ($value as $k => $v) { + $value[$k]['server_id'] = $metaconsole_connections[$node]; + $value[$k]['server_name'] = $node; } + + $data = array_merge($data, $value); } } + } + if (empty($filter['server_id']) === true) { // TODO: XXX; hd($sort_field, true); hd($order, true); @@ -1620,20 +1632,23 @@ function events_get_all( $count = count($data); $end = ((int) $offset !== 0) ? ($offset + $limit) : $limit; $finally = array_slice($data, $offset, $end, true); - $return = [ 'data' => $finally, 'total' => $count, ]; } else { - // TODO: XXX limit * nodes. - $return = array_slice($data, 0, 1000000, true); + $return = array_slice( + $data, + 0, + ($config['max_number_of_events_per_node'] * count($metaconsole_connections)), + true + ); } return $return; + } else { + return $data; } - } else { - $sql = 'SELECT count(*) as nitems FROM ('.$sql.') tt'; } if ($return_sql) { diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 3dd916da45..2459fab187 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -352,7 +352,10 @@ if (is_ajax() === true) { $history ); - if (is_metaconsole() === false) { + if (is_metaconsole() === false + || (is_metaconsole() === true + && empty($filter['server_id']) === false) + ) { $count = events_get_all( 'count', $filter,