diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 0c982e6031..0ee513a877 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -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. *