From: Marcin Haba Date: Sat, 18 Apr 2020 19:02:37 +0000 (+0200) Subject: baculum: Add show log time parameter to job log endpoint X-Git-Tag: Release-9.6.4~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7deb0aad5accb29aebbe5dae11296ed3cad706ce;p=thirdparty%2Fbacula.git baculum: Add show log time parameter to job log endpoint --- diff --git a/gui/baculum/protected/API/Class/LogManager.php b/gui/baculum/protected/API/Class/LogManager.php index 49a2ac22e..4d3ef1766 100644 --- a/gui/baculum/protected/API/Class/LogManager.php +++ b/gui/baculum/protected/API/Class/LogManager.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/JobLog.php b/gui/baculum/protected/API/Pages/API/JobLog.php index 7dd9650a7..ea53912b0 100644 --- a/gui/baculum/protected/API/Pages/API/JobLog.php +++ b/gui/baculum/protected/API/Pages/API/JobLog.php @@ -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 @@ -30,6 +30,10 @@ 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 { } } } - ?> diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 3f5e480c2..ef0ed0b8b 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -4231,6 +4231,15 @@ }, "parameters": [{ "$ref": "#/components/parameters/JobId" + },{ + "name": "show_time", + "in": "query", + "description": "Show time in job log.", + "required": false, + "default": 0, + "schema": { + "type": "bool" + } }] } },