From cd148a682ae78ddf151b05a426d4a2a291f03f45 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sun, 24 Jan 2021 20:54:13 +0100 Subject: [PATCH] baculum: Add console messages log API endpoint --- .../protected/API/Pages/API/Messages.php | 46 +++++++++++++++++++ .../protected/API/Pages/API/endpoints.xml | 2 + .../protected/API/openapi_baculum.json | 43 +++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 gui/baculum/protected/API/Pages/API/Messages.php diff --git a/gui/baculum/protected/API/Pages/API/Messages.php b/gui/baculum/protected/API/Pages/API/Messages.php new file mode 100644 index 000000000..644077254 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/Messages.php @@ -0,0 +1,46 @@ + + * @category API + * @package Baculum API + */ +class Messages extends BaculumAPIServer { + + public function get() { + $misc = $this->getModule('misc'); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; + + $cmd = ['messages']; + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, null, true); + $output = $result->output; + if ($result->exitcode == 0) { + $output = $limit > 0 ? array_slice($output, -$limit) : $output; + } + $this->output = $output; + $this->error = $result->exitcode > 0 ? GenericError::ERROR_WRONG_EXITCODE : GenericError::ERROR_NO_ERRORS; + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 404180496..2b18c7530 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -78,6 +78,8 @@ + + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 9d7046586..64bdd8397 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -4415,6 +4415,49 @@ }] } }, + "/api/v1/joblog/messages": { + "get": { + "tags": ["joblog"], + "summary": "Get console messages log.", + "description": "Get messages log. Note, because there are returned all current Bacula messages, this endpoint should not be shared non-admin users.", + "responses": { + "200": { + "description": "Job messages log output", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "description": "Job log output", + "type": "string" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 4, 5, 6, 7, 9, 11, 1000] + } + } + } + } + } + } + }, + "parameters": [{ + "name": "limit", + "in": "query", + "description": "Set messages log Limit.", + "required": false, + "default": 0, + "schema": { + "type": "integer" + } + }] + } + }, "/api/v1/status/director": { "get": { "tags": ["status"], -- 2.47.3