Merge branch '2299_Añadir_nueva_funcionalidad_en_el_CLI_remove_agent_from_policy' into 'develop'
2299 añadir nueva funcionalidad en el cli remove agent from policy See merge request artica/pandorafms!2092 Former-commit-id: d9ef39c8571ab3558e76883e1afc9cbb00225c79
This commit is contained in:
commit
6ba8b9ab9a
|
@ -32,6 +32,7 @@ include_once($config['homedir'] . "/include/functions_servers.php");
|
||||||
include_once($config['homedir'] . "/include/functions_planned_downtimes.php");
|
include_once($config['homedir'] . "/include/functions_planned_downtimes.php");
|
||||||
include_once($config['homedir'] . "/include/functions_db.php");
|
include_once($config['homedir'] . "/include/functions_db.php");
|
||||||
include_once($config['homedir'] . "/include/functions_event_responses.php");
|
include_once($config['homedir'] . "/include/functions_event_responses.php");
|
||||||
|
include_once($config['homedir'] . "/include/functions_policies.php");
|
||||||
enterprise_include_once ('include/functions_local_components.php');
|
enterprise_include_once ('include/functions_local_components.php');
|
||||||
enterprise_include_once ('include/functions_events.php');
|
enterprise_include_once ('include/functions_events.php');
|
||||||
enterprise_include_once ('include/functions_agents.php');
|
enterprise_include_once ('include/functions_agents.php');
|
||||||
|
@ -6448,6 +6449,63 @@ function api_set_update_snmp_module_policy($id, $thrash1, $other, $thrash3) {
|
||||||
array('type' => 'string', 'data' => __('SNMP policy module updated.')));
|
array('type' => 'string', 'data' => __('SNMP policy module updated.')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an agent from a policy.
|
||||||
|
* @param $id Id of the policy
|
||||||
|
* @param $id2 Id of the agent policy
|
||||||
|
* @param $trash1
|
||||||
|
* @param $trash2
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* api.php?op=set&op2=remove_agent_from_policy&apipass=1234&user=admin&pass=pandora&id=11&id2=2
|
||||||
|
*/
|
||||||
|
function api_set_remove_agent_from_policy ($id, $id2, $thrash2, $thrash3) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], 0, "AW")){
|
||||||
|
returnError('forbidden', 'string');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id == '' || !$id) {
|
||||||
|
returnError('error_parameter', __('Error deleting agent from policy. Policy cannot be left blank.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id2 == '' || !$id2) {
|
||||||
|
returnError('error_parameter', __('Error deleting agent from policy. Agent cannot be left blank.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$policy = policies_get_policy ($id, false, false);
|
||||||
|
$agent = db_get_row_filter('tagente', array('id_agente' => $id2));
|
||||||
|
$policy_agent = db_get_row_filter('tpolicy_agents', array('id_policy' => $id ,'id_agent' => $id2));
|
||||||
|
|
||||||
|
if (empty ($policy)){
|
||||||
|
returnError('error_policy', __('This policy does not exist.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (empty ($agent)){
|
||||||
|
returnError('error_agent', __('This agent does not exist.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (empty ($policy_agent)){
|
||||||
|
returnError('error_policy_agent', __('This agent does not exist in this policy.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = policies_change_delete_pending_agent($policy_agent['id']);
|
||||||
|
$data = __('Successfully added to delete pending id agent %d to id policy %d.', $id2, $id);
|
||||||
|
|
||||||
|
if ($return === false)
|
||||||
|
returnError('error_delete_policy_agent', 'Could not be deleted id agent %d from id policy %d', $id2, $id);
|
||||||
|
else
|
||||||
|
returnData('string', array('type' => 'string', 'data' => $data));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new group. And return the id_group of the new group.
|
* Create a new group. And return the id_group of the new group.
|
||||||
*
|
*
|
||||||
|
|
|
@ -195,6 +195,7 @@ sub help_screen{
|
||||||
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
||||||
help_screen_line('--apply_all_policies', '', 'Force apply to all the policies');
|
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>', '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('--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');
|
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
|
||||||
help_screen_line('--create_policy', '<policy_name> <group_name> <description>');
|
help_screen_line('--create_policy', '<policy_name> <group_name> <description>');
|
||||||
|
@ -4101,6 +4102,19 @@ sub cli_policy_add_agent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# delete an agent to a policy
|
||||||
|
# Related option: --remove_agent_from_policy
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
sub cli_policy_delete_agent() {
|
||||||
|
my ($policy_id, $agent_id) = @ARGV[2..3];
|
||||||
|
|
||||||
|
my $result = api_call(\%conf,'set', 'remove_agent_from_policy', $policy_id, $agent_id);
|
||||||
|
print "$result \n\n ";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sub cli_create_planned_downtime() {
|
sub cli_create_planned_downtime() {
|
||||||
my $name = @ARGV[2];
|
my $name = @ARGV[2];
|
||||||
my @todo = @ARGV[3..21];
|
my @todo = @ARGV[3..21];
|
||||||
|
@ -5836,6 +5850,10 @@ sub pandora_manage_main ($$$) {
|
||||||
param_check($ltotal, 2);
|
param_check($ltotal, 2);
|
||||||
cli_policy_add_agent();
|
cli_policy_add_agent();
|
||||||
}
|
}
|
||||||
|
elsif ($param eq '--remove_agent_from_policy') {
|
||||||
|
param_check($ltotal, 2);
|
||||||
|
cli_policy_delete_agent();
|
||||||
|
}
|
||||||
elsif ($param eq '--enable_user') {
|
elsif ($param eq '--enable_user') {
|
||||||
param_check($ltotal, 1);
|
param_check($ltotal, 1);
|
||||||
cli_user_enable();
|
cli_user_enable();
|
||||||
|
|
Loading…
Reference in New Issue