refactor events meta pandora_enterprise#9086

This commit is contained in:
Daniel Barbero Martin 2022-06-13 17:06:09 +02:00
parent 5680b82563
commit 90013603a7
3 changed files with 78 additions and 56 deletions

View File

@ -2054,6 +2054,10 @@ function config_process_config()
config_update_value('max_execution_event_response', 10); 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'])) { if (!isset($config['max_macro_fields'])) {
config_update_value('max_macro_fields', 10); config_update_value('max_macro_fields', 10);
} }

View File

@ -1338,13 +1338,18 @@ function events_get_all(
$id_server = 0; $id_server = 0;
if (empty($filter['id_server']) === false) { if (empty($filter['id_server']) === false) {
$id_server = $filter['id_server']; $id_server = $filter['id_server'];
} else if (empty($filter['server_id']) === false) {
$id_server = $filter['server_id'];
} }
// Pagination. // Pagination.
$pagination = ''; $pagination = '';
if (is_metaconsole() === true) { if (is_metaconsole() === true && empty($id_server) === true) {
// TODO: XXX TOTAL 10000 - 10000000. settins meta 300000; TIP. capturra el error. // TODO: XXX TIP. capturra el error.
$pagination = ' LIMIT 100000 '; $pagination = sprintf(
' LIMIT %d',
$config['max_number_of_events_per_node']
);
} else if (isset($limit, $offset) === true && $limit > 0) { } else if (isset($limit, $offset) === true && $limit > 0) {
$pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
} }
@ -1512,63 +1517,70 @@ function events_get_all(
('.$sql.') tbase'; ('.$sql.') tbase';
} }
if ($count !== true) { if ($count === true
if (is_metaconsole() === true) { && (is_metaconsole() !== false
$result_meta = []; || (is_metaconsole() === true && empty($filter['server_id']) === false))
$metaconsole_connections = metaconsole_get_names(); ) {
if (isset($metaconsole_connections) === true $sql = 'SELECT count(*) as nitems FROM ('.$sql.') tt';
&& 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;
}
$result_meta = Promise\wait( if (is_metaconsole() === true) {
parallelMap( $result_meta = [];
$metaconsole_connections, $metaconsole_connections = metaconsole_get_names();
function ($node) use ($sql) { if (isset($metaconsole_connections) === true
if ($node !== 0) { && is_array($metaconsole_connections) === true
$node = new Node((int) $node); ) {
$node->connect(); 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); $result_meta = Promise\wait(
if ($res === false) { parallelMap(
$res = []; $metaconsole_connections,
} function ($node) use ($sql) {
if ($node !== 0) {
if ($node !== 0) { $node = new Node((int) $node);
$node->disconnect(); $node->connect();
}
return $res;
} }
)
);
} catch (\Exception $e) {
$e->getReasons();
}
}
$data = []; $res = db_get_all_rows_sql($sql);
if (empty($result_meta) === false) { if ($res === false) {
foreach ($result_meta as $node => $value) { $res = [];
if (empty($value) === false) { }
foreach ($value as $k => $v) {
$value[$k]['server_id'] = $metaconsole_connections[$node]; if ($node !== 0) {
$value[$k]['server_name'] = $node; $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; // TODO: XXX;
hd($sort_field, true); hd($sort_field, true);
hd($order, true); hd($order, true);
@ -1620,20 +1632,23 @@ function events_get_all(
$count = count($data); $count = count($data);
$end = ((int) $offset !== 0) ? ($offset + $limit) : $limit; $end = ((int) $offset !== 0) ? ($offset + $limit) : $limit;
$finally = array_slice($data, $offset, $end, true); $finally = array_slice($data, $offset, $end, true);
$return = [ $return = [
'data' => $finally, 'data' => $finally,
'total' => $count, 'total' => $count,
]; ];
} else { } else {
// TODO: XXX limit * nodes. $return = array_slice(
$return = array_slice($data, 0, 1000000, true); $data,
0,
($config['max_number_of_events_per_node'] * count($metaconsole_connections)),
true
);
} }
return $return; return $return;
} else {
return $data;
} }
} else {
$sql = 'SELECT count(*) as nitems FROM ('.$sql.') tt';
} }
if ($return_sql) { if ($return_sql) {

View File

@ -352,7 +352,10 @@ if (is_ajax() === true) {
$history $history
); );
if (is_metaconsole() === false) { if (is_metaconsole() === false
|| (is_metaconsole() === true
&& empty($filter['server_id']) === false)
) {
$count = events_get_all( $count = events_get_all(
'count', 'count',
$filter, $filter,