From: Marcin Haba Date: Thu, 9 Aug 2018 19:59:55 +0000 (+0200) Subject: baculum: Add status director and status storage endpoints X-Git-Tag: Release-9.2.1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=915de484c5bc6cd425a9c8aae900e762fce1b880;p=thirdparty%2Fbacula.git baculum: Add status director and status storage endpoints --- diff --git a/gui/baculum/protected/API/Class/ComponentStatusModule.php b/gui/baculum/protected/API/Class/ComponentStatusModule.php new file mode 100644 index 000000000..8b2e60d79 --- /dev/null +++ b/gui/baculum/protected/API/Class/ComponentStatusModule.php @@ -0,0 +1,52 @@ +\w+)=(?P[\S\s]*)$/', $line, $match) === 1) { + $ret = $match; + } + return $ret; + } +} +?> diff --git a/gui/baculum/protected/API/Class/DirectorStatus.php b/gui/baculum/protected/API/Class/DirectorStatus.php new file mode 100644 index 000000000..b205b0156 --- /dev/null +++ b/gui/baculum/protected/API/Class/DirectorStatus.php @@ -0,0 +1,68 @@ +parseLine($output[$i]); + if (is_array($line)) { // check if line + if (!key_exists($section, $result)) { + $result[$section] = array(); + continue; + } + $opts[$line['key']] = $line['value']; + } elseif (count($opts) > 0) { // dump all parameters + $result[$section][] = $opts; + $opts = array(); + } + } + } + return $result; + } +} +?> diff --git a/gui/baculum/protected/API/Class/StorageStatus.php b/gui/baculum/protected/API/Class/StorageStatus.php new file mode 100644 index 000000000..4bc9c01a0 --- /dev/null +++ b/gui/baculum/protected/API/Class/StorageStatus.php @@ -0,0 +1,65 @@ + 10) { + $result[] = $opts; + } + if (count($opts) > 0) { + $opts = array(); + } + } elseif ($output[$i] === 'header:') { + $header = true; + } else { + $line = $this->parseLine($output[$i]); + if (is_array($line)) { + $opts[$line['key']] = $line['value']; + } + } + } + if ($header) { + // header is only one so get it without using list + $result = array_pop($result); + } + return $result; + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/ComponentStatus.php b/gui/baculum/protected/API/Pages/API/ComponentStatus.php new file mode 100644 index 000000000..d813cb5e4 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/ComponentStatus.php @@ -0,0 +1,78 @@ +getModule('misc'); + $component = $this->Request->contains('component') ? $this->Request['component'] : ''; + $type = $this->Request->contains('type') && $misc->isValidName($this->Request['type']) ? $this->Request['type'] : ''; + + switch($component) { + case 'director': { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('status', 'director'), + true + ); + if ($result->exitcode === 0) { + $output = $this->getModule('status_dir')->getStatus($result->output); + if ($misc->isValidName($type) && key_exists($type, $output)) { + $this->output = $output[$type]; + } else { + $this->output = $output; + } + } else { + $this->output = $result->output; + } + $this->error = $result->exitcode; + break; + } + case 'storage': { + $storage = 'storage'; + if (empty($type)) { + $type = 'header'; // default list terminated jobs + } + if ($this->Request->contains('name') && $misc->isValidName($this->Request['name'])) { + $storage .= '="' . $this->Request['name'] . '"'; + } + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('.status', $storage, $type), + true + ); + if ($result->exitcode === 0) { + $this->output = $this->getModule('status_sd')->getStatus($result->output); + } else { + $this->output = $result->output; + } + $this->error = $result->exitcode; + break; + } + } + } +} +?> diff --git a/gui/baculum/protected/API/Pages/config.xml b/gui/baculum/protected/API/Pages/config.xml index 60e712cc0..a28dc64aa 100644 --- a/gui/baculum/protected/API/Pages/config.xml +++ b/gui/baculum/protected/API/Pages/config.xml @@ -35,5 +35,8 @@ + + + diff --git a/gui/baculum/protected/API/endpoints.xml b/gui/baculum/protected/API/endpoints.xml index 0e4faa5f5..6f59adcb5 100644 --- a/gui/baculum/protected/API/endpoints.xml +++ b/gui/baculum/protected/API/endpoints.xml @@ -82,6 +82,8 @@ + +