From db89c72be577bf4fcae03d7c717e6f337c9256cb Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 29 Nov 2023 16:00:46 +0100 Subject: [PATCH 1/2] fix error empty clusters pandora_enterprise#12511 --- .../godmode/agentes/agent_manager.php | 27 +++++++++++++++-- pandora_console/include/functions_agents.php | 29 +++++++++++++++++-- pandora_console/include/lib/Cluster.php | 4 +++ pandora_console/views/cluster/view.php | 6 +++- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 557b855e09..a7f979180a 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -1104,11 +1104,24 @@ if ($new_agent === false) { $actionButtons .= html_print_input_hidden('id_agente', $id_agente); if (is_management_allowed() === true) { + $clusters = agents_get_agent_belongs_cluster($id_agente); + $cluster_belongs = ''; + if (empty($clusters) === false) { + $clusters = array_reduce( + $clusters, + function ($carry, $item) { + $carry[] = $item['name']; + return $carry; + } + ); + $cluster_belongs = implode(', ', $clusters); + } + $actionButtons .= html_print_button( __('Delete agent'), 'deleteAgent', false, - 'deleteAgentDialog('.$id_agente.')', + 'deleteAgentDialog('.$id_agente.', "'.$cluster_belongs.'")', [ 'icon' => 'delete', 'mode' => 'secondary dialog_opener', @@ -1156,10 +1169,18 @@ ui_require_jquery_file('bgiframe'); } } - function deleteAgentDialog($idAgente) { + function deleteAgentDialog($idAgente, cluster) { + var msg_cluster = ''; + if(cluster) { + msg_cluster = ""; + msg_cluster += ': '; + msg_cluster += cluster; + msg_cluster += '. '; + } + confirmDialog({ title: "", - message: "", + message: msg_cluster + "", onAccept: function() { window.location.assign('index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&borrar_agente='+$idAgente); } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2d6803ccd4..32dc0a9312 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -4976,13 +4976,38 @@ function get_resume_agent_concat($id_agente, $all_groups, $agent) } +/** + * agent belongs to the clusters. + * + * @param integer $idAgent + * + * @return array Names clusters. + */ +function agents_get_agent_belongs_cluster(int $idAgent): array +{ + $sql = sprintf( + 'SELECT tcluster.name + FROM tcluster + INNER JOIN tcluster_agent + ON tcluster.id = tcluster_agent.id_cluster + WHERE tcluster_agent.id_agent = %d', + $idAgent + ); + + $result = db_get_all_rows_sql($sql); + if ($result === false) { + $result = []; + } + + return $result; +} + + /** * Return an array with a list of status agents * * @return array. */ - - function agents_status_list() { $status_list = []; diff --git a/pandora_console/include/lib/Cluster.php b/pandora_console/include/lib/Cluster.php index b7bd21d929..46e7ba4324 100644 --- a/pandora_console/include/lib/Cluster.php +++ b/pandora_console/include/lib/Cluster.php @@ -213,6 +213,10 @@ class Cluster extends Entity public function getCounters() :array { $id_agent_modules = $this->getIdsModulesInvolved(); + if (empty($id_agent_modules) === true) { + return []; + } + $sql = sprintf( 'SELECT SUM( IF(estado = 1, 1, 0) ) AS critical, SUM( IF(estado = 2, 1, 0) ) AS warning, diff --git a/pandora_console/views/cluster/view.php b/pandora_console/views/cluster/view.php index 32bcdb0736..93894ba7e5 100644 --- a/pandora_console/views/cluster/view.php +++ b/pandora_console/views/cluster/view.php @@ -151,7 +151,11 @@ $agentCountModules = html_print_div( true ); -$alive_animation = agents_get_starmap(0, 180, 30, $module_involved_ids); +$alive_animation = ''; +if (empty($module_involved_ids) === false) { + $alive_animation = agents_get_starmap(0, 180, 30, $module_involved_ids); +} + $output = '
'; $output .= '
'; From 7df7fdff7da53afc2235230b72768b4757a46c25 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 13 Dec 2023 10:32:29 +0100 Subject: [PATCH 2/2] fix msg error agent cluster pandora_enterprise#12511 --- .../godmode/agentes/modificar_agente.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 5ea31914c6..a7ee6bf4c0 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -958,12 +958,33 @@ if ($agents !== false) { ); if ($check_aw === true && is_management_allowed() === true) { - if ($agent['id_os'] != CLUSTER_OS_ID) { - $onClickActionDeleteAgent = 'if (!confirm(\' '.__('Are you sure?').'\')) return false;'; - } else { - $onClickActionDeleteAgent = 'if (!confirm(\' '.__('WARNING! - You are going to delete a cluster agent. Are you sure?').'\')) return false;'; + $clusters = agents_get_agent_belongs_cluster($agent['id_agente']); + $cluster_belongs = ''; + if (empty($clusters) === false) { + $clusters = array_reduce( + $clusters, + function ($carry, $item) { + $carry[] = $item['name']; + return $carry; + } + ); + $cluster_belongs = implode(', ', $clusters); } + $msg = ''; + if ($agent['id_os'] == CLUSTER_OS_ID) { + $msg .= __('You are going to delete a cluster agent'); + $msg .= '. '; + } else if (empty($cluster_belongs) === false) { + $msg .= __('This agent belongs to the clusters'); + $msg .= ': '; + $msg .= $cluster_belongs; + $msg .= '. '; + } + + $msg .= __('Are you sure?'); + $onClickActionDeleteAgent = 'if (!confirm(\' '.$msg.'\')) return false;'; + $agentActionButtons[] = html_print_menu_button( [ 'href' => ui_get_full_url(