Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Glpi/Inventory/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
*
Expand Down
26 changes: 26 additions & 0 deletions src/Glpi/Plugin/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Like an deployement plugin need to provide its endpoint for contunuing the dialog
* Like a deployement plugin need to provide its endpoint for continuing 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
Comment on lines +842 to +843
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - 'machineid' => The ID of the machine for which configuration is requested.
* - 'task' => "Taskname[version]", the task name request
* - '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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The hooks must return an array that will be send as a json answer to the request.
* The hooks must return an array that will be sent as a json answer to the request.

* This array should have an "response" key to be considered valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This array should have an "response" key to be considered valid.
* This array should have a "response" key to be considered valid.

* If any 'errors' key is provided, we will return an HTTP answer with a 400 error code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If any 'errors' key is provided, we will return an HTTP answer with a 400 error code
* If any 'errors' key is provided, we will return an HTTP answer with a 400 error code.

* An example from the deploy plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* An example from the deploy plugin
*
* 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:
Expand Down