From fd368aec862b371e3135f3ac81c53647a8d00610 Mon Sep 17 00:00:00 2001 From: enriquecd Date: Tue, 12 Jun 2018 12:08:57 +0200 Subject: [PATCH] Add mode 1 and empty ip on create agent by API new_cluster, and get cluster items by API - #2294 --- pandora_console/include/functions_api.php | 39 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 309bb9b215..a87de34dd7 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -10845,6 +10845,13 @@ function api_set_new_cluster($thrash1, $thrash2, $other, $thrash3) { returnError('forbidden', 'string'); return; } + + $name_exist = db_process_sql('select count(name) as already_exist from tcluster as already_exist where name = "'.$name.'"'); + + if($name_exist[0]['already_exist'] > 0){ + returnError('error_set_new_cluster', __('A cluster with this name already exists.')); + return false; + } $server_name = db_process_sql('select name from tserver where server_type=5 limit 1'); @@ -10856,11 +10863,12 @@ function api_set_new_cluster($thrash1, $thrash2, $other, $thrash3) { 'comentarios' => $description, 'id_grupo' => $idGroup, 'id_os' => 100, - 'server_name' => $server_name_agent + 'server_name' => $server_name_agent, + 'modo' => 1 ); if (trim($name) != "") { - $id_agent = agents_create_agent($values_agent['nombre'],$values_agent['id_grupo'],300,'127.0.0.1',$values_agent); + $id_agent = agents_create_agent($values_agent['nombre'],$values_agent['id_grupo'],300,'',$values_agent); // Create cluster $values_cluster = array( @@ -11363,7 +11371,8 @@ function api_get_cluster_id_by_name($cluster_name, $trash1, $trash2, $returnType returnError('id_not_found', $returnType); } - $cluster_group = clusters_get_group($id_cluster); + $cluster_group = clusters_get_group($value); + if(!$cluster_group || !check_acl($config['id_user'], $cluster_group, "AR")){ returnError('error_get_cluster_status', __('The user cannot access to the cluster')); return; @@ -11382,7 +11391,7 @@ function api_get_agents_id_name_by_cluster_id($cluster_id, $trash1, $trash2, $re $all_agents = cluster_get_agents_id_name_by_cluster_id($cluster_id); if (count($all_agents) > 0 and $all_agents !== false) { - $data = array('type' => 'array', 'data' => $all_agents); + $data = array('type' => 'json', 'data' => $all_agents); returnData('json', $data); } @@ -11399,7 +11408,7 @@ function api_get_agents_id_name_by_cluster_name($cluster_name, $trash1, $trash2, $all_agents = cluster_get_agents_id_name_by_cluster_name($cluster_name); if (count($all_agents) > 0 and $all_agents !== false) { - $data = array('type' => 'array', 'data' => $all_agents); + $data = array('type' => 'json', 'data' => $all_agents); returnData('json', $data); } @@ -11416,7 +11425,7 @@ function api_get_modules_id_name_by_cluster_id ($cluster_id){ $all_modules = cluster_get_modules_id_name_by_cluster_id($cluster_id); if (count($all_modules) > 0 and $all_modules !== false) { - $data = array('type' => 'array', 'data' => $all_modules); + $data = array('type' => 'json', 'data' => $all_modules); returnData('json', $data); } @@ -11431,10 +11440,10 @@ function api_get_modules_id_name_by_cluster_name ($cluster_name){ return; } - $all_modules = cluster_get_modules_id_name_by_cluster_name($cluster_name); + $all_modules = cluster_get_modules_id_name_by_cluster_name($cluster_name); if (count($all_modules) > 0 and $all_modules !== false) { - $data = array('type' => 'array', 'data' => $all_modules); + $data = array('type' => 'json', 'data' => $all_modules); returnData('json', $data); } @@ -11463,6 +11472,20 @@ function util_api_check_agent_and_print_error($id_agent, $returnType, $access = return false; } +function api_get_cluster_items ($cluster_id){ + + $all_items = cluster_get_items($cluster_id); + + if (count($all_items) > 0 and $all_items !== false) { + $data = array('type' => 'json', 'data' => $all_items); + + returnData('json', $data); + } + else { + returnError('error_cluster_items', 'No items retrieved.'); + } +} + ?> \ No newline at end of file