From fb4ac30b57bf3d1c103711368f26cb4b3795730e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 9 Aug 2023 13:20:43 +0200 Subject: [PATCH] #10598 show error on create web and check --- .../include/ajax/task_to_perform.php | 12 ++++---- pandora_console/include/functions_api.php | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/ajax/task_to_perform.php b/pandora_console/include/ajax/task_to_perform.php index a8a13e08f2..53bdf0556a 100644 --- a/pandora_console/include/ajax/task_to_perform.php +++ b/pandora_console/include/ajax/task_to_perform.php @@ -65,8 +65,8 @@ if ($check_web) { __('Agent Web monitoring created on welcome'), ]; - $id_agent = api_set_new_agent(0, '', $array_other, '', true); - if ($id_agent > 0) { + $id_agent = api_set_new_agent(0, '', $array_other, '', true, true); + if (is_integer($id_agent)) { $module_name = get_parameter('module_name', 'Web_monitoring_module'); $text_to_search = get_parameter('text_to_search', ''); $url_goliat = get_parameter('url_goliat', 'https://pandorafms.com/en/'); @@ -76,7 +76,7 @@ if ($check_web) { ui_print_success_message(__('Your check has been created, click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); } } else { - ui_print_error_message(__('The Name is not valid for the modules.')); + ui_print_error_message(__($id_agent)); } } else { ui_print_error_message(__('Web server is not enabled.')); @@ -110,8 +110,8 @@ if ($check_connectivity) { __('Basic connectivity'), ]; - $id_agent = api_set_new_agent(0, '', $array_other, '', true); - if ($id_agent > 0) { + $id_agent = api_set_new_agent(0, '', $array_other, '', true, true); + if (is_integer($id_agent)) { $ip_target = get_parameter('ip_target', '127.0.0.1'); $basic_network = create_module_basic_network($id_agent, $id_group, $ip_target); $latency_network = create_module_latency_network($id_agent, $id_group, $ip_target); @@ -120,7 +120,7 @@ if ($check_connectivity) { ui_print_success_message(__('Your check has been created, click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); } } else { - ui_print_error_message(__('The Name is not valid for the modules.')); + ui_print_error_message(__($id_agent)); } } else { ui_print_error_message(__('Web server is not enabled.')); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 2a21bed3a6..7e22befbee 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1916,7 +1916,7 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params) * * @param $thrash3 Don't use. */ -function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false) +function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false, $message=false) { global $config; @@ -2009,16 +2009,40 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false) // Check if agent exists (BUG WC-50518-2). if ($alias == '' && $alias_as_name === 0) { + if ($message === true) { + return 'No agent alias specified'; + } + returnError('No agent alias specified'); } else if (agents_get_agent_id($nombre_agente)) { + if ($message === true) { + return 'The agent name already exists in DB.'; + } + returnError('The agent name already exists in DB.'); } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { + if ($message === true) { + return 'The group does not exist.'; + } + returnError('The group does not exist.'); } else if (group_allow_more_agents($grupo, true, 'create') === false) { + if ($message === true) { + return 'Agent cannot be created due to the maximum agent limit for this group'; + } + returnError('Agent cannot be created due to the maximum agent limit for this group'); } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { + if ($message === true) { + return 'The OS does not exist.'; + } + returnError('The OS does not exist.'); } else if ($server_name === false) { + if ($message === true) { + return 'The '.get_product_name().' Server does not exist.'; + } + returnError('The '.get_product_name().' Server does not exist.'); } else { if ($alias_as_name === 1) { @@ -13122,7 +13146,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) $ack_utimestamp = $val['ack_utimestamp']; $values['id_usuario'] = $val['id_usuario']; } - + api_set_validate_event_by_id($val['id_evento']); } }