From: Marcin Haba Date: Fri, 24 Nov 2023 14:53:48 +0000 (+0100) Subject: baculum: Add option to interpret Bacula error codes by API X-Git-Tag: Beta-15.0.1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43bc6a9e2183718200f585de66d31a00d02d3415;p=thirdparty%2Fbacula.git baculum: Add option to interpret Bacula error codes by API --- diff --git a/gui/baculum/protected/API/Lang/en/messages.mo b/gui/baculum/protected/API/Lang/en/messages.mo index 4308a1686..3e410be2e 100644 Binary files a/gui/baculum/protected/API/Lang/en/messages.mo and b/gui/baculum/protected/API/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/API/Lang/en/messages.po b/gui/baculum/protected/API/Lang/en/messages.po index e1f21b03a..b7978cbe3 100644 --- a/gui/baculum/protected/API/Lang/en/messages.po +++ b/gui/baculum/protected/API/Lang/en/messages.po @@ -691,3 +691,6 @@ msgstr "Dedicated Bconsole config" msgid "Audit log:" msgstr "Audit log:" + +msgid "Interpret Bacula errors:" +msgstr "Interpret Bacula errors:" diff --git a/gui/baculum/protected/API/Lang/pl/messages.mo b/gui/baculum/protected/API/Lang/pl/messages.mo index b2b349dad..36e257dee 100644 Binary files a/gui/baculum/protected/API/Lang/pl/messages.mo and b/gui/baculum/protected/API/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/API/Lang/pl/messages.po b/gui/baculum/protected/API/Lang/pl/messages.po index a25f107d0..3ee6b39ac 100644 --- a/gui/baculum/protected/API/Lang/pl/messages.po +++ b/gui/baculum/protected/API/Lang/pl/messages.po @@ -697,3 +697,6 @@ msgstr "Dedykowana konfiguracja Bconsole" msgid "Audit log:" msgstr "Audit log:" + +msgid "Interpret Bacula errors:" +msgstr "Interpret Bacula errors:" diff --git a/gui/baculum/protected/API/Lang/pt/messages.mo b/gui/baculum/protected/API/Lang/pt/messages.mo index 410645c72..7417a22f5 100644 Binary files a/gui/baculum/protected/API/Lang/pt/messages.mo and b/gui/baculum/protected/API/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/API/Lang/pt/messages.po b/gui/baculum/protected/API/Lang/pt/messages.po index 1d4583c72..ecf231e86 100644 --- a/gui/baculum/protected/API/Lang/pt/messages.po +++ b/gui/baculum/protected/API/Lang/pt/messages.po @@ -698,3 +698,6 @@ msgstr "Configuração do Bconsole dedicado" msgid "Audit log:" msgstr "Audit log:" + +msgid "Interpret Bacula errors:" +msgstr "Interpret Bacula errors:" diff --git a/gui/baculum/protected/API/Lang/ru/messages.mo b/gui/baculum/protected/API/Lang/ru/messages.mo index e5e25c04d..388e16fed 100644 Binary files a/gui/baculum/protected/API/Lang/ru/messages.mo and b/gui/baculum/protected/API/Lang/ru/messages.mo differ diff --git a/gui/baculum/protected/API/Lang/ru/messages.po b/gui/baculum/protected/API/Lang/ru/messages.po index ef9f0a25d..c57c27041 100644 --- a/gui/baculum/protected/API/Lang/ru/messages.po +++ b/gui/baculum/protected/API/Lang/ru/messages.po @@ -698,3 +698,6 @@ msgstr "Выделенная Bconsole" msgid "Audit log:" msgstr "Audit log:" + +msgid "Interpret Bacula errors:" +msgstr "Interpret Bacula errors:" diff --git a/gui/baculum/protected/API/Modules/BaculaError.php b/gui/baculum/protected/API/Modules/BaculaError.php new file mode 100644 index 000000000..aabac5486 --- /dev/null +++ b/gui/baculum/protected/API/Modules/BaculaError.php @@ -0,0 +1,81 @@ + + * @category Error + * @package Baculum API + */ +class BaculaError extends APIModule { + + const DIRECTOR_ERROR_PATTERN = '/^\s*\[(?PD[A-Z]\d{4})\]/'; + const STORAGE_ERROR_PATTERN = '/^\s*\[(?PS[A-Z]\d{4})\]/'; + const CLIENT_ERROR_PATTERN = '/^\s*\[(?PF[A-Z]\d{4})\]/'; + const CONSOLE_ERROR_PATTERN = '/^\s*\[(?PC[A-Z]\d{4})\]/'; + + /** + * Find first error in output. + * + * @param array $output bconsole output + * @return array with code, error code and message + */ + public function checkForErrors($output) { + $code = null; + $error = BError::ERROR_NO_ERRORS; + $errmsg = BError::MSG_ERROR_NO_ERRORS; + for ($i = 0; $i < count($output); $i++) { + if (preg_match(self::DIRECTOR_ERROR_PATTERN, $output[$i], $match) === 1) { + $code = $match['code']; + $error = BError::ERROR_BACULA_DIRECTOR_ERROR; + $errmsg = BError::MSG_ERROR_BACULA_DIRECTOR_ERROR; + break; + } elseif (preg_match(self::STORAGE_ERROR_PATTERN, $output[$i], $match) === 1) { + $code = $match['code']; + $error = BError::ERROR_BACULA_STORAGE_ERROR; + $errmsg = BError::MSG_ERROR_BACULA_STORAGE_ERROR; + break; + } elseif (preg_match(self::CLIENT_ERROR_PATTERN, $output[$i], $match) === 1) { + $code = $match['code']; + $error = BError::ERROR_BACULA_CLIENT_ERROR; + $errmsg = BError::MSG_ERROR_BACULA_CLIENT_ERROR; + break; + } elseif (preg_match(self::CONSOLE_ERROR_PATTERN, $output[$i], $match) === 1) { + $code = $match['code']; + $error = BError::ERROR_BACULA_CONSOLE_ERROR; + $errmsg = BError::MSG_ERROR_BACULA_CONSOLE_ERROR; + break; + } + } + $result = [ + 'code' => $code, + 'error' => $error, + 'errmsg' => $errmsg + ]; + return $result; + } +} diff --git a/gui/baculum/protected/API/Modules/Bconsole.php b/gui/baculum/protected/API/Modules/Bconsole.php index acfa03ef4..a1b6c80da 100644 --- a/gui/baculum/protected/API/Modules/Bconsole.php +++ b/gui/baculum/protected/API/Modules/Bconsole.php @@ -185,7 +185,26 @@ class Bconsole extends APIModule { } } $output = array_values($output); - return (object)array('output' => $output, 'exitcode' => (integer)$exitcode); + $result = [ + 'output' => $output, + 'exitcode' => (integer)$exitcode + ]; + if (key_exists('interpret_bacula_errors', $this->config) && $this->config['interpret_bacula_errors'] == 1) { + $berror = $this->getModule('bacula_error')->checkForErrors($output); + if ($berror['error'] != 0) { + $result = [ + 'output' => sprintf( + 'Error: %s, BaculaCode: %s, APIError: %s, Output: %s', + $berror['errmsg'], + $berror['code'], + $berror['error'], + implode(PHP_EOL, $output) + ), + 'exitcode' => $berror['error'] + ]; + } + } + return (object)$result; } public function bconsoleCommand($director, array $command, $ptype = null, $without_cmd = false) { diff --git a/gui/baculum/protected/API/Pages/API/config.xml b/gui/baculum/protected/API/Pages/API/config.xml index a37b9b0eb..4f14a0ac6 100644 --- a/gui/baculum/protected/API/Pages/API/config.xml +++ b/gui/baculum/protected/API/Pages/API/config.xml @@ -59,6 +59,7 @@ + diff --git a/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php b/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php index cc038205a..cb7f0e4f1 100644 --- a/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php +++ b/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php @@ -205,6 +205,7 @@ class APIInstallWizard extends BaculumAPIPage { $cfg_data['bconsole']['bin_path'] = $this->BconsolePath->Text; $cfg_data['bconsole']['cfg_path'] = $this->BconsoleConfigPath->Text; $cfg_data['bconsole']['use_sudo'] = (integer)($this->UseSudo->Checked === true); + $cfg_data['bconsole']['interpret_bacula_errors'] = 1; // it is enabled by default; $cfg_data['jsontools']['enabled'] = (integer)($this->ConfigYes->Checked === true); $cfg_data['jsontools']['use_sudo'] = (integer)($this->BJSONUseSudo->Checked === true); $cfg_data['jsontools']['bconfig_dir'] = $this->BConfigDir->Text; diff --git a/gui/baculum/protected/API/Pages/Panel/APISettings.page b/gui/baculum/protected/API/Pages/Panel/APISettings.page index 724d0489c..c07b91324 100644 --- a/gui/baculum/protected/API/Pages/Panel/APISettings.page +++ b/gui/baculum/protected/API/Pages/Panel/APISettings.page @@ -368,6 +368,20 @@ +
+
+ +
+
+ +
+
diff --git a/gui/baculum/protected/API/Pages/Panel/APISettings.php b/gui/baculum/protected/API/Pages/Panel/APISettings.php index 6009e53df..cfeea719e 100644 --- a/gui/baculum/protected/API/Pages/Panel/APISettings.php +++ b/gui/baculum/protected/API/Pages/Panel/APISettings.php @@ -92,6 +92,12 @@ class APISettings extends BaculumAPIPage { $this->BconsolePath->Text = $this->config['bconsole']['bin_path']; $this->BconsoleConfigPath->Text = $this->config['bconsole']['cfg_path']; $this->BconsoleUseSudo->Checked = ($this->config['bconsole']['use_sudo'] == 1); + if (key_exists('interpret_bacula_errors', $this->config['bconsole'])) { + $this->BconsoleInterpretBaculaErrors->Checked = ($this->config['bconsole']['interpret_bacula_errors'] == 1); + } else { + // Default value if option not specified + $this->BconsoleInterpretBaculaErrors->Checked = true; + } } private function loadConfigSettings() { @@ -423,7 +429,8 @@ class APISettings extends BaculumAPIPage { 'enabled' => ($this->BconsoleEnabled->Checked ? 1 : 0), 'bin_path' => $this->BconsolePath->Text, 'cfg_path' => $this->BconsoleConfigPath->Text, - 'use_sudo' => ($this->BconsoleUseSudo->Checked ? 1 : 0) + 'use_sudo' => ($this->BconsoleUseSudo->Checked ? 1 : 0), + 'interpret_bacula_errors' => ($this->BconsoleInterpretBaculaErrors->Checked ? 1 : 0) ]; $this->config['bconsole'] = $cfg; $this->getModule('api_config')->setConfig($this->config); diff --git a/gui/baculum/protected/Common/Modules/Errors/BaculaError.php b/gui/baculum/protected/Common/Modules/Errors/BaculaError.php new file mode 100644 index 000000000..be6ea87e8 --- /dev/null +++ b/gui/baculum/protected/Common/Modules/Errors/BaculaError.php @@ -0,0 +1,43 @@ + + * @category Errors + * @package Baculum Common + */ +class BaculaError extends GenericError { + + const ERROR_BACULA_DIRECTOR_ERROR = 600; + const ERROR_BACULA_STORAGE_ERROR = 601; + const ERROR_BACULA_CLIENT_ERROR = 602; + const ERROR_BACULA_CONSOLE_ERROR = 603; + + const MSG_ERROR_BACULA_DIRECTOR_ERROR = 'Bacula Director error.'; + const MSG_ERROR_BACULA_STORAGE_ERROR = 'Bacula Storage error.'; + const MSG_ERROR_BACULA_CLIENT_ERROR = 'Bacula Client error.'; + const MSG_ERROR_BACULA_CONSOLE_ERROR = 'Bacula Console error.'; +}