From 6efaa2bbc605747c02e1922ebb326e130addee97 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 21 Feb 2023 15:06:15 +0100 Subject: [PATCH 1/7] #8642 Added heatmap widget --- pandora_console/include/class/Heatmap.class.php | 4 +++- pandora_console/include/lib/Dashboard/Widget.php | 4 ++++ pandora_console/operation/heatmap.php | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index 8572d6cad1..bab7f8fd85 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -25,6 +25,8 @@ * GNU General Public License for more details. * ============================================================================ */ + +namespace PandoraFMS; class Heatmap { @@ -159,7 +161,7 @@ class Heatmap ], ]; - echo '
'; + echo '
'; ?> 1 && $this->group === 1) { + if (count($groups) > 1 && $this->group === 1 && $this->dashboard === false) { $x_back = 0; $y_back = 0; @@ -1111,7 +1185,7 @@ class Heatmap echo ''; // Dialog. - echo ''; + echo '
'; } diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 7ffafd974f..3347ff0323 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -1560,3 +1560,36 @@ function showManualThresholds(element) { $(".dashboard-input-threshold-critical").addClass("invisible_important"); } } + +/** + * @return {void} + */ +// eslint-disable-next-line no-unused-vars +function type_change() { + var type = document.getElementById("type").value; + + switch (type) { + case "3": + $("#li_tags").hide(); + $("#li_groups").hide(); + $("#li_module_groups").hide(); + break; + case "2": + $("#li_tags").hide(); + $("#li_groups").hide(); + $("#li_module_groups").show(); + break; + case "1": + $("#li_tags").show(); + $("#li_groups").hide(); + $("#li_module_groups").hide(); + break; + + default: + case "0": + $("#li_tags").hide(); + $("#li_groups").show(); + $("#li_module_groups").hide(); + break; + } +} diff --git a/pandora_console/include/lib/Dashboard/Widgets/heatmap.php b/pandora_console/include/lib/Dashboard/Widgets/heatmap.php index c10c7c1f27..2f9d9533cd 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/heatmap.php +++ b/pandora_console/include/lib/Dashboard/Widgets/heatmap.php @@ -192,6 +192,26 @@ class HeatmapWidget extends Widget // Retrieve global - common inputs. $values = parent::decoders($decoder); + if (isset($decoder['search']) === true) { + $values['search'] = $decoder['search']; + } + + if (isset($decoder['type']) === true) { + $values['type'] = $decoder['type']; + } + + if (isset($decoder['groups']) === true) { + $values['groups'] = $decoder['groups']; + } + + if (isset($decoder['tags']) === true) { + $values['tags'] = $decoder['tags']; + } + + if (isset($decoder['module_groups']) === true) { + $values['module_groups'] = $decoder['module_groups']; + } + return $values; } @@ -205,9 +225,117 @@ class HeatmapWidget extends Widget */ public function getFormInputs(): array { + global $config; // Retrieve global - common inputs. $inputs = parent::getFormInputs(); + $values = $this->values; + + // Search. + $inputs[] = [ + 'label' => \__('Search'), + 'arguments' => [ + 'name' => 'search', + 'type' => 'text', + 'class' => 'event-widget-input', + 'value' => $values['search'], + 'return' => true, + 'size' => 30, + ], + ]; + + $inputs[] = [ + 'label' => __('Type'), + 'arguments' => [ + 'type' => 'select', + 'fields' => [ + 0 => __('Group agents'), + 1 => __('Group modules by tag'), + 2 => __('Group modules by module group'), + 3 => __('Group modules by agents'), + ], + 'name' => 'type', + 'selected' => $values['type'], + 'script' => 'type_change()', + 'return' => true, + ], + ]; + + // Filters. + $inputs[] = [ + 'label' => __('Groups'), + 'style' => ($values['type'] === '0') ? '' : 'display:none', + 'id' => 'li_groups', + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groups[]', + 'returnAllGroup' => true, + 'privilege' => 'AR', + 'selected' => explode(',', $values['groups'][0]), + 'return' => true, + 'multiple' => true, + ], + ]; + + if (tags_has_user_acl_tags($config['id_user']) === false) { + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name' + ); + } else { + $user_tags = tags_get_user_tags($config['id_user'], 'AR'); + if (empty($user_tags) === false) { + $id_user_tags = array_keys($user_tags); + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag + WHERE id_tag IN ('.implode(',', $id_user_tags).') + ORDER BY name' + ); + } else { + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name' + ); + } + } + + $inputs[] = [ + 'label' => __('Tag'), + 'style' => ($values['type'] === '1') ? '' : 'display:none', + 'id' => 'li_tags', + 'arguments' => [ + 'type' => 'select', + 'fields' => $tags, + 'name' => 'tags[]', + 'selected' => explode(',', $values['tags'][0]), + 'return' => true, + 'multiple' => true, + ], + ]; + + $module_groups_aux = db_get_all_rows_sql( + 'SELECT id_mg, name FROM tmodule_group ORDER BY name' + ); + + $module_groups = []; + foreach ($module_groups_aux as $key => $module_group) { + $module_groups[$module_group['id_mg']] = $module_group['name']; + } + + $inputs[] = [ + 'label' => __('Module group'), + 'style' => ($values['type'] === '2') ? '' : 'display:none', + 'id' => 'li_module_groups', + 'arguments' => [ + 'type' => 'select', + 'fields' => $module_groups, + 'name' => 'module_groups[]', + 'selected' => explode(',', $values['module_groups'][0]), + 'return' => true, + 'multiple' => true, + 'nothing' => __('Not assigned'), + 'nothing_value' => 0, + ], + ]; + return $inputs; } @@ -222,6 +350,27 @@ class HeatmapWidget extends Widget // Retrieve global - common inputs. $values = parent::getPost(); + $values['search'] = \get_parameter('search', ''); + $values['type'] = \get_parameter('type', 0); + + switch ((int) $values['type']) { + case 2: + $values['module_groups'] = \get_parameter('module_groups', 0); + break; + + case 1: + $values['tags'] = \get_parameter('tags', 0); + break; + + case 0: + $values['groups'] = \get_parameter('groups', 0); + break; + + default: + // Do nothing. + break; + } + return $values; } @@ -256,8 +405,8 @@ class HeatmapWidget extends Widget public function getSizeModalConfiguration(): array { $size = [ - 'width' => 400, - 'height' => 205, + 'width' => 500, + 'height' => 300, ]; return $size; @@ -276,10 +425,23 @@ class HeatmapWidget extends Widget \ui_require_css_file('heatmap', 'include/styles/', true); $values = $this->values; - hd($values, true); + $search = (empty($values['search']) === false) ? $values['search'] : ''; + $type = (empty($values['type']) === false) ? $values['type'] : 0; + $filter = []; + if (isset($values['groups'])) { + $filter = explode(',', $values['groups'][0]); + } + + if (isset($values['tags'])) { + $filter = explode(',', $values['tags'][0]); + } + + if (isset($values['module_groups'])) { + $filter = explode(',', $values['module_groups'][0]); + } // Control call flow. - $heatmap = new Heatmap(0, [], null, 300, 400, 200, 0, 1); + $heatmap = new Heatmap($type, $filter, null, 300, 400, 200, $search, 0, true); // AJAX controller. if (is_ajax() === true) { $method = get_parameter('method'); diff --git a/pandora_console/operation/heatmap.php b/pandora_console/operation/heatmap.php index a53eebd698..1e063d3c3d 100644 --- a/pandora_console/operation/heatmap.php +++ b/pandora_console/operation/heatmap.php @@ -62,6 +62,8 @@ if ($group_sent === true) { $group = (int) get_parameter('group', true); } +$dashboard = (bool) get_parameter('dashboard', false); + $is_ajax = is_ajax(); if ($is_ajax === false && $pure === false) { $viewtab['config'] = ''.html_print_image( @@ -192,6 +194,7 @@ if ($is_ajax === false && $pure === true) { html_print_input_hidden('type', $type); html_print_input_hidden('search', $search); html_print_input_hidden('filter', implode(',', $filter)); + html_print_input_hidden('dashboard', $dashboard); echo ''; echo '
'; echo '
'; @@ -230,7 +233,7 @@ if ($is_ajax === false && $pure === true) { // Control call flow. try { // Heatmap construct. - $heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group); + $heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group, $dashboard); } catch (Exception $e) { if (is_ajax() === true) { echo json_encode(['error' => '[Heatmap]'.$e->getMessage() ]); From a7a283fe2275326b54848974d7c9f6aba9512cb0 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 14 Mar 2023 12:52:44 +0100 Subject: [PATCH 5/7] #8642 Fixed heatmap widget --- pandora_console/include/class/Heatmap.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index f7375c2a5e..c440fcfecc 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -381,7 +381,7 @@ class Heatmap } $id_grupo = ''; - if (empty($this->filter) === false && current($this->filter) != 0) { + if (empty($this->filter) === false && empty(current($this->filter)) === false) { $id_grupo = ' AND id_grupo IN ('.implode(',', $this->filter).')'; } From feff8668be741eee62a94b031f90f0defaf3a538 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 14 Mar 2023 16:49:12 +0100 Subject: [PATCH 6/7] #8642 added img --- pandora_console/images/widgets/heatmap.png | Bin 5155 -> 5436 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/pandora_console/images/widgets/heatmap.png b/pandora_console/images/widgets/heatmap.png index 413134613b5d68f89c89eeb2f661478f6e438298..f16f8eb9927d60fc3da4ae07f9584d4212cf0047 100644 GIT binary patch literal 5436 zcmaJ_by$;o`==QQ1L>4eiUQjJiP12+J4GC9l4Em>E*Yf=f*_&7knUELk`w_!lyD$Y zf^fkTmLATcf|kUkpWhO$5*kU_WlP|9Rvl)@fXc6d8uBSlvX z8jScY0}e!E&(LIK%4&gFgsT?{4{|}ddHARZZ8f(Efjp2ZLbkHTP-83{^a{t&@?sR;eoC_7^_ z5FCR;f#kqYNmnRT8YB+`OUYfmDhHJSNkgTf5U4CfN?KA%P7!)lQA!^4=Oc8c4Trp` zXrZO^r>?V;ijX@Vk5z;~0s;cS0Wx3=&J7|3gTWwBX^6D6q(o$e)keIE94-ymLd-)H5v9Y4Qk1rnKbZ_E7o+rpgp_+YE;dbe zZr(tG6NRYN&xNtD{__%d>E{3)brOP_3Rn8-2+0-L+og+sMcqO;N+R?CeSMcBo(_1J5E@myIl{Uz+(=BqrIE#3k+@k$x^;}k-9Wut@w#x+{c8z#FXq`USDjFY8_~GZ8tWX)mJwT(FJLkKZbD(o zM5>HosJY)@NniZ>XMR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v2|R-Q#+1dkq2_#DRQZ7`q#y2`LSgI# zV;(n7KYl(O8=kWi0msqb+`G)vRrYS=Ah=y>oURyzp244?Jkw6pbLabY0^J=~K6aNH z$NJ>>IS7R>I>Wa_5^=mI2kt%Ca&Q$oe$Mz{Z6a(O=j~GCkSE9QK_lI+IM$qjcu_q$ zeh(Vc($Y}<{sZWp?OXMtJ=vlmH#aMMdEy8fgg>W39LT3eyf1Y_UZ9aIm((Z6??L18 z<;xLlnIazp8RxQ8N;dojfq{u5@*O^Wn1EdQPyOdNd>_Zr0wmQqz$iC27s;|WHbaLF zrDfH_$B!RJM~=k37B?mz03wkH%FD|$rTIOmH4#rR;;qyiGA%1BL+|g~gr?l(ZJWZD z$HM5UQ8%LU@^YP{-}D@+(QRl+H4fC&V1|Y=vc0|6AurG%&To2zZmRmpYt2$s;~pee zuW?e?SRx!$O=0;iTG7BRBL3cw{u%U(wiHrSaj=Ulqz4=EcUJiy?n^-U?CfmR_@0P% ztn+67#(EKDkNNuZ0)Ep=K((Z21-r<{{` zZ#t5yXNrM6`}VA4{M2dkNb9m2Tz3FyKi_U6AMrJ-8Zo;%@F<8s35*ID$;vv zRJY$6Wi|~v2KTKs Date: Fri, 24 Mar 2023 14:11:08 +0100 Subject: [PATCH 7/7] #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;