From eefe7688b4b2670493f39d9685282ba604c98bc0 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 17 Jun 2020 12:48:20 +0200 Subject: [PATCH] Added log_viewer in metaconsole --- pandora_console/include/functions_agents.php | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 6c1bcbc331..bb819ef416 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1661,6 +1661,57 @@ function agents_get_alias($id_agent, $case='none') } +/** + * Get alias of an agent in metaconsole (cached function). + * + * @param integer $id_agent Agent id. + * @param string $case Case (upper, lower, none). + * @param integer $id_server server id. + * + * @return string Alias of the given agent. + */ +function agents_get_alias_metaconsole($id_agent, $case='none', $id_server=false) +{ + global $config; + // Prepare cache. + static $cache = []; + if (empty($case)) { + $case = 'none'; + } + + // Check cache. + if (isset($cache[$case][$id_server][$id_agent])) { + return $cache[$case][$id_server][$id_agent]; + } + + $alias = (string) db_get_value_filter( + 'alias', + 'tmetaconsole_agent', + [ + 'id_tagente' => $id_agent, + 'id_tmetaconsole_setup' => $id_server, + ] + ); + + switch ($case) { + case 'upper': + $alias = mb_strtoupper($alias, 'UTF-8'); + break; + + case 'lower': + $alias = mb_strtolower($alias, 'UTF-8'); + break; + + default: + // Not posible. + break; + } + + $cache[$case][$id_server][$id_agent] = $alias; + return $alias; +} + + function agents_get_alias_by_name($name, $case='none') { if (is_metaconsole()) {