]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add show log time parameter to job log endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 18 Apr 2020 19:02:37 +0000 (21:02 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Tue, 19 May 2020 18:46:11 +0000 (20:46 +0200)
gui/baculum/protected/API/Class/LogManager.php
gui/baculum/protected/API/Pages/API/JobLog.php
gui/baculum/protected/API/openapi_baculum.json

index 49a2ac22e237750bb743d1b0888776666f93d315..4d3ef1766854df080d9e18ccf68fc5fe60265c48 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2019 Kern Sibbald
+ * Copyright (C) 2013-2020 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -32,13 +32,23 @@ Prado::using('Application.API.Class.LogRecord');
  */
 class LogManager extends APIModule {
 
-       public function getLogByJobId($jobid) {
+       /**
+        * Get job log by job identifier.
+        *
+        * @param integer $jobid job identifier
+        * @param boolean $show_time show time in job log
+        * @return array job log lines
+        */
+       public function getLogByJobId($jobid, $show_time = false) {
                $logs = LogRecord::finder()->findAllByjobid($jobid);
-               $joblog = null;
+               $joblog = [];
                if(is_array($logs)) {
-                       $joblog = array();
                        foreach($logs as $log) {
-                               $joblog[] = $log->logtext;
+                               if ($show_time) {
+                                       $joblog[] = $log->time . ' ' . $log->logtext;
+                               } else {
+                                       $joblog[] = $log->logtext;
+                               }
                        }
                }
                return $joblog;
index 7dd9650a7d17e36f7f499c0d23f959ce18247b94..ea53912b0773ab2bf5d79c34f4a248ab177ab46b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2019 Kern Sibbald
+ * Copyright (C) 2013-2020 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 class JobLog extends BaculumAPIServer {
        public function get() {
                $jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
+               $show_time = false;
+               if ($this->Request->contains('show_time') && $this->getModule('misc')->isValidBoolean($this->Request['show_time'])) {
+                       $show_time = (bool)$this->Request['show_time'];
+               }
                $result = $this->getModule('bconsole')->bconsoleCommand(
                        $this->director,
                        array('.jobs')
@@ -38,7 +42,7 @@ class JobLog extends BaculumAPIServer {
                        array_shift($result->output);
                        $job = $this->getModule('job')->getJobById($jobid);
                        if (is_object($job) && in_array($job->name, $result->output)) {
-                               $log = $this->getModule('joblog')->getLogByJobId($job->jobid);
+                               $log = $this->getModule('joblog')->getLogByJobId($job->jobid, $show_time);
                                $log = array_map('trim', $log);
                                // Output may contain national characters.
                                $this->output = array_map('utf8_encode', $log);
@@ -53,5 +57,4 @@ class JobLog extends BaculumAPIServer {
                }
        }
 }
-
 ?>
index 3f5e480c28b8832749b53f771674ce2c777e9602..ef0ed0b8b10e75ddb8959ef5fa6e1b5adcbea54a 100644 (file)
                                },
                                "parameters": [{
                                        "$ref": "#/components/parameters/JobId"
+                               },{
+                                       "name": "show_time",
+                                       "in": "query",
+                                       "description": "Show time in job log.",
+                                       "required": false,
+                                       "default": 0,
+                                       "schema": {
+                                               "type": "bool"
+                                       }
                                }]
                        }
                },