From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../library/Monitoring/TransportStep.php | 143 +++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/TransportStep.php (limited to 'modules/monitoring/library/Monitoring/TransportStep.php') diff --git a/modules/monitoring/library/Monitoring/TransportStep.php b/modules/monitoring/library/Monitoring/TransportStep.php new file mode 100644 index 0000000..d138eb4 --- /dev/null +++ b/modules/monitoring/library/Monitoring/TransportStep.php @@ -0,0 +1,143 @@ +data = $data; + } + + public function apply() + { + $transportConfig = $this->data['transportConfig']; + $transportName = $transportConfig['name']; + unset($transportConfig['name']); + + try { + Config::fromArray(array($transportName => $transportConfig)) + ->setConfigFile(Config::resolvePath('modules/monitoring/commandtransports.ini')) + ->saveIni(); + } catch (Exception $e) { + $this->error = $e; + return false; + } + + $this->error = false; + return true; + } + + public function getSummary() + { + switch ($this->data['transportConfig']['transport']) { + case 'local': + $details = '

' . sprintf( + mt( + 'monitoring', + 'Icinga Web 2 will use the named pipe located at "%s"' + . ' to send commands to your monitoring instance.' + ), + $this->data['transportConfig']['path'] + ) . '

'; + break; + case 'remote': + $details = '

' + . sprintf( + mt( + 'monitoring', + 'Icinga Web 2 will use the named pipe located on a remote machine at "%s" to send commands' + . ' to your monitoring instance by using the connection details listed below:' + ), + $this->data['transportConfig']['path'] + ) + . '

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
' . mt('monitoring', 'Remote Host') . '' . $this->data['transportConfig']['host'] . '
' . mt('monitoring', 'Remote SSH Port') . '' . $this->data['transportConfig']['port'] . '
' . mt('monitoring', 'Remote SSH User') . '' . $this->data['transportConfig']['user'] . '
'; + break; + case 'api': + $details = '

' + . mt( + 'monitoring', + 'Icinga Web 2 will use the Icinga 2 API to send commands' + . ' to your monitoring instance by using the connection details listed below:' + ) + . '

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
' . mt('monitoring', 'Host') . '' . $this->data['transportConfig']['host'] . '
' . mt('monitoring', 'Port') . '' . $this->data['transportConfig']['port'] . '
' . mt('monitoring', 'Username') . '' . $this->data['transportConfig']['username'] . '
' . mt('monitoring', 'Password') . '' . str_repeat('*', strlen($this->data['transportConfig']['password'])) . '
'; + break; + default: + throw new ProgrammingError( + 'Unknown command transport type: %s', + $this->data['transportConfig']['transport'] + ); + } + + return '

' . mt('monitoring', 'Command Transport', 'setup.page.title') . '

' + . '
' . $details . '
'; + } + + public function getReport() + { + if ($this->error === false) { + return array(sprintf( + mt('monitoring', 'Command transport configuration has been successfully created: %s'), + Config::resolvePath('modules/monitoring/commandtransports.ini') + )); + } elseif ($this->error !== null) { + return array( + sprintf( + mt( + 'monitoring', + 'Command transport configuration could not be written to: %s. An error occured:' + ), + Config::resolvePath('modules/monitoring/commandtransports.ini') + ), + sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error)) + ); + } + } +} -- cgit v1.2.3