From: Marcin Haba Date: Fri, 26 Apr 2019 04:50:24 +0000 (+0200) Subject: baculum: Add links to resources in job log output X-Git-Tag: Release-9.4.3~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6f5cdf48395058ed7ea307a78c057364aad9205;p=thirdparty%2Fbacula.git baculum: Add links to resources in job log output --- diff --git a/gui/baculum/protected/Web/Class/LogParser.php b/gui/baculum/protected/Web/Class/LogParser.php new file mode 100644 index 000000000..0c3fcc8dc --- /dev/null +++ b/gui/baculum/protected/Web/Class/LogParser.php @@ -0,0 +1,89 @@ +[a-zA-Z0-9:.\-_ ]+)"?/i'; + const POOL_PATTERN = '/^\s+Pool\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const READ_POOL_PATTERN = '/^\s+Read Pool\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const WRITE_POOL_PATTERN = '/^\s+Write Pool\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const STORAGE_PATTERN = '/^\s+Storage\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const READ_STORAGE_PATTERN = '/^\s+Read Storage\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const WRITE_STORAGE_PATTERN = '/^\s+Write Storage\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const FILESET_PATTERN = '/^\s+FileSet\:\s+"?(?P[a-zA-Z0-9:.\-_ ]+)"?/i'; + const VERIFY_JOB_PATTERN = '/^\s+Verify Job\:\s+"?(?P[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( + '%s', + $type, + rawurlencode($name), + $name + ); + } +} +?> diff --git a/gui/baculum/protected/Web/Pages/ClientView.php b/gui/baculum/protected/Web/Pages/ClientView.php index 0fbea572b..f90e7355e 100644 --- a/gui/baculum/protected/Web/Pages/ClientView.php +++ b/gui/baculum/protected/Web/Pages/ClientView.php @@ -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( diff --git a/gui/baculum/protected/Web/Pages/JobHistoryView.php b/gui/baculum/protected/Web/Pages/JobHistoryView.php index 88fa31509..694c3af29 100644 --- a/gui/baculum/protected/Web/Pages/JobHistoryView.php +++ b/gui/baculum/protected/Web/Pages/JobHistoryView.php @@ -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); } diff --git a/gui/baculum/protected/Web/Pages/PoolView.php b/gui/baculum/protected/Web/Pages/PoolView.php index bd28f96bb..ee7df16c2 100644 --- a/gui/baculum/protected/Web/Pages/PoolView.php +++ b/gui/baculum/protected/Web/Pages/PoolView.php @@ -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( diff --git a/gui/baculum/protected/Web/Pages/StorageView.php b/gui/baculum/protected/Web/Pages/StorageView.php index f0cd47093..c6d3f4c93 100644 --- a/gui/baculum/protected/Web/Pages/StorageView.php +++ b/gui/baculum/protected/Web/Pages/StorageView.php @@ -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), diff --git a/gui/baculum/protected/Web/Pages/config.xml b/gui/baculum/protected/Web/Pages/config.xml index 2450a6579..21babe7b7 100644 --- a/gui/baculum/protected/Web/Pages/config.xml +++ b/gui/baculum/protected/Web/Pages/config.xml @@ -16,6 +16,7 @@ + diff --git a/gui/baculum/protected/Web/endpoints.xml b/gui/baculum/protected/Web/endpoints.xml index 22a1daa21..4a2d2729a 100644 --- a/gui/baculum/protected/Web/endpoints.xml +++ b/gui/baculum/protected/Web/endpoints.xml @@ -7,13 +7,16 @@ + + +