From: Marcin Haba Date: Wed, 21 Feb 2024 12:29:22 +0000 (+0100) Subject: baculum: Add overview parameter to client resources endpoint X-Git-Tag: Release-15.0.2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70c7b4f3efe3fa339386c5e5735204b34573c187;p=thirdparty%2Fbacula.git baculum: Add overview parameter to client resources endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/ClientResNames.php b/gui/baculum/protected/API/Pages/API/ClientResNames.php index 638e571d9..e2be86cd8 100644 --- a/gui/baculum/protected/API/Pages/API/ClientResNames.php +++ b/gui/baculum/protected/API/Pages/API/ClientResNames.php @@ -21,6 +21,7 @@ */ use Baculum\API\Modules\BaculumAPIServer; +use Baculum\API\Modules\ClientManager; use Baculum\Common\Modules\Errors\BconsoleError; /** @@ -32,7 +33,13 @@ use Baculum\Common\Modules\Errors\BconsoleError; */ class ClientResNames extends BaculumAPIServer { public function get() { - $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : 0; + $misc = $this->getModule('misc'); + $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int) $this->Request['limit'] : 0; + $mode = $this->Request->contains('overview') && $misc->isValidBooleanTrue($this->Request['overview']) ? ClientManager::CLIENT_RESULT_MODE_OVERVIEW : ClientManager::CLIENT_RESULT_MODE_NORMAL; + if ($mode == ClientManager::CLIENT_RESULT_MODE_OVERVIEW) { + // For overview mode, limit is not taken into account + $limit = 0; + } $clients_cmd = ['.client']; $directors = $this->getModule('bconsole')->getDirectors(); @@ -74,6 +81,25 @@ class ClientResNames extends BaculumAPIServer { $this->output = BconsoleError::MSG_ERROR_WRONG_EXITCODE . $emsg; $this->error = BconsoleError::ERROR_WRONG_EXITCODE; } else { + if ($mode == ClientManager::CLIENT_RESULT_MODE_OVERVIEW) { + $clis = [ + 'reachable' => [], + 'unreachable' => [] + ]; + $clients_cat = $this->getModule('client')->getClients(); + foreach ($clients as $director => $clients_bac) { + for ($i = 0; $i < count($clients_cat); $i++) { + if (in_array($clients_cat[$i]['name'], $clients_bac)) { + if (empty($clients_cat[$i]['uname'])) { + $clis['unreachable'][] = $clients_cat[$i]['name']; + } else { + $clis['reachable'][] = $clients_cat[$i]['name']; + } + } + } + } + $clients = $clis; + } $this->output = $clients; $this->error = BconsoleError::ERROR_NO_ERRORS; } diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index feaaa34bc..38e49345b 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -929,6 +929,15 @@ "parameters": [ { "$ref": "#/components/parameters/Limit" + }, + { + "name": "overview", + "in": "query", + "required": false, + "description": "If set, it provides the client list split into reacheable and unreachable clients. Offset and limit parameters do not apply to overview counts.", + "schema": { + "type": "boolean" + } } ] }