diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 3f84835bb3..5aa1020214 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -6009,14 +6009,12 @@ function api_set_delete_module_template_by_names($id, $id2, $other, $trash1) $result = db_process_sql_delete('talert_template_modules', $values); - $delete_count++; - if ($result != 0) { $delete_count++; } } - returnError('error_delete_module_template_by_name', __('Module template have been deleted in %d agents.', $delete_count)); + returnError('error_delete_module_template_by_name', __('Module template has been deleted in %d agents.', $delete_count)); } else { $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); @@ -8999,67 +8997,41 @@ function api_set_delete_module($id, $id2, $other, $trash1) return; } - if ($other['type'] == 'string') { - $simulate = false; - if ($other['data'][0] == 'simulate') { - $simulate = true; - } + $simulate = false; + if ($other['data'][0] == 'simulate') { + $simulate = true; + } - $agent_by_alias = false; + $agent_by_alias = false; - if ($other['data'][1] === '1') { - $agent_by_alias = true; - } + if ($other['data'][1] === '1') { + $agent_by_alias = true; + } - if ($agent_by_alias) { - $idsAgents = agents_get_agent_id_by_alias($id); - } else { - $idAgent = agents_get_agent_id($id); - } + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } - if ($agent_by_alias) { - foreach ($idsAgents as $id) { - if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { - return; - } - } - } else { - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { return; } } - - if ($agent_by_alias) { - foreach ($idsAgents as $id) { - $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $id2]); - - if ($idAgentModule === false) { - continue; - } - - if (!$simulate) { - $return = modules_delete_agent_module($idAgentModule); - } else { - $return = true; - } - - $data['type'] = 'string'; - if ($return === false) { - $data['data'] = 0; - } else { - $data['data'] = $return; - } - - returnData('string', $data); - } - + } else { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { return; - } else { - $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $id2]); + } + } + + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $id2]); if ($idAgentModule === false) { - returnError('error_parameter', 'Error in the parameters.'); - return; + continue; } if (!$simulate) { @@ -9076,10 +9048,31 @@ function api_set_delete_module($id, $id2, $other, $trash1) } returnData('string', $data); + } + + return; + } else { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $id2]); + + if ($idAgentModule === false) { + returnError('error_parameter', 'Error in the parameters.'); return; } - } else { - returnError('error_parameter', 'Error in the parameters.'); + + if (!$simulate) { + $return = modules_delete_agent_module($idAgentModule); + } else { + $return = true; + } + + $data['type'] = 'string'; + if ($return === false) { + $data['data'] = 0; + } else { + $data['data'] = $return; + } + + returnData('string', $data); return; } } diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 33a16dabd6..628461a83c 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -104,8 +104,8 @@ sub help_screen{ print "Available options for $param:\n\n" unless $param eq ''; print "AGENTS:\n\n" unless $param ne ''; help_screen_line('--create_agent', " \n\t [
]", 'Create agent'); - help_screen_line('--update_agent', ' ', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id"); - help_screen_line('--delete_agent', '', 'Delete agent'); + help_screen_line('--update_agent', ' []', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id"); + help_screen_line('--delete_agent', ' []', 'Delete agent'); help_screen_line('--disable_group', '', 'Disable agents from an entire group'); help_screen_line('--enable_group', '', 'Enable agents from an entire group'); help_screen_line('--create_group', ' [ ]', 'Create an agent group'); @@ -118,14 +118,14 @@ sub help_screen{ help_screen_line('--get_planned_downtimes_items', ' [ ]', 'Get all items of planned downtimes'); help_screen_line('--set_planned_downtimes_deleted', ' ', 'Deleted a planned downtime'); help_screen_line('--get_module_id', ' ', 'Get the id of an module'); - help_screen_line('--get_agent_group', '', 'Get the group name of an agent'); - help_screen_line('--get_agent_group_id', '', 'Get the group ID of an agent'); - help_screen_line('--get_agent_modules', '', 'Get the modules of an agent'); - help_screen_line('--get_agents', '[ ]', "Get \n\t list of agents with optative filter parameters"); - help_screen_line('--delete_conf_file', '', 'Delete a local conf of a given agent'); - help_screen_line('--clean_conf_file', '', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments"); + help_screen_line('--get_agent_group', ' []', 'Get the group name of an agent'); + help_screen_line('--get_agent_group_id', ' []', 'Get the group ID of an agent'); + help_screen_line('--get_agent_modules', ' []', 'Get the modules of an agent'); + help_screen_line('--get_agents', '[ ]', "Get \n\t list of agents with optative filter parameters"); + help_screen_line('--delete_conf_file', ' []', 'Delete a local conf of a given agent'); + help_screen_line('--clean_conf_file', ' []', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments"); help_screen_line('--get_bad_conf_files', '', 'Get the files bad configured (without essential tokens)'); - help_screen_line('--locate_agent', '', 'Search a agent into of nodes of metaconsole. Only Enterprise.'); + help_screen_line('--locate_agent', ' []', 'Search a agent into of nodes of metaconsole. Only Enterprise.'); help_screen_line('--migration_agent_queue', ' []', 'Migrate agent only metaconsole'); help_screen_line('--migration_agent', ' ', 'Is migrating the agent only metaconsole'); help_screen_line('--apply_module_template', ' ', 'Apply module template to agent'); @@ -139,29 +139,29 @@ sub help_screen{ help_screen_line('--set_disabled_and_standby', ' ', 'Overwrite and disable and standby status'); help_screen_line('--reset_agent_counts', '', 'Resets module counts and alert counts in the agents'); print "\nMODULES:\n\n" unless $param ne ''; - help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); - help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); - help_screen_line('--create_network_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ]", 'Add not snmp network module to agent'); - help_screen_line('--create_snmp_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t + help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); + help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); + help_screen_line('--create_network_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ]", 'Add not snmp network module to agent'); + help_screen_line('--create_snmp_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ] \n\t \n\t ]", 'Add snmp network module to agent'); - help_screen_line('--create_plugin_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Add plug-in module to agent'); + help_screen_line('--create_plugin_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Add plug-in module to agent'); help_screen_line('--get_module_group', '[]', 'Dysplay all module groups'); help_screen_line('--create_module_group', ''); help_screen_line('--module_group_synch', " []", 'Synchronize metaconsole module groups'); - help_screen_line('--delete_module', 'Delete module from agent', ' '); - help_screen_line('--data_module', " \n\t []", 'Insert data to module'); - help_screen_line('--get_module_data', " []", "\n\t Show the data of a module in the last X seconds (interval) in CSV format"); - help_screen_line('--delete_data', '-m | -a | -g ', "Delete historic \n\t data of a module, the modules of an agent or the modules of the agents of a group"); - help_screen_line('--update_module', ' ', 'Update a module field'); + help_screen_line('--delete_module', 'Delete module from agent', ' []'); + help_screen_line('--data_module', " \n\t [ ]", 'Insert data to module'); + help_screen_line('--get_module_data', " [ ]", "\n\t Show the data of a module in the last X seconds (interval) in CSV format"); + help_screen_line('--delete_data', '-m | -a | -g []', "Delete historic \n\t data of a module, the modules of an agent or the modules of the agents of a group"); + help_screen_line('--update_module', ' []', 'Update a module field'); help_screen_line('--get_agents_module_current_data', '', "Get the agent and current data \n\t of all the modules with a given name"); - help_screen_line('--create_network_module_from_component', ' ', "Create a new network \n\t module from a network component"); + help_screen_line('--create_network_module_from_component', ' []', "Create a new network \n\t module from a network component"); help_screen_line('--create_network_component', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", "Create a new network component"); - help_screen_line('--create_synthetic', " ,,|, \n\t [ , | ,, ]", "Create a new Synthetic module"); + help_screen_line('--create_synthetic', " ,,|, \n\t [ , | ,, ]", "Create a new Synthetic module"); print "\nALERTS:\n\n" unless $param ne ''; - help_screen_line('--create_template_module', ' ', 'Add alert template to module'); - help_screen_line('--delete_template_module', ' ', 'Delete alert template from module'); - help_screen_line('--create_template_action', " \n\t [ ]', 'Add alert action to module-template"); - help_screen_line('--delete_template_action', " \n\t ", 'Delete alert action from module-template'); + help_screen_line('--create_template_module', ' []', 'Add alert template to module'); + help_screen_line('--delete_template_module', ' []', 'Delete alert template from module'); + help_screen_line('--create_template_action', " \n\t [ ]', 'Add alert action to module-template"); + help_screen_line('--delete_template_action', " \n\t []", 'Delete alert action from module-template'); help_screen_line('--disable_alerts', '', 'Disable alerts in all groups (system wide)'); help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)'); help_screen_line('--create_alert_template', " \n\t [ \n\t \n\t \n\t ]", 'Create alert template'); @@ -175,7 +175,7 @@ sub help_screen{ help_screen_line('--create_special_day', " ", 'Create special day'); help_screen_line('--delete_special_day', '', 'Delete special day'); help_screen_line('--update_special_day', " ", 'Update a field of a special day'); - help_screen_line('--create_data_module_from_local_component', ' ', "Create a new data \n\t module from a local component"); + help_screen_line('--create_data_module_from_local_component', ' []', "Create a new data \n\t module from a local component"); help_screen_line('--create_local_component', " [ \n\t \n\t \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Create local component'); print "\nUSERS:\n\n" unless $param ne ''; @@ -193,17 +193,17 @@ sub help_screen{ help_screen_line('--disable_double_auth', '', 'Disable the double authentication for the specified user'); help_screen_line('--meta_synch_user', " [ \n\t ]", 'Synchronize metaconsole users'); print "\nEVENTS:\n\n" unless $param ne ''; - help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); - help_screen_line('--validate_event', " \n\t ", 'Validate events'); - help_screen_line('--validate_event_id', '', 'Validate event given a event id'); - help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); - help_screen_line('--add_event_comment', ' ', 'Add event\'s comment'); + help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); + help_screen_line('--validate_event', " \n\t []", 'Validate events'); + help_screen_line('--validate_event_id', '', 'Validate event given a event id'); + help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); + help_screen_line('--add_event_comment', ' ', 'Add event\'s comment'); print "\nINCIDENTS:\n\n" unless $param ne ''; help_screen_line('--create_incident', " <description> <origin> <status> <priority 0 for Informative, \n\t 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance>\n\t <group> [<owner>]", 'Create incidents'); print "\nPOLICIES:\n\n" unless $param ne ''; help_screen_line('--apply_policy', '<id_policy> [<id_agent> <name(boolean)> <id_server>]', 'Force apply a policy in an agent'); help_screen_line('--apply_all_policies', '', 'Force apply to all the policies'); - help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy'); + help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name> [<use_alias>]', 'Add an agent to a policy'); help_screen_line('--remove_agent_from_policy', '<policy_id> <agent_id>', 'Delete an agent to a policy'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy'); @@ -218,7 +218,7 @@ sub help_screen{ help_screen_line('--add_collection_to_policy', "<policy_name> <collection_name>"); help_screen_line('--validate_policy_alerts', '<policy_name>', 'Validate the alerts of a given policy'); help_screen_line('--get_policy_modules', '<policy_name>', 'Get the modules of a policy'); - help_screen_line('--get_policies', '[<agent_name>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)"); + help_screen_line('--get_policies', '[<agent_name> <use_alias>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)"); help_screen_line('--recreate_collection', '<collection_id>', 'Recreate the files of a collection'); print "\nNETFLOW:\n\n" unless $param ne ''; @@ -2684,6 +2684,7 @@ sub cli_create_template_module() { exist_check($id_agent,'agent',$agent_name); my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); if ($module_id == -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; next; } @@ -2726,6 +2727,7 @@ sub cli_delete_template_module() { exist_check($id_agent,'agent',$agent_name); my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; next; } my $template_id = get_template_id($dbh,$template_name); @@ -2773,6 +2775,7 @@ sub cli_create_template_action() { exist_check($id_agent,'agent',$agent_name); my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; next; } my $template_id = get_template_id($dbh,$template_name); @@ -2840,6 +2843,7 @@ sub cli_delete_template_action() { exist_check($id_agent,'agent',$agent_name); my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; next; } my $template_id = get_template_id($dbh,$template_name); @@ -4390,7 +4394,7 @@ sub cli_delete_data($) { print_log "DELETING THE DATA OF THE MODULE $name OF THE AGENT $name2\n\n"; - pandora_delete_data($dbh, 'module', $id_module); + pandora_delete_data($dbh, 'module', $id_module); } } else { # Delete module data