From e311c81f845f210e4bc64a56d1cbf29aee4911d2 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 24 Mar 2023 14:11:08 +0100 Subject: [PATCH] #8642 Fixed meta --- pandora_console/include/ajax/heatmap.ajax.php | 12 + .../include/class/Heatmap.class.php | 1008 +++++++++++------ 2 files changed, 684 insertions(+), 336 deletions(-) diff --git a/pandora_console/include/ajax/heatmap.ajax.php b/pandora_console/include/ajax/heatmap.ajax.php index abfcd39e45..dd22fcdfef 100644 --- a/pandora_console/include/ajax/heatmap.ajax.php +++ b/pandora_console/include/ajax/heatmap.ajax.php @@ -26,6 +26,8 @@ * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Node; + if (is_ajax() === true) { global $config; @@ -216,6 +218,12 @@ if (is_ajax() === true) { if ($getInfo === true) { enterprise_include_once('include/functions_agents.php'); $id = get_parameter('id', 0); + $id_server = get_parameter('id_server', 0); + if (empty($id_server) === false) { + $nd = new Node($id_server); + $nd->connect(); + } + switch ($type) { case 3: case 2: @@ -375,6 +383,10 @@ if (is_ajax() === true) { } break; } + + if (empty($id_server) === false) { + $nd->disconnect(); + } } return; diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index c440fcfecc..de3ef90ba3 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -1,4 +1,5 @@ randomId.'" class="mainDiv" style="width: 100%;height: 100%;'.$style_dashboard.'">'; ?> - + } + }); + } + }); + '; } @@ -397,51 +404,115 @@ class Heatmap $id_grupo ); - $result = db_get_all_rows_sql($sql); - $agents = []; - // Agent status. - foreach ($result as $key => $agent) { - if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { - $status = 'notinit'; - } else if ($agent['critical_count'] > 0) { - $status = 'critical'; - } else if ($agent['warning_count'] > 0) { - $status = 'warning'; - } else if ($agent['unknown_count'] > 0) { - $status = 'unknown'; - } else { - $status = 'normal'; - } + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - if ($agent['last_status_change'] != 0) { - $seconds = (time() - $agent['last_status_change']); + $result = db_get_all_rows_sql($sql); + // Agent status. + foreach ($result as $agent) { + if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { + $status = 'notinit'; + } else if ($agent['critical_count'] > 0) { + $status = 'critical'; + } else if ($agent['warning_count'] > 0) { + $status = 'warning'; + } else if ($agent['unknown_count'] > 0) { + $status = 'unknown'; + } else { + $status = 'normal'; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($agent['last_status_change'] != 0) { + $seconds = (time() - $agent['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $agents[$cont] = $agent; + $agents[$cont]['status'] = $status; + $agents[$cont]['server'] = $node['id']; + + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + $agents = []; + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $agents[$key] = $agent; - $agents[$key]['status'] = $status; + // Agent status. + foreach ($result as $key => $agent) { + if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { + $status = 'notinit'; + } else if ($agent['critical_count'] > 0) { + $status = 'critical'; + } else if ($agent['warning_count'] > 0) { + $status = 'warning'; + } else if ($agent['unknown_count'] > 0) { + $status = 'unknown'; + } else { + $status = 'normal'; + } + + if ($agent['last_status_change'] != 0) { + $seconds = (time() - $agent['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $agents[$key] = $agent; + $agents[$key]['status'] = $status; + } } return $agents; @@ -491,71 +562,157 @@ class Heatmap $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $cont = 0; + $result = []; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -600,77 +757,163 @@ class Heatmap ae.last_status_change FROM tagente_estado ae %s INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo - WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo', + WHERE 1=1 %s %s GROUP BY ae.id_agente_modulo', $id_user_groups, $filter_tag, $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $result = []; + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -714,71 +957,157 @@ class Heatmap $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $result = []; + $nodes = metaconsole_get_connections(); + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + $result = []; + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -876,7 +1205,6 @@ class Heatmap { $yAxis = sqrt(($total / $relation)); return $yAxis; - } @@ -887,7 +1215,7 @@ class Heatmap * * @return boolean True allowed, false not. */ - public function ajaxMethod(string $method):bool + public function ajaxMethod(string $method): bool { return in_array($method, $this->AJAXMethods); } @@ -933,8 +1261,13 @@ class Heatmap $contY = 0; $cont = 1; foreach ($result as $value) { + $name = $value['id']; + if (empty($value['server']) === false) { + $name .= '|'.$value['server']; + } + echo ''; + width="1" height="1" x ="'.$contX.' "y="'.$contY.'" name="'.$name.'" />'; $contX++; if ($contX >= $Xaxis) { @@ -952,39 +1285,42 @@ class Heatmap } ?> - + }); + 1 && $this->group === 1 && $this->dashboard === false) { $x_back = 0;