From 13f0e3db2336463088f34a68c074475883052d25 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 9 May 2023 16:45:44 +0200 Subject: [PATCH 1/4] #10362 recursive group visual console --- pandora_console/extras/mr/65.sql | 6 + .../models/VisualConsole/Items/Group.php | 267 ++++++++++++++---- .../rest-api/models/VisualConsole/View.php | 4 + pandora_console/pandoradb.sql | 1 + 4 files changed, 224 insertions(+), 54 deletions(-) create mode 100644 pandora_console/extras/mr/65.sql diff --git a/pandora_console/extras/mr/65.sql b/pandora_console/extras/mr/65.sql new file mode 100644 index 0000000000..4b2ee3ddbf --- /dev/null +++ b/pandora_console/extras/mr/65.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE `tlayout_data` +ADD COLUMN `recursive_group` TINYINT NOT NULL DEFAULT '0' AFTER `fill_color`; + +COMMIT; diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php index 50fca70543..e2e9064a22 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php @@ -34,6 +34,25 @@ final class Group extends Item protected static $indexCacheByUser = true; + /** + * Get the "recursive Group" switch value. + * + * @param array $data Unknown input data structure. + * + * @return mixed If the recursive should be true or not. + */ + private static function getRecursiveGroup(array $data) + { + return static::issetInArray( + $data, + [ + 'recursiveGroup', + 'recursive_group', + ] + ); + } + + /** * Get the "show statistics" switch value. * @@ -87,6 +106,11 @@ final class Group extends Item $return['id_group'] = $id_group; } + $recursive_group = static::getRecursiveGroup($data); + if ($recursive_group !== null) { + $return['recursive_group'] = static::parseBool($recursive_group); + } + $show_statistics = static::getShowStatistics($data); if ($show_statistics !== null) { $return['show_statistics'] = static::parseBool($show_statistics); @@ -112,6 +136,7 @@ final class Group extends Item $return['groupId'] = static::extractGroupId($data); $return['imageSrc'] = static::extractImageSrc($data); $return['statusImageSrc'] = static::extractStatusImageSrc($data); + $return['recursiveGroup'] = static::extractRecursiveGroup($data); $return['showStatistics'] = static::extractShowStatistics($data); return $return; @@ -177,6 +202,21 @@ final class Group extends Item } + /** + * Extract the "show statistics" switch value. + * + * @param array $data Unknown input data structure. + * + * @return boolean If the statistics should be shown or not. + */ + private static function extractRecursiveGroup(array $data): bool + { + return static::parseBool( + static::issetInArray($data, ['recursiveGroup', 'recursive_group']) + ); + } + + /** * Extract the "show statistics" switch value. * @@ -227,63 +267,147 @@ final class Group extends Item } $groupId = static::extractGroupId($data); + $recursiveGroup = static::extractrecursiveGroup($data); $showStatistics = static::extractShowStatistics($data); if ($showStatistics === true) { $isMetaconsole = \is_metaconsole(); + if ($recursiveGroup) { + $childers_id = groups_get_children_ids($groupId); + } + // Retrieve the agent stats. - $agentsCritical = \agents_get_agents( - [ - 'id_grupo' => $groupId, - 'status' => AGENT_STATUS_CRITICAL, - ], - ['COUNT(*) AS total'], - 'AR', - false, - false, - true, - $isMetaconsole - ); - $numCritical = $agentsCritical[0]['total']; - $agentsWarning = \agents_get_agents( - [ - 'id_grupo' => $groupId, - 'status' => AGENT_STATUS_WARNING, - ], - ['COUNT(*) AS total'], - 'AR', - false, - false, - true, - $isMetaconsole - ); - $numWarning = $agentsWarning[0]['total']; - $agentsUnknown = \agents_get_agents( - [ - 'id_grupo' => $groupId, - 'status' => AGENT_STATUS_UNKNOWN, - ], - ['COUNT(*) AS total'], - 'AR', - false, - false, - true, - $isMetaconsole - ); - $numUnknown = $agentsUnknown[0]['total']; - $agentsOk = \agents_get_agents( - [ - 'id_grupo' => $groupId, - 'status' => AGENT_STATUS_NORMAL, - ], - ['COUNT(*) AS total'], - 'AR', - false, - false, - true, - $isMetaconsole - ); - $numNormal = $agentsOk[0]['total']; + if ($recursiveGroup) { + $numCritical = 0; + foreach ($childers_id as $id_group) { + $agentsCritical = \agents_get_agents( + [ + 'id_grupo' => $id_group, + 'status' => AGENT_STATUS_CRITICAL, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numCritical += $agentsCritical[0]['total']; + } + } else { + $agentsCritical = \agents_get_agents( + [ + 'id_grupo' => $groupId, + 'status' => AGENT_STATUS_CRITICAL, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numCritical = $agentsCritical[0]['total']; + } + + if ($recursiveGroup) { + $numWarning = 0; + foreach ($childers_id as $id_group) { + $agentsWarning = \agents_get_agents( + [ + 'id_grupo' => $id_group, + 'status' => AGENT_STATUS_WARNING, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numWarning += $agentsWarning[0]['total']; + } + } else { + $agentsWarning = \agents_get_agents( + [ + 'id_grupo' => $groupId, + 'status' => AGENT_STATUS_WARNING, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numWarning = $agentsWarning[0]['total']; + } + + if ($recursiveGroup) { + $numUnknown = 0; + foreach ($childers_id as $id_group) { + $agentsUnknown = \agents_get_agents( + [ + 'id_grupo' => $id_group, + 'status' => AGENT_STATUS_UNKNOWN, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numUnknown += $agentsUnknown[0]['total']; + } + } else { + $agentsUnknown = \agents_get_agents( + [ + 'id_grupo' => $groupId, + 'status' => AGENT_STATUS_UNKNOWN, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numUnknown = $agentsUnknown[0]['total']; + } + + if ($recursiveGroup) { + $numNormal = 0; + foreach ($childers_id as $id_group) { + $agentsOk = \agents_get_agents( + [ + 'id_grupo' => $id_group, + 'status' => AGENT_STATUS_NORMAL, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numNormal += $agentsOk[0]['total']; + } + } else { + $agentsOk = \agents_get_agents( + [ + 'id_grupo' => $groupId, + 'status' => AGENT_STATUS_NORMAL, + ], + ['COUNT(*) AS total'], + 'AR', + false, + false, + true, + $isMetaconsole + ); + $numNormal = $agentsOk[0]['total']; + } $numTotal = ($numCritical + $numWarning + $numUnknown + $numNormal); @@ -327,6 +451,11 @@ final class Group extends Item ',', array_keys(\users_get_groups()) ); + + if ($recursiveGroup === true) { + $childers_id = groups_get_children_ids($groupId); + $groupFilter .= ','.implode(',', $childers_id); + } } $sql = sprintf( @@ -356,8 +485,25 @@ final class Group extends Item $status = AGENT_STATUS_NORMAL; } } else { - // Get the status img src. - $status = \groups_get_status($groupId, true); + if ($recursiveGroup === true) { + $childers_id = groups_get_children_ids($groupId); + $flag_stop_foreach = false; + foreach ($childers_id as $id_children) { + if ($flag_stop_foreach === true) { + // Stop if some child is not normal. + break; + } + + // Get the status img src from all modules childs. + $status = \groups_get_status($id_children, true); + if ($status !== AGENT_STATUS_NORMAL) { + $flag_stop_foreach = true; + } + } + } else { + // Get the status img src. + $status = \groups_get_status($groupId, true); + } } $imagePath = \visual_map_get_image_status_element($data, $status); @@ -559,6 +705,19 @@ final class Group extends Item ], ]; + if ((int) $values['type'] === GROUP_ITEM) { + // Recursive group. + $inputs[] = [ + 'label' => __('Recursive'), + 'arguments' => [ + 'name' => 'recursiveGroup', + 'id' => 'recursiveGroup', + 'type' => 'switch', + 'value' => $values['recursiveGroup'], + ], + ]; + } + // Show statistics. $inputs[] = [ 'label' => __('Show statistics'), diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php index f63ee9231c..f3079e8c0e 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/View.php +++ b/pandora_console/include/rest-api/models/VisualConsole/View.php @@ -379,6 +379,10 @@ class View extends \HTML case GROUP_ITEM: $data['imageSrc'] = \get_parameter('imageSrc'); + $data['recursiveGroup'] = \get_parameter_switch( + 'recursiveGroup', + 0 + ); $data['showStatistics'] = \get_parameter_switch( 'showStatistics', 0 diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index e868f73d6d..38ce21bc71 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1726,6 +1726,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_data` ( `label_position` VARCHAR(50) NOT NULL DEFAULT 'down', `border_color` VARCHAR(200) DEFAULT '', `fill_color` VARCHAR(200) DEFAULT '', + `recursive_group` TINYINT NOT NULL DEFAULT 0, `show_statistics` TINYINT NOT NULL DEFAULT 0, `linked_layout_node_id` INT NOT NULL DEFAULT 0, `linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default', From 1ba6566cff9265903cd00b209c26bd7795e51ef0 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 9 May 2023 16:52:30 +0200 Subject: [PATCH 2/4] #10362 token recursive group VC default 1 --- .../include/rest-api/models/VisualConsole/Items/Group.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php index e2e9064a22..f27d1ecda0 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Group.php @@ -706,6 +706,10 @@ final class Group extends Item ]; if ((int) $values['type'] === GROUP_ITEM) { + if (isset($values['recursiveGroup']) === false) { + $values['recursiveGroup'] = true; + } + // Recursive group. $inputs[] = [ 'label' => __('Recursive'), From e87da5e1e5fffdb0f336089c9dd6abc702ecc078 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 17 May 2023 08:09:26 +0200 Subject: [PATCH 3/4] #10362 change MR after change Milestone --- pandora_console/extras/mr/64.sql | 3 +++ pandora_console/extras/mr/65.sql | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 pandora_console/extras/mr/65.sql diff --git a/pandora_console/extras/mr/64.sql b/pandora_console/extras/mr/64.sql index e4e42cc516..5f9ef08e05 100644 --- a/pandora_console/extras/mr/64.sql +++ b/pandora_console/extras/mr/64.sql @@ -4,4 +4,7 @@ UPDATE pandora.tnetwork_component SET module_enabled=1 WHERE name='Cisco _nameOID_ power state'; +ALTER TABLE `tlayout_data` +ADD COLUMN `recursive_group` TINYINT NOT NULL DEFAULT '0' AFTER `fill_color`; + COMMIT; diff --git a/pandora_console/extras/mr/65.sql b/pandora_console/extras/mr/65.sql deleted file mode 100644 index 4b2ee3ddbf..0000000000 --- a/pandora_console/extras/mr/65.sql +++ /dev/null @@ -1,6 +0,0 @@ -START TRANSACTION; - -ALTER TABLE `tlayout_data` -ADD COLUMN `recursive_group` TINYINT NOT NULL DEFAULT '0' AFTER `fill_color`; - -COMMIT; From 7b414c6b69b2044618fee0cd88289bdb4b00a950 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 17 May 2023 09:39:35 +0200 Subject: [PATCH 4/4] #10362 change MR 64 correction ticket #11109 --- pandora_console/extras/mr/64.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/64.sql b/pandora_console/extras/mr/64.sql index 5f9ef08e05..9408ab3ca5 100644 --- a/pandora_console/extras/mr/64.sql +++ b/pandora_console/extras/mr/64.sql @@ -1,6 +1,6 @@ START TRANSACTION; -UPDATE pandora.tnetwork_component +UPDATE `tnetwork_component` SET module_enabled=1 WHERE name='Cisco _nameOID_ power state';