Recreate service modules

This commit is contained in:
fbsanchez 2021-10-07 13:21:04 +02:00
parent 2118f44a7a
commit d4ceaa4643
1 changed files with 47 additions and 0 deletions
pandora_console/include

View File

@ -14641,6 +14641,53 @@ function api_set_add_element_service($thrash1, $thrash2, $other, $thrash3)
}
/**
* Example: http://127.0.0.1/pandora_console/include/api.php?op=set&op2=recreate_service_modules&id=1&user=admin&apipass=1234&pass=pandora
* Recreates modules for given service id, if needed.
*
* @param integer $id Id service.
* @param integer|null $id_agent Agent id to allocate service if node env.
* @return void
*/
function api_set_recreate_service_modules($id, $id_agent)
{
global $config;
if (!check_acl($config['id_user'], $service['id_group'], 'AW')) {
returnError('forbidden', 'string');
return;
}
$id_agent = (int) $id_agent;
if (empty($id_agent) === true) {
$id_agent = null;
}
if (is_metaconsole() === true) {
// Force agent recreation in MC if modules are missing.
$id_agent = null;
}
$result = false;
try {
$service = new PandoraFMS\Enterprise\Service($id);
if ($service->migrateModules() !== true) {
$service->addModules($id_agent);
}
$result = true;
} catch (Exception $e) {
$result = false;
$error = $e->getMessage();
}
if ($result === true) {
returnData('string', ['type' => 'string', 'data' => 'OK']);
} else {
returnError('The service modules could not be recreated: '.$error);
}
}
/**
* Update a special day. And return a message with the result of the operation.
*