From 8690aa908afa87e150ab5dfea1e15ae11e74ff0e Mon Sep 17 00:00:00 2001 From: enriquecd Date: Mon, 19 Mar 2018 10:05:29 +0100 Subject: [PATCH] Cluster monitoring 2 - #2007 --- .../godmode/agentes/modificar_agente.php | 60 +++++++++++--- .../godmode/alerts/alert_list.builder.php | 6 ++ .../godmode/alerts/alert_list.list.php | 10 ++- pandora_console/godmode/alerts/alert_list.php | 81 +++++++++++++++++++ pandora_console/include/api.php | 58 ++++++++++++- pandora_console/include/functions_api.php | 4 + .../include/functions_treeview.php | 13 ++- .../operation/agentes/estado_agente.php | 20 ++++- 8 files changed, 235 insertions(+), 17 deletions(-) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 5e2ffc3533..d65470bd21 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -495,6 +495,8 @@ if ($agents !== false) { $id_grupo = $agent["id_grupo"]; + $cluster = db_get_row_sql('select id from tcluster where id_agent = '.$agent['id_agente']); + if (! check_acl ($config["id_user"], $id_grupo, "AW", $agent['id_agente']) && ! check_acl ($config["id_user"], $id_grupo, "AD", $agent['id_agente'])) continue; @@ -564,22 +566,38 @@ if ($agents !== false) { echo ''; echo ""; @@ -628,19 +646,41 @@ if ($agents !== false) { if ($agent['disabled']) { echo "". - html_print_image('images/lightbulb_off.png', true, array('alt' => __('Enable agent'), 'title' => __('Enable agent'))) .""; + enable_agent=".$agent["id_agente"]."&group_id=$ag_group&recursion=$recursion&search=$search&offset=$offsetArg&sort_field=$sortField&sort=$sort&disabled=$disabled'"; + + if($agent["id_os"] != 21){ + echo ">"; + } + else{ + echo ' onClick="if (!confirm(\' '.__('You are going to enable a cluster agent. Are you sure?').'\')) return false;">'; + } + + echo html_print_image('images/lightbulb_off.png', true, array('alt' => __('Enable agent'), 'title' => __('Enable agent'))) .""; } else { echo "". - html_print_image('images/lightbulb.png', true, array('alt' => __('Disable agent'), 'title' => __('Disable agent'))) .""; + disable_agent=".$agent["id_agente"]."&group_id=$ag_group&recursion=$recursion&search=$search&offset=$offsetArg&sort_field=$sortField&sort=$sort&disabled=$disabled'"; + if($agent["id_os"] != 21){ + echo ">"; + } + else{ + echo ' onClick="if (!confirm(\' '.__('You are going to disable a cluster agent. Are you sure?').'\')) return false;">'; + } + + echo html_print_image('images/lightbulb.png', true, array('alt' => __('Disable agent'), 'title' => __('Disable agent'))) .""; } if (check_acl ($config["id_user"], $agent["id_grupo"], "AW")) { echo "  '; + + if($agent["id_os"] != 21){ + echo ' onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'; + } + else{ + echo ' onClick="if (!confirm(\' '.__('You are going to delete a cluster agent. Are you sure?').'\')) return false;">'; + } + echo html_print_image('images/cross.png', true, array("border" => '0')) . ""; } diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index 68f5f9b019..0440ca8350 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -141,6 +141,12 @@ echo '
'; html_print_table ($table); echo '
'; + +if($id_cluster){ + echo ""; +} + + html_print_submit_button (__('Add alert'), 'add', false, 'class="sub wand"'); html_print_input_hidden ('create_alert', 1); echo '
'; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 8a2a7c6702..da6e951c83 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -159,8 +159,14 @@ else { $form_filter .= ""; if ( defined("METACONSOLE")) echo "
"; + +if(!$id_cluster){ + ui_toggle($form_filter, __('Alert control filter'), __('Toggle filter(s)')); +} +else{ + unset($form_filter); +} -ui_toggle($form_filter, __('Alert control filter'), __('Toggle filter(s)')); $simple_alerts = array(); @@ -737,7 +743,7 @@ if (isset($dont_display_alert_create_bttn)) if ($dont_display_alert_create_bttn) $display_create = false; -if ($display_create && (check_acl ($config['id_user'], 0, "LW") || check_acl ($config['id_user'], $template_group, "LM"))) { +if ($display_create && (check_acl ($config['id_user'], 0, "LW") || check_acl ($config['id_user'], $template_group, "LM")) && !$id_cluster) { echo '
'; echo '
'; html_print_submit_button (__('Create'), 'crtbtn', false, 'class="sub next"'); diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index a56ed8bcac..fd610b5371 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -143,6 +143,20 @@ if ($delete_alert) { $messageAction = ui_print_result_message ($result, __('Successfully deleted'), __('Could not be deleted'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_delete_alert='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_delete_alert='.$result); + } + + } + } if ($add_action) { @@ -211,6 +225,20 @@ if ($delete_action) { $messageAction = ui_print_result_message ($result, __('Successfully deleted'), __('Could not be deleted'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_delete_action='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_delete_action='.$result); + } + + } + } if ($enable_alert) { @@ -228,6 +256,19 @@ if ($enable_alert) { $messageAction = ui_print_result_message ($result, __('Successfully enabled'), __('Could not be enabled'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_enable_alert='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_enable_alert='.$result); + } + + } } if ($disable_alert) { @@ -245,6 +286,20 @@ if ($disable_alert) { $messageAction = ui_print_result_message ($result, __('Successfully disabled'), __('Could not be disabled'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_disable_alert='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_disable_alert='.$result); + } + + } + } if ($standbyon_alert) { @@ -262,6 +317,19 @@ if ($standbyon_alert) { $messageAction = ui_print_result_message ($result, __('Successfully set standby'), __('Could not be set standby'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_standbyon='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_standbyon='.$result); + } + + } } if ($standbyoff_alert) { @@ -279,6 +347,19 @@ if ($standbyoff_alert) { $messageAction = ui_print_result_message ($result, __('Successfully set off standby'), __('Could not be set off standby'), '', true); + + $id_cluster = db_get_all_rows_sql('select id,cluster_type from tcluster where id_agent = '.$id_agente); + + if($id_cluster){ + + if($id_cluster[0]['cluster_type'] == 'AA'){ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=5&update=1&message_standbyoff='.$result); + } + else{ + header('Location: index.php?sec=reporting&sec2=enterprise/godmode/reporting/cluster_builder&id_cluster='.$id_cluster[0]['id'].'&step=7&update=1&message_standbyoff='.$result); + } + + } } if ($id_agente) { diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index e79e05bbb7..991630d8d3 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -105,8 +105,64 @@ if ($correctLogin) { } else { $function_name = 'api_' . $op . '_' . $op2; + + if ($op == "set" && $id){ + switch ($op2) { + case "update_agent": + + case "add_module_in_conf": + case "update_module_in_conf": + case "delete_module_in_conf": + + $id_os = db_get_value_sql('select id_os from tagente where id_agente = '.$id); + + if($id_os == 21){ + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + + break; + + case "create_network_module": + case "create_plugin_module": + case "create_data_module": + case "create_synthetic_module": + case "create_snmp_module": + case "delete_module": + case "delete_agent": + + $id_os = db_get_value_sql('select id_os from tagente where nombre = "'.$id.'"'); + + html_debug($id_os); + + if($id_os == 21){ + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + + break; + + case "update_network_module": + case "update_plugin_module": + case "update_data_module": + case "update_snmp_module": + + $id_os = db_get_value_sql('select id_os from tagente where id_agente = (select id_agente from tagente_modulo where id_agente_modulo ='.$id.')'); + + if($id_os == 21){ + returnError('not_allowed_operation_cluster', $returnType); + return false; + } + + break; + + default: + + // break; + } + } } - + // Check if the function exists if (function_exists($function_name)) { if (!DEBUG) { diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index c3fbfef69b..4e5e2cfab0 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -85,6 +85,10 @@ function returnError($typeError, $returnType = 'string') { returnData($returnType, array('type' => 'string', 'data' => __('Id does not exist in BD.'))); break; + case 'not_allowed_operation_cluster': + returnData($returnType, + array('type' => 'string', 'data' => __('This operation can not be used in cluster elements.'))); + break; default: returnData("string", array('type' => 'string', 'data' => __($returnType))); diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 9da64a6dbe..d41eb740a5 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -622,8 +622,17 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals if ( $user_access_node && check_acl ($config["id_user"], $agent["id_grupo"], "AW")) { $go_to_agent = '
'; - $go_to_agent .= ''; - $go_to_agent .= html_print_submit_button (__('Go to agent edition'), 'upd_button', false, 'class="sub config"', true); + + if($agent["id_os"] != 21){ + $go_to_agent .= ''; + $go_to_agent .= html_print_submit_button (__('Go to agent edition'), 'upd_button', false, 'class="sub config"', true); + } + else{ + $cluster = db_get_row_sql('select id from tcluster where id_agent = '.$id_agente); + $go_to_agent .= ''; + $go_to_agent .= html_print_submit_button (__('Edit cluster'), 'upd_button', false, 'class="sub config"', true); + } + $go_to_agent .= ''; $go_to_agent .= '
'; diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index d272c5e2f4..f562d0cea9 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -599,6 +599,9 @@ $table->data = array (); $rowPair = true; $iterator = 0; foreach ($agents as $agent) { + + $cluster = db_get_row_sql('select id from tcluster where id_agent = '.$agent['id_agente']); + if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else @@ -637,11 +640,24 @@ foreach ($agents as $agent) { } $data[0] .= '
';