diff --git a/src/Glpi/Inventory/Request.php b/src/Glpi/Inventory/Request.php index 1436fb031f2..d718db3786d 100644 --- a/src/Glpi/Inventory/Request.php +++ b/src/Glpi/Inventory/Request.php @@ -98,8 +98,10 @@ protected function handleAction(string $action, mixed $content = null): bool case self::NETINV_ACTION: $this->networkInventory($content); break; - case self::REGISTER_ACTION: case self::CONFIG_ACTION: + $this->getConfiguration($content); + break; + case self::REGISTER_ACTION: case self::ESX_ACTION: case self::COLLECT_ACTION: case self::DEPLOY_ACTION: @@ -251,6 +253,24 @@ public function networkInventory(mixed $data): void $this->network($data); } + + public function getConfiguration(mixed $content) + { + $hook_response = Plugin::doHookFunction( + Hooks::INVENTORY_GET_CONFIGURATION, + ['content' => $content] + ); + + if (isset($hook_response['response']) && count($hook_response['response'])) { + $this->addToResponse($hook_response); + } elseif (isset($hook_response['errors']) && count($hook_response['errors'])) { + $this->addError($hook_response['errors'], 400); + } else { + //nothing expected happens; this is an error + $this->addError("Query '" . $this->query . "' is not supported.", 501); + } + } + /** * Handle agent network inventory request * diff --git a/src/Glpi/Plugin/Hooks.php b/src/Glpi/Plugin/Hooks.php index 61f03a14929..14e8cc15e6c 100644 --- a/src/Glpi/Plugin/Hooks.php +++ b/src/Glpi/Plugin/Hooks.php @@ -834,6 +834,32 @@ class Hooks */ public const INVENTORY_GET_PARAMS = 'inventory_get_params'; + /** + * Register a function to provide an agent with additional requested configuration parameters. + * Like an deployement plugin need to provide its endpoint for contunuing the dialog + * + * The function is called with the following parameters: + * - 'machineid' => The ID of the machine for which configuration is requested. + * - 'task' => "Taskname[version]", the task name request + * + * The hooks must return an array that will be send as a json answer to the request. + * This array should have an "response" key to be considered valid. + * If any 'errors' key is provided, we will return an HTTP answer with a 400 error code + * An example from the deploy plugin + * [ + * "response" => [ + * "configValidityPeriod" => 600, + * "schedule" => [ + * { + * "task": "Deploy", + * "remote": "https:\/\/server\/plugins\/deploy\/" + * } + * ] + * ] + * ] + */ + public const INVENTORY_GET_CONFIGURATION = 'inventory_get_configuration'; + /** * Register a function to be called before the inventory submission is handled. * The function is called with the following parameters: