mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
fixed api calls
This commit is contained in:
parent
3a95c3dd58
commit
57b06be302
@ -35,6 +35,8 @@ enterprise_include_once('include/functions_modules.php');
|
|||||||
enterprise_include_once('include/functions_clusters.php');
|
enterprise_include_once('include/functions_clusters.php');
|
||||||
enterprise_include_once('include/functions_alerts.php');
|
enterprise_include_once('include/functions_alerts.php');
|
||||||
|
|
||||||
|
use PandoraFMS\Enterprise\Cluster;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the "other" parameter.
|
* Parse the "other" parameter.
|
||||||
@ -13883,8 +13885,10 @@ function api_set_add_cluster_agent($thrash1, $thrash2, $other, $thrash3)
|
|||||||
$array_json = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
$array_json = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
||||||
if (!empty($array_json)) {
|
if (!empty($array_json)) {
|
||||||
foreach ($array_json as $key => $element) {
|
foreach ($array_json as $key => $element) {
|
||||||
$check_cluster_group = clusters_get_group($element['id']);
|
$clusters = Cluster::search(['id' => $element['id']]);
|
||||||
if ((!check_acl($config['id_user'], $check_cluster_group, 'AW'))
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if ((!check_acl($config['id_user'], $cluster['group'], 'AW'))
|
||||||
|| (!agents_check_access_agent($element['id_agent'], 'AW'))
|
|| (!agents_check_access_agent($element['id_agent'], 'AW'))
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
@ -13914,8 +13918,10 @@ function api_set_add_cluster_item($thrash1, $thrash2, $other, $thrash3)
|
|||||||
$array_json = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
$array_json = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
||||||
if (is_array($array_json)) {
|
if (is_array($array_json)) {
|
||||||
foreach ($array_json as $key => $element) {
|
foreach ($array_json as $key => $element) {
|
||||||
$cluster_group = clusters_get_group($element['id']);
|
$clusters = Cluster::search(['id' => $element['id_cluster']]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AW')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AW')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14044,8 +14050,10 @@ function api_set_delete_cluster($id, $thrash1, $thrast2, $thrash3)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($id);
|
$clusters = Cluster::search(['id' => $id]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AD')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AD')) {
|
||||||
returnError('error_set_delete_cluster', __('The user cannot access to the cluster'));
|
returnError('error_set_delete_cluster', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -14085,44 +14093,32 @@ function api_set_delete_cluster_agents($thrash1, $thrast2, $other, $thrash3)
|
|||||||
|
|
||||||
$target_agents = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
$target_agents = json_decode(base64_decode(io_safe_output($other['data'][0])), true);
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($id_agent);
|
$deleted_counter = 0;
|
||||||
if (!users_is_admin($config['id_user'])) {
|
|
||||||
if (!$cluster_group
|
|
||||||
|| (!check_acl($config['id_user'], $cluster_group, 'AW'))
|
|
||||||
|| (!agents_check_access_agent($id_agent, 'AW'))
|
|
||||||
) {
|
|
||||||
returnError('error_set_delete_cluster_agent', __('The user cannot access to the cluster'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$n_agents_deleted = 0;
|
foreach ($target_agents as $ta) {
|
||||||
$n_agents = 0;
|
$clusters = Cluster::search(['id' => $ta['id']]);
|
||||||
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
if (is_array($target_agents)) {
|
// $cluster_group = clusters_get_group($id_agent);
|
||||||
$target_clusters = [];
|
if (!users_is_admin($config['id_user'])) {
|
||||||
foreach ($target_agents as $data) {
|
if (!$cluster['group']
|
||||||
$n_agents++;
|
|| (!check_acl($config['id_user'], $cluster['group'], 'AW'))
|
||||||
if (!isset($target_clusters[$data['id']])) {
|
|| (!agents_check_access_agent($ta['id_agent'], 'AW'))
|
||||||
$target_clusters[$data['id']] = [];
|
) {
|
||||||
}
|
returnError('error_set_delete_cluster_agent', __('The user cannot access to the cluster'));
|
||||||
|
return;
|
||||||
array_push($target_clusters[$data['id']], $data['id_agent']);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($target_clusters as $id_cluster => $id_agent_array) {
|
|
||||||
$rs = cluster_delete_agents($id_cluster, $id_agent_array);
|
|
||||||
if ($rs !== false) {
|
|
||||||
$n_agents_deleted += $rs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cluster = new Cluster($ta['id']);
|
||||||
|
$deleted = $cluster->removeMember($ta['id_agent']);
|
||||||
|
|
||||||
|
if ($deleted === true) {
|
||||||
|
$deleted_counter++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($n_agents > $n_agents_deleted) {
|
returnData('string', ['type' => 'string', 'data' => $deleted_counter]);
|
||||||
returnError('error_delete', 'Error in delete operation.');
|
|
||||||
} else {
|
|
||||||
returnData('string', ['type' => 'string', 'data' => $n_agents_deleted]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14135,8 +14131,10 @@ function api_set_delete_cluster_item($id, $thrash1, $thrast2, $thrast3)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($id);
|
$clusters = Cluster::search(['id' => $id]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AD')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AD')) {
|
||||||
returnError('error_set_delete_cluster_item', __('The user cannot access to the cluster'));
|
returnError('error_set_delete_cluster_item', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -14310,8 +14308,10 @@ function api_get_cluster_status($id_cluster, $trash1, $trash2, $returnType)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($id_cluster);
|
$clusters = Cluster::search(['id' => $id_cluster]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -14342,21 +14342,23 @@ function api_get_cluster_id_by_name($cluster_name, $trash1, $trash2, $returnType
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = cluster_get_id_by_name($cluster_name);
|
$clusters = Cluster::search(['name' => $cluster_name]);
|
||||||
if (($value === false) || ($value === null)) {
|
|
||||||
|
if ($clusters === false) {
|
||||||
returnError('id_not_found', $returnType);
|
returnError('id_not_found', $returnType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($value);
|
$cluster = $clusters[0];
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'data' => $value,
|
'data' => $cluster['id'],
|
||||||
];
|
];
|
||||||
|
|
||||||
returnData($returnType, $data);
|
returnData($returnType, $data);
|
||||||
@ -14371,13 +14373,22 @@ function api_get_agents_id_name_by_cluster_id($cluster_id, $trash1, $trash2, $re
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($cluster_id);
|
$clusters = Cluster::search(['id' => $cluster_id]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_agents = cluster_get_agents_id_name_by_cluster_id($cluster_id);
|
$cluster = new Cluster($cluster_id);
|
||||||
|
$cluster_agents = $cluster->getMembers();
|
||||||
|
|
||||||
|
$all_agents = [];
|
||||||
|
|
||||||
|
foreach ($cluster_agents as $ca) {
|
||||||
|
$all_agents[$ca->id_agente()] = $ca->name();
|
||||||
|
}
|
||||||
|
|
||||||
if ($all_agents !== false) {
|
if ($all_agents !== false) {
|
||||||
$data = [
|
$data = [
|
||||||
@ -14400,18 +14411,27 @@ function api_get_agents_id_name_by_cluster_name($cluster_name, $trash1, $trash2,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = cluster_get_id_by_name($cluster_name);
|
$clusters = Cluster::search(['name' => $cluster_name]);
|
||||||
if (($value === false) || ($value === null)) {
|
|
||||||
|
if ($clusters === false) {
|
||||||
returnError('id_not_found', $returnType);
|
returnError('id_not_found', $returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($value);
|
$cluster = $clusters[0];
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_agents = cluster_get_agents_id_name_by_cluster_id($value);
|
$cluster = new Cluster($cluster['id']);
|
||||||
|
$cluster_agents = $cluster->getMembers();
|
||||||
|
|
||||||
|
$all_agents = [];
|
||||||
|
|
||||||
|
foreach ($cluster_agents as $ca) {
|
||||||
|
$all_agents[$ca->id_agente()] = $ca->name();
|
||||||
|
}
|
||||||
|
|
||||||
if (count($all_agents) > 0 and $all_agents !== false) {
|
if (count($all_agents) > 0 and $all_agents !== false) {
|
||||||
$data = [
|
$data = [
|
||||||
@ -14474,13 +14494,30 @@ function api_get_modules_id_name_by_cluster_id($cluster_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($cluster_id);
|
$clusters = Cluster::search(['id' => $cluster_id]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_modules = cluster_get_modules_id_name_by_cluster_id($cluster_id);
|
$cluster_type = $cluster['cluster_type'] == 'AA' ? MODULE_PREDICTION_CLUSTER_AA : MODULE_PREDICTION_CLUSTER_AP;
|
||||||
|
|
||||||
|
$cluster = new Cluster($cluster_id);
|
||||||
|
$cluster_modules = $cluster->getItems($cluster_type);
|
||||||
|
|
||||||
|
$all_modules = [];
|
||||||
|
|
||||||
|
foreach ($cluster_modules as $cm) {
|
||||||
|
$module_obj = $cm->getModule();
|
||||||
|
$module_values = $module_obj->toArray();
|
||||||
|
|
||||||
|
$id_agent_module = $module_values['id_agente_modulo'];
|
||||||
|
$module_name = $module_values['nombre'];
|
||||||
|
|
||||||
|
$all_modules[$id_agent_module] = $module_name;
|
||||||
|
}
|
||||||
|
|
||||||
if (count($all_modules) > 0 and $all_modules !== false) {
|
if (count($all_modules) > 0 and $all_modules !== false) {
|
||||||
$data = [
|
$data = [
|
||||||
@ -14504,18 +14541,30 @@ function api_get_modules_id_name_by_cluster_name($cluster_name)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = cluster_get_id_by_name($cluster_name);
|
$clusters = Cluster::search(['name' => $cluster_name]);
|
||||||
if (($value === false) || ($value === null)) {
|
$cluster = $clusters[0];
|
||||||
returnError('id_not_found', $returnType);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($value);
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_modules = cluster_get_modules_id_name_by_cluster_id($value);
|
$cluster_type = $cluster['cluster_type'] == 'AA' ? MODULE_PREDICTION_CLUSTER_AA : MODULE_PREDICTION_CLUSTER_AP;
|
||||||
|
|
||||||
|
$cluster = new Cluster($cluster['id']);
|
||||||
|
$cluster_modules = $cluster->getItems($cluster_type);
|
||||||
|
|
||||||
|
$all_modules = [];
|
||||||
|
|
||||||
|
foreach ($cluster_modules as $cm) {
|
||||||
|
$module_obj = $cm->getModule();
|
||||||
|
$module_values = $module_obj->toArray();
|
||||||
|
|
||||||
|
$id_agent_module = $module_values['id_agente_modulo'];
|
||||||
|
$module_name = $module_values['nombre'];
|
||||||
|
|
||||||
|
$all_modules[$id_agent_module] = $module_name;
|
||||||
|
}
|
||||||
|
|
||||||
if (count($all_modules) > 0 and $all_modules !== false) {
|
if (count($all_modules) > 0 and $all_modules !== false) {
|
||||||
$data = [
|
$data = [
|
||||||
@ -14702,13 +14751,61 @@ function api_get_cluster_items($cluster_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cluster_group = clusters_get_group($cluster_id);
|
$clusters = Cluster::search(['id' => $cluster_id]);
|
||||||
if (!check_acl($config['id_user'], $cluster_group, 'AR')) {
|
$cluster = $clusters[0];
|
||||||
|
|
||||||
|
if (!check_acl($config['id_user'], $cluster['group'], 'AR')) {
|
||||||
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
returnError('error_get_cluster_status', __('The user cannot access to the cluster'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_items = cluster_get_items($cluster_id);
|
$cluster = new Cluster($cluster_id);
|
||||||
|
$cluster_modules_AA = $cluster->getItems(MODULE_PREDICTION_CLUSTER_AA);
|
||||||
|
$cluster_modules_AP = $cluster->getItems(MODULE_PREDICTION_CLUSTER_AP);
|
||||||
|
$cluster_modules = array_merge($cluster_modules_AA, $cluster_modules_AP);
|
||||||
|
|
||||||
|
$cluster_items = [];
|
||||||
|
|
||||||
|
foreach ($cluster_modules as $cm) {
|
||||||
|
$cluster_module_values = $cm->toArray();
|
||||||
|
|
||||||
|
$module_obj = $cm->getModule();
|
||||||
|
$module_values = $module_obj->toArray();
|
||||||
|
|
||||||
|
$cluster_items[] = [
|
||||||
|
'id' => $cluster_module_values['id'],
|
||||||
|
'name' => $cluster_module_values['name'],
|
||||||
|
'id_agente_modulo' => $module_values['id_agente_modulo'],
|
||||||
|
'item_type' => $cluster_module_values['item_type'],
|
||||||
|
'critical_limit' => $cluster_module_values['critical_limit'],
|
||||||
|
'warning_limit' => $cluster_module_values['warning_limit'],
|
||||||
|
'is_critical' => $cluster_module_values['is_critical'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cluster_items_2 = [];
|
||||||
|
|
||||||
|
foreach ($cluster_items as $key => $value) {
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['name'] = $cluster_items[$key]['name'];
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['id_agente_modulo'] = $cluster_items[$key]['id_agente_modulo'];
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['type'] = $cluster_items[$key]['item_type'];
|
||||||
|
|
||||||
|
if ($cluster_items_2[$cluster_items[$key]['id']]['type'] == 'AA') {
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['pcrit'] = $cluster_items[$key]['critical_limit'];
|
||||||
|
} else if ($cluster_items_2[$cluster_items[$key]['id']]['type'] == 'AP') {
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['pcrit'] = $cluster_items[$key]['is_critical'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cluster_items_2[$cluster_items[$key]['id']]['type'] == 'AA') {
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['pwarn'] = $cluster_items[$key]['warning_limit'];
|
||||||
|
} else if ($cluster_items_2[$cluster_items[$key]['id']]['type'] == 'AP') {
|
||||||
|
$cluster_items_2[$cluster_items[$key]['id']]['pwarn'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($cluster_items_2[$key]['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$all_items = $cluster_items_2;
|
||||||
|
|
||||||
if (count($all_items) > 0 and $all_items !== false) {
|
if (count($all_items) > 0 and $all_items !== false) {
|
||||||
$data = [
|
$data = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user