remove functions api to api enterprise because policies is enterprise
This commit is contained in:
parent
f05ba656e1
commit
9236285a98
|
@ -5391,74 +5391,6 @@ function api_set_planned_downtimes_additem ($id, $thrash1, $other, $thrash3) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add agent to a policy. And return a message with the result of the operation.
|
||||
*
|
||||
* @param string $id Id of the target policy.
|
||||
* @param $thrash1 Don't use.
|
||||
* @param array $other it's array, $other as param is <id_agent> in this order
|
||||
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
|
||||
* example:
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* api.php?op=set&op2=add_agent_policy&id=1&other=167&other_mode=url_encode_separator_|
|
||||
*
|
||||
* @param $thrash3 Don't use
|
||||
*/
|
||||
function api_set_add_agent_policy($id, $thrash1, $other, $thrash2) {
|
||||
if (defined ('METACONSOLE')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id == "") {
|
||||
returnError('error_add_agent_policy', __('Error adding agent to policy. Id_policy cannot be left blank.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($other['data'][0] == "") {
|
||||
returnError('error_add_agent_policy', __('Error adding agent to policy. Id_agent cannot be left blank.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the agent exists and permissions
|
||||
if (!util_api_check_agent_and_print_error((int) $other['data'][0], 'string', "AW")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the policy permissions and existence
|
||||
if (enterprise_hook('policies_check_user_policy', array($id)) === false) {
|
||||
$result_agent = db_get_value ('id_agente', 'tagente', 'id_agente', (int) $other['data'][0]);
|
||||
if ($result_agent) {
|
||||
returnError('error_add_agent_policy', __('Error adding agent to policy. Id policy doesn\'t exist.'));
|
||||
return;
|
||||
}
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the agent is already in the policy
|
||||
$id_agent_policy = enterprise_hook('policies_get_agents', array($id, array('id_agent' => $other['data'][0]), 'id'));
|
||||
|
||||
if ($id_agent_policy === ENTERPRISE_NOT_HOOK) {
|
||||
returnError('error_add_agent_policy', __('Error adding agent to policy.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id_agent_policy === false) {
|
||||
$success = enterprise_hook('policies_create_agent', array($other['data'][0], $id));
|
||||
}
|
||||
else {
|
||||
returnError('error_add_agent_policy', __('Error adding agent to policy. The agent is already in the policy.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($success)
|
||||
returnData('string', array('type' => 'string', 'data' => $success));
|
||||
else
|
||||
returnError('error_add_agent_policy', 'Error adding agent to policy.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add data module to policy. And return id from new module.
|
||||
*
|
||||
|
@ -6420,153 +6352,6 @@ function api_set_update_snmp_module_policy($id, $thrash1, $other, $thrash3) {
|
|||
array('type' => 'string', 'data' => __('SNMP policy module updated.')));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply policy. And return id from the applying operation.
|
||||
*
|
||||
* @param string $id Id of the target policy.
|
||||
* @param $thrash1 Don't use.
|
||||
* @param array $other Don't use
|
||||
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
|
||||
* example:
|
||||
*
|
||||
* api.php?op=set&op2=apply_policy&id=1
|
||||
*
|
||||
* @param $thrash3 Don't use
|
||||
*/
|
||||
function api_set_apply_policy($id, $thrash1, $other, $thrash3) {
|
||||
if (defined ('METACONSOLE')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id == "") {
|
||||
returnError('error_apply_policy', __('Error applying policy. Id_policy cannot be left blank.'));
|
||||
return;
|
||||
}
|
||||
|
||||
# Check if this operation is duplicated
|
||||
$duplicated = enterprise_hook('policies_get_policy_queue_status', array($id));
|
||||
|
||||
if ($duplicated === ENTERPRISE_NOT_HOOK) {
|
||||
// We want to return a value
|
||||
if ($other == "return") {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
returnError('error_apply_policy', __('Error applying policy.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($duplicated == STATUS_IN_QUEUE_APPLYING or $duplicated == STATUS_IN_QUEUE_IN) {
|
||||
// We want to return a value
|
||||
if ($other == "return") {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
returnError('error_apply_policy',
|
||||
__('Error applying policy. This policy is already pending to apply.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$check_acl = enterprise_hook('policies_check_user_policy', array($id));
|
||||
if ($check_acl !== true) {
|
||||
// We want to return a value
|
||||
if ($other == "return") {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
returnError('error_apply_policy', __('Error applying policy.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$id = enterprise_hook('add_policy_queue_operation', array($id, 0, 'apply'));
|
||||
|
||||
if ($id === ENTERPRISE_NOT_HOOK) {
|
||||
// We want to return a value
|
||||
if ($other == "return") {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
returnError('error_apply_policy', __('Error applying policy.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We want to return a value
|
||||
if ($other == "return") {
|
||||
if ($id)
|
||||
return $id;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
if ($id)
|
||||
returnData('string', array('type' => 'string', 'data' => $id));
|
||||
else
|
||||
returnError('error_apply_policy', 'Error applying policy.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply all policy in database. And return the number of policies applied.
|
||||
*
|
||||
* @param string $id Don't use.
|
||||
* @param $thrash1 Don't use.
|
||||
* @param array $other Don't use
|
||||
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
|
||||
* example:
|
||||
*
|
||||
* api.php?op=set&op2=apply_all_policies
|
||||
*
|
||||
* @param $thrash3 Don't use
|
||||
*/
|
||||
function api_set_apply_all_policies($thrash1, $thrash2, $other, $thrash3) {
|
||||
global $config;
|
||||
if (defined ('METACONSOLE')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!check_acl($config['id_user'], 0, "AW")) {
|
||||
returnError('forbidden', 'string');
|
||||
return;
|
||||
}
|
||||
|
||||
$policies = array();
|
||||
|
||||
# Get all policies
|
||||
$policies = enterprise_hook('policies_get_policies', array(false, false, false));
|
||||
|
||||
if ($policies === ENTERPRISE_NOT_HOOK) {
|
||||
returnError('error_apply_all_policy', __('Error applying all policies.'));
|
||||
return;
|
||||
}
|
||||
if ($policies === false) $policies = array();
|
||||
|
||||
$num_policies = count($policies);
|
||||
$count_results = 0;
|
||||
foreach ($policies as $policy) {
|
||||
$return_value = enterprise_hook('add_policy_queue_operation',
|
||||
array($policy['id'], 0, 'apply'));
|
||||
|
||||
if ($return_value != -1) {
|
||||
$count_results++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($num_policies > $count_results) {
|
||||
$errors = $num_policies - $count_results;
|
||||
|
||||
returnError('error_apply_policy', 'Error applying policy. ' . $errors . ' failed. ');
|
||||
}
|
||||
else {
|
||||
returnData('string', array('type' => 'string', 'data' => $count_results));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new group. And return the id_group of the new group.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue