From 8a221f10b0c554ccc46a23627b05186c53403fba Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 11 Apr 2022 14:20:17 +0200 Subject: [PATCH] allow disable counters on mc environments --- .../include/class/TreeService.class.php | 104 ++++++++++-------- pandora_console/include/functions_config.php | 4 + 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index ebca4562a6..0b29b3a895 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -530,33 +530,6 @@ class TreeService extends Tree $tmp['elementDescription'] = $item->description(); $tmp['disabled'] = $item->service()->disabled(); - if ($this->connectedToNode === false - && is_metaconsole() === true - && $tmp['metaID'] > 0 - ) { - // Impersonate node. - \enterprise_include_once('include/functions_metaconsole.php'); - \enterprise_hook( - 'metaconsole_connect', - [ - null, - $tmp['metaID'], - ] - ); - } - - if (check_acl($config['id_user'], $item->service()->id_group(), 'AR')) { - $grandchildren = $item->service()->children(); - } - - if ($this->connectedToNode === false - && is_metaconsole() === true - && $tmp['metaID'] > 0 - ) { - // Restore connection. - \enterprise_hook('metaconsole_restore_db'); - } - $counters = [ 'total_modules' => 0, 'total_agents' => 0, @@ -565,29 +538,66 @@ class TreeService extends Tree 'total' => 0, ]; - if (is_array($grandchildren) === true) { - $counters = array_reduce( - $grandchildren, - function ($carry, $item) { - if ($item->type() === SERVICE_ELEMENT_MODULE) { - $carry['total_modules']++; - } else if ($item->type() === SERVICE_ELEMENT_AGENT) { - $carry['total_agents']++; - } else if ($item->type() === SERVICE_ELEMENT_SERVICE) { - $carry['total_services']++; - } else if ($item->type() === SERVICE_ELEMENT_DYNAMIC) { - $carry['total_dynamic']++; - } + if (is_metaconsole() === false + || (isset($config['realtimestats']) === true + && $config['realtimestats'] === true + && $tmp['metaID'] > 0) + ) { + // Look for counters. + if ($this->connectedToNode === false + && is_metaconsole() === true + && $tmp['metaID'] > 0 + ) { + // Impersonate node. + \enterprise_include_once('include/functions_metaconsole.php'); + \enterprise_hook( + 'metaconsole_connect', + [ + null, + $tmp['metaID'], + ] + ); + } - $carry['total']++; + if (check_acl($config['id_user'], $item->service()->id_group(), 'AR')) { + $grandchildren = $item->service()->children(); + } - return $carry; - }, - $counters - ); - } + if ($this->connectedToNode === false + && is_metaconsole() === true + && $tmp['metaID'] > 0 + ) { + // Restore connection. + \enterprise_hook('metaconsole_restore_db'); + } - if ($counters['total'] > 0) { + if (is_array($grandchildren) === true) { + $counters = array_reduce( + $grandchildren, + function ($carry, $item) { + if ($item->type() === SERVICE_ELEMENT_MODULE) { + $carry['total_modules']++; + } else if ($item->type() === SERVICE_ELEMENT_AGENT) { + $carry['total_agents']++; + } else if ($item->type() === SERVICE_ELEMENT_SERVICE) { + $carry['total_services']++; + } else if ($item->type() === SERVICE_ELEMENT_DYNAMIC) { + $carry['total_dynamic']++; + } + + $carry['total']++; + + return $carry; + }, + $counters + ); + } + + if ($counters['total'] > 0) { + $tmp['searchChildren'] = 1; + } + } else { + // Always search for. $tmp['searchChildren'] = 1; } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 6f79be6c76..337c0d4ec6 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -2060,6 +2060,10 @@ function config_process_config() config_update_value('metaconsole_events_history', 0); } + if (!isset($config['realtimestats'])) { + config_update_value('realtimestats', 1); + } + if (!isset($config['trap_purge'])) { config_update_value('trap_purge', 7); }