From ee3df634d60366d15ea3bb6cc3135f62d587ffcb Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 5 Dec 2023 10:35:02 +0100 Subject: [PATCH] fix error histogram and events history graph pandora_enterprise#12209 --- .../include/functions_reporting.php | 21 ++++++++++++++++++ .../VisualConsole/Items/EventsHistory.php | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index d7dfef4b58..fba3583ca1 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -15920,6 +15920,11 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) return false; } + if ($metaconsole_on && $server_name != '') { + // Restore db connection. + metaconsole_restore_db(); + } + $filter = [ 'id_agentmodule' => $content['id_agent_module'], 'group_rep' => EVENT_GROUP_REP_ALL, @@ -15927,6 +15932,10 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) 'time_to' => date('H:i:s', ($report['datetime'] - $content['period'])), ]; + if ($metaconsole_on && $server_name != '') { + $filter['id_server'] = $connection['id']; + } + $previous_event = events_get_all( ['te.event_type, te.timestamp, te.utimestamp'], $filter, @@ -15953,6 +15962,10 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) 'time_to' => date('H:i:s', $report['datetime']), ]; + if ($metaconsole_on && $server_name != '') { + $filter['id_server'] = $connection['id']; + } + $events = events_get_all( ['te.event_type, te.timestamp, te.utimestamp'], $filter, @@ -15963,6 +15976,14 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) true ); + // Metaconsole connection. + if ($metaconsole_on && $server_name != '') { + $connection = metaconsole_get_connection($server_name); + if (!metaconsole_load_external_db($connection)) { + ui_print_error_message('Error connecting to '.$server_name); + } + } + $not_init_data = []; $previous_data = [ 'event_type' => $status, diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php b/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php index 7db7139259..f5eeed5ace 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php @@ -120,6 +120,23 @@ final class EventsHistory extends Item $moduleId = static::parseIntOr($linkedModule['moduleId'], null); $legendColor = static::extractLegendColor($data); + $metaconsoleId = $linkedModule['metaconsoleId']; + + // Maybe connect to node. + $nodeConnected = false; + if (\is_metaconsole() === true && $metaconsoleId !== null) { + $nodeConnected = \metaconsole_connect( + null, + $metaconsoleId + ) === NOERR; + + if ($nodeConnected === false) { + throw new \InvalidArgumentException( + 'error connecting to the node' + ); + } + } + if ($agentId === null) { throw new \InvalidArgumentException('missing agent Id'); } @@ -166,6 +183,11 @@ final class EventsHistory extends Item $data['html'] = $html; + // Restore connection. + if ($nodeConnected === true) { + \metaconsole_restore_db(); + } + return $data; }