]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add links to resources in job log output
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 26 Apr 2019 04:50:24 +0000 (06:50 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Fri, 26 Apr 2019 04:50:24 +0000 (06:50 +0200)
gui/baculum/protected/Web/Class/LogParser.php [new file with mode: 0644]
gui/baculum/protected/Web/Pages/ClientView.php
gui/baculum/protected/Web/Pages/JobHistoryView.php
gui/baculum/protected/Web/Pages/PoolView.php
gui/baculum/protected/Web/Pages/StorageView.php
gui/baculum/protected/Web/Pages/config.xml
gui/baculum/protected/Web/endpoints.xml

diff --git a/gui/baculum/protected/Web/Class/LogParser.php b/gui/baculum/protected/Web/Class/LogParser.php
new file mode 100644 (file)
index 0000000..0c3fcc8
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 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.
+ */
+
+Prado::using('Application.Web.Class.WebModule');
+
+class LogParser extends WebModule {
+
+       const CLIENT_PATTERN = '/^\s+Client\:\s+"?(?P<client>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const POOL_PATTERN = '/^\s+Pool\:\s+"?(?P<pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const READ_POOL_PATTERN = '/^\s+Read Pool\:\s+"?(?P<read_pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const WRITE_POOL_PATTERN = '/^\s+Write Pool\:\s+"?(?P<write_pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const STORAGE_PATTERN = '/^\s+Storage\:\s+"?(?P<storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const READ_STORAGE_PATTERN = '/^\s+Read Storage\:\s+"?(?P<read_storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const WRITE_STORAGE_PATTERN = '/^\s+Write Storage\:\s+"?(?P<write_storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const FILESET_PATTERN = '/^\s+FileSet\:\s+"?(?P<fileset>[a-zA-Z0-9:.\-_ ]+)"?/i';
+       const VERIFY_JOB_PATTERN = '/^\s+Verify Job\:\s+"?(?P<verify_job>[a-zA-Z0-9:.\-_ ]+)"?/i';
+
+       public function parse(array $logs) {
+               $out = array();
+               for ($i = 0; $i < count($logs); $i++) {
+                       $lines = explode("\n", $logs[$i]);
+                       for ($j = 0; $j < count($lines); $j++) {
+                               $out[] = $this->parseLine($lines[$j]);
+                       }
+               }
+               return $out;
+       }
+
+       private function parseLine($log_line) {
+               if (preg_match(self::CLIENT_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('client', $match['client']);
+                       $log_line = str_replace($match['client'], $link, $log_line);
+               } elseif (preg_match(self::POOL_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('pool', $match['pool']);
+                       $log_line = str_replace($match['pool'], $link, $log_line);
+               } elseif (preg_match(self::READ_POOL_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('pool', $match['read_pool']);
+                       $log_line = str_replace($match['read_pool'], $link, $log_line);
+               } elseif (preg_match(self::WRITE_POOL_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('pool', $match['write_pool']);
+                       $log_line = str_replace($match['write_pool'], $link, $log_line);
+               } elseif (preg_match(self::STORAGE_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('storage', $match['storage']);
+                       $log_line = str_replace($match['storage'], $link, $log_line);
+               } elseif (preg_match(self::READ_STORAGE_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('storage', $match['read_storage']);
+                       $log_line = str_replace($match['read_storage'], $link, $log_line);
+               } elseif (preg_match(self::WRITE_STORAGE_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('storage', $match['write_storage']);
+                       $log_line = str_replace($match['write_storage'], $link, $log_line);
+               } elseif (preg_match(self::FILESET_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('fileset', $match['fileset']);
+                       $log_line = str_replace($match['fileset'], $link, $log_line);
+               } elseif (preg_match(self::VERIFY_JOB_PATTERN, $log_line, $match) === 1) {
+                       $link = $this->getLink('job', $match['verify_job']);
+                       $log_line = str_replace($match['verify_job'], $link, $log_line);
+               }
+               return $log_line;
+       }
+
+       private function getLink($type, $name) {
+               return sprintf(
+                       '<a href="/web/%s/%s">%s</a>',
+                       $type,
+                       rawurlencode($name),
+                       $name
+               );
+       }
+}
+?>
index 0fbea572b1c93f5559648292646b255233cb980b..f90e7355ee0d53785724f866c5760bedf3b98334 100644 (file)
@@ -37,6 +37,16 @@ class ClientView extends BaculumWebPage {
                $clientid = 0;
                if ($this->Request->contains('clientid')) {
                        $clientid = $this->Request['clientid'];
+               } elseif ($this->Request->contains('client')) {
+                       $result = $this->getModule('api')->get(array('clients'));
+                       if ($result->error === 0) {
+                               for ($i = 0; $i < count($result->output); $i++) {
+                                       if ($this->Request['client'] === $result->output[$i]->name) {
+                                               $clientid = $result->output[$i]->clientid;
+                                               break;
+                                       }
+                               }
+                       }
                }
                $this->setClientId($clientid);
                $clientshow = $this->getModule('api')->get(
index 88fa31509cc25f0d416f6e1d5f46a034a0bdc522..694c3af298512523e3c9e08d77b94ad3295ad4c0 100644 (file)
@@ -176,6 +176,8 @@ class JobHistoryView extends BaculumWebPage {
                if ($this->getJobLogOrder() === self::SORT_DESC) {
                        $joblog = array_reverse($joblog);
                }
+               $joblog = $this->getModule('log_parser')->parse($joblog);
+
                $this->JobLog->Text = implode(PHP_EOL, $joblog);
        }
 
index bd28f96bb770f8599b5f301a23478391f1484a14..ee7df16c23ed3a4128fd92db463f1fa18fc99e1f 100644 (file)
@@ -40,9 +40,21 @@ class PoolView extends BaculumWebPage {
                if ($this->IsPostBack || $this->IsCallBack) {
                        return;
                }
+               $poolid = 0;
                if ($this->Request->contains('poolid')) {
-                       $this->setPoolId($this->Request['poolid']);
+                       $poolid = $this->Request['poolid'];
+               } elseif ($this->Request->contains('pool')) {
+                       $result = $this->getModule('api')->get(array('pools'));
+                       if ($result->error === 0) {
+                               for ($i = 0; $i < count($result->output); $i++) {
+                                       if ($this->Request['pool'] === $result->output[$i]->name) {
+                                               $poolid = $result->output[$i]->poolid;
+                                               break;
+                                       }
+                               }
+                       }
                }
+               $this->setPoolId($poolid);
                $this->setPool();
                $this->setVolumesinPool();
                $poolshow = $this->getModule('api')->get(
index f0cd470937943c93f497c38f6832090030ebe1ba..c6d3f4c93590cf1b65d2cff51d31dedc2f675b47 100644 (file)
@@ -46,6 +46,16 @@ class StorageView extends BaculumWebPage {
                $storageid = 0;
                if ($this->Request->contains('storageid')) {
                        $storageid = intval($this->Request['storageid']);
+               } elseif ($this->Request->contains('storage')) {
+                       $result = $this->getModule('api')->get(array('storages'));
+                       if ($result->error === 0) {
+                               for ($i = 0; $i < count($result->output); $i++) {
+                                       if ($this->Request['storage'] === $result->output[$i]->name) {
+                                               $storageid = $result->output[$i]->storageid;
+                                               break;
+                                       }
+                               }
+                       }
                }
                $storage = $this->Application->getModule('api')->get(
                        array('storages', $storageid),
index 2450a6579f01c1a4bd2e0b07b2921460f4337478..21babe7b757f8f4bc00e2cb0ea6e4e08d30285f9 100644 (file)
@@ -16,6 +16,7 @@
                <module id="log" class="System.Util.TLogRouter">
                        <route class="TFileLogRoute"  Categories="Execute, External, Application, General, Security" LogPath="Application.Web.Logs" LogFile="baculum-web.log" MaxFileSize="1000" MaxLogFiles="5" />
                </module>
+               <module id="log_parser" class="Application.Web.Class.LogParser" />
                <!-- auth modules -->
                <module id="basic_webuser" class="Application.Web.Class.BasicWebUserConfig" />
        </modules>
index 22a1daa2108c7bc3834b5a548ee88bca805bf84d..4a2d2729a915cd6c3ae9b5ec37495d07868f2943 100644 (file)
@@ -7,13 +7,16 @@
        <url ServiceParameter="JobView" pattern="web/job/{job}/" parameters.job="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="StorageList" pattern="web/storage/" />
        <url ServiceParameter="StorageView" pattern="web/storage/{storageid}/" parameters.storageid="\d+" />
+       <url ServiceParameter="StorageView" pattern="web/storage/{storage}/" parameters.storage="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="DeviceView" pattern="web/device/{storageid}/{device}/" parameters.storageid="\d+" parameters.device="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="PoolList" pattern="web/pool/" />
        <url ServiceParameter="PoolView" pattern="web/pool/{poolid}/" parameters.poolid="\d+" />
+       <url ServiceParameter="PoolView" pattern="web/pool/{pool}/" parameters.pool="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="VolumeList" pattern="web/volume/" />
        <url ServiceParameter="VolumeView" pattern="web/volume/{mediaid}/" parameters.mediaid="\d+" />
        <url ServiceParameter="ClientList" pattern="web/client/" />
        <url ServiceParameter="ClientView" pattern="web/client/{clientid}/" parameters.clientid="\d+" />
+       <url ServiceParameter="ClientView" pattern="web/client/{client}/" parameters.client="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="FileSetList" pattern="web/fileset/" />
        <url ServiceParameter="FileSetView" pattern="web/fileset/{fileset}/" parameters.fileset="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="ScheduleList" pattern="web/schedule/" />