Merge branch 'ent-7722-cambio-en-el-comportamiento-de-modulos-al-editar-un-servicio' into 'develop'

Recreate service modules

See merge request artica/pandorafms!4456
This commit is contained in:
Daniel Rodriguez 2021-10-15 09:52:03 +00:00
commit 691b23c442
1 changed files with 47 additions and 0 deletions

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.
*