]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add console messages log API endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 24 Jan 2021 19:54:13 +0000 (20:54 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:24 +0000 (09:03 +0100)
gui/baculum/protected/API/Pages/API/Messages.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

diff --git a/gui/baculum/protected/API/Pages/API/Messages.php b/gui/baculum/protected/API/Pages/API/Messages.php
new file mode 100644 (file)
index 0000000..6440772
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+/**
+ * Console messages.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @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;
+       }
+}
+?>
index 404180496bbc3ff7823ecf219f56387f89b4d7c2..2b18c75309ecfce1ceca4785acae329793062353 100644 (file)
@@ -78,6 +78,8 @@
        <url ServiceParameter="BVFSCleanUp" pattern="api/v1/bvfs/cleanup/" />
        <!-- joblog endpoints -->
        <url ServiceParameter="JobLog" pattern="api/v1/joblog/{id}/" parameters.id="\d+" />
+       <!-- @TODO: Separate this endpoint outside 'joblog' -->
+       <url ServiceParameter="Messages" pattern="api/v1/joblog/messages" />
        <!-- fileset endpoints -->
        <url ServiceParameter="FileSets" pattern="api/v1/filesets/" />
        <url ServiceParameter="FileSet" pattern="api/v1/filesets/{id}/" parameters.id="\d+" />
index 9d704658604a0ad7e821dc05a263b8481fd5937e..64bdd83971e72dbd3c422b75df21224fcb1cbc14 100644 (file)
                                }]
                        }
                },
+               "/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"],