mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
parent
ec6948dddf
commit
2f05ed3d49
63
modules/monitoring/application/forms/Setup/BackendPage.php
Normal file
63
modules/monitoring/application/forms/Setup/BackendPage.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
use Icinga\Application\Platform;
|
||||||
|
|
||||||
|
class BackendPage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_backend');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'Please configure below how Icinga Web 2 should retrieve monitoring information.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'text',
|
||||||
|
'name',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => mt('monitoring', 'Backend Name'),
|
||||||
|
'description' => mt('monitoring', 'The identifier of this backend')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$resourceTypes = array('livestatus' => 'Livestatus');
|
||||||
|
if (
|
||||||
|
Platform::extensionLoaded('pdo') && (
|
||||||
|
Platform::zendClassExists('Zend_Db_Adapter_Pdo_Mysql')
|
||||||
|
|| Platform::zendClassExists('Zend_Db_Adapter_Pdo_Pgsql')
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
$resourceTypes['ido'] = 'IDO';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'select',
|
||||||
|
'type',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => mt('monitoring', 'Backend Type'),
|
||||||
|
'description' => mt('monitoring', 'The data source used for retrieving monitoring information'),
|
||||||
|
'multiOptions' => $resourceTypes
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
use Icinga\Form\Config\Resource\DbResourceForm;
|
||||||
|
|
||||||
|
class IdoResourcePage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_ido');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'type',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'value' => 'db'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'Please fill out the connection details below to access'
|
||||||
|
. ' the IDO database of your monitoring environment.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($formData['skip_validation']) && $formData['skip_validation']) {
|
||||||
|
$this->addSkipValidationCheckbox();
|
||||||
|
} else {
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'skip_validation',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'value' => 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$livestatusResourceForm = new DbResourceForm();
|
||||||
|
$this->addElements($livestatusResourceForm->createElements($formData)->getElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid($data)
|
||||||
|
{
|
||||||
|
if (false === parent::isValid($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
||||||
|
if (false === DbResourceForm::isValidResource($this)) {
|
||||||
|
$this->addSkipValidationCheckbox();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a checkbox to the form by which the user can skip the connection validation
|
||||||
|
*/
|
||||||
|
protected function addSkipValidationCheckbox()
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
'skip_validation',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Skip Validation'),
|
||||||
|
'description' => t('Check this to not to validate connectivity with the given database server')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
40
modules/monitoring/application/forms/Setup/InstancePage.php
Normal file
40
modules/monitoring/application/forms/Setup/InstancePage.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
use Icinga\Module\Monitoring\Form\Config\InstanceConfigForm;
|
||||||
|
|
||||||
|
class InstancePage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_instance');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'Please define the settings specific to your monitoring instance below.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($formData['host'])) {
|
||||||
|
$formData['type'] = 'remote'; // This is necessary as the type element gets ignored by Form::getValues()
|
||||||
|
}
|
||||||
|
|
||||||
|
$instanceConfigForm = new InstanceConfigForm();
|
||||||
|
$instanceConfigForm->createElements($formData);
|
||||||
|
$this->addElements($instanceConfigForm->getElements());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
use Icinga\Form\Config\Resource\LivestatusResourceForm;
|
||||||
|
|
||||||
|
class LivestatusResourcePage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_livestatus');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'type',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'value' => 'livestatus'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'Please fill out the connection details below to access the Livestatus'
|
||||||
|
. ' socket interface for your monitoring environment.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($formData['skip_validation']) && $formData['skip_validation']) {
|
||||||
|
$this->addSkipValidationCheckbox();
|
||||||
|
} else {
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'skip_validation',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'value' => 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$livestatusResourceForm = new LivestatusResourceForm();
|
||||||
|
$this->addElements($livestatusResourceForm->createElements($formData)->getElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid($data)
|
||||||
|
{
|
||||||
|
if (false === parent::isValid($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
||||||
|
if (false === LivestatusResourceForm::isValidResource($this)) {
|
||||||
|
$this->addSkipValidationCheckbox();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a checkbox to the form by which the user can skip the connection validation
|
||||||
|
*/
|
||||||
|
protected function addSkipValidationCheckbox()
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
'skip_validation',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Skip Validation'),
|
||||||
|
'description' => t('Check this to not to validate connectivity with the given Livestatus socket')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
36
modules/monitoring/application/forms/Setup/SecurityPage.php
Normal file
36
modules/monitoring/application/forms/Setup/SecurityPage.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
use Icinga\Module\Monitoring\Form\Config\SecurityConfigForm;
|
||||||
|
|
||||||
|
class SecurityPage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_security');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'To protect your monitoring environment against prying eyes please fill out the settings below.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$securityConfigForm = new SecurityConfigForm();
|
||||||
|
$securityConfigForm->createElements($formData);
|
||||||
|
$this->addElements($securityConfigForm->getElements());
|
||||||
|
}
|
||||||
|
}
|
65
modules/monitoring/application/forms/Setup/WelcomePage.php
Normal file
65
modules/monitoring/application/forms/Setup/WelcomePage.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Element\Note;
|
||||||
|
|
||||||
|
class WelcomePage extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('setup_monitoring_welcome');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'welcome',
|
||||||
|
array(
|
||||||
|
'value' => mt('monitoring', 'Welcome to the installation of the monitoring module for Icinga Web 2!'),
|
||||||
|
'decorators' => array(
|
||||||
|
'ViewHelper',
|
||||||
|
array('HtmlTag', array('tag' => 'h2'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'core_hint',
|
||||||
|
array(
|
||||||
|
'value' => mt('monitoring', 'This is the core module for Icinga Web 2.')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
new Note(
|
||||||
|
'description',
|
||||||
|
array(
|
||||||
|
'value' => mt(
|
||||||
|
'monitoring',
|
||||||
|
'It offers various status and reporting views with powerful filter capabilities that allow'
|
||||||
|
. ' you to keep track of the most important events in your monitoring environment.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addDisplayGroup(
|
||||||
|
array('core_hint', 'description'),
|
||||||
|
'info',
|
||||||
|
array(
|
||||||
|
'decorators' => array(
|
||||||
|
'FormElements',
|
||||||
|
array('HtmlTag', array('tag' => 'div', 'class' => 'info'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Installation;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Zend_Config;
|
||||||
|
use Icinga\Web\Setup\Step;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Config\PreservingIniWriter;
|
||||||
|
|
||||||
|
class BackendStep extends Step
|
||||||
|
{
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
protected $backendIniError;
|
||||||
|
|
||||||
|
protected $resourcesIniError;
|
||||||
|
|
||||||
|
public function __construct(array $data)
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply()
|
||||||
|
{
|
||||||
|
$success = $this->createBackendsIni();
|
||||||
|
$success &= $this->createResourcesIni();
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createBackendsIni()
|
||||||
|
{
|
||||||
|
$config = array();
|
||||||
|
$config[$this->data['backendConfig']['name']] = array(
|
||||||
|
'type' => $this->data['backendConfig']['type'],
|
||||||
|
'resource' => $this->data['resourceConfig']['name']
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => new Zend_Config($config),
|
||||||
|
'filename' => Config::resolvePath('modules/monitoring/backends.ini'),
|
||||||
|
'filemode' => octdec($this->data['fileMode'])
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->backendIniError = $e;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->backendIniError = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createResourcesIni()
|
||||||
|
{
|
||||||
|
$resourceConfig = $this->data['resourceConfig'];
|
||||||
|
$resourceName = $resourceConfig['name'];
|
||||||
|
unset($resourceConfig['name']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$config = Config::app('resources', true);
|
||||||
|
$config->merge(new Zend_Config(array($resourceName => $resourceConfig)));
|
||||||
|
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => $config,
|
||||||
|
'filename' => Config::resolvePath('resources.ini'),
|
||||||
|
'filemode' => octdec($this->data['fileMode'])
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->resourcesIniError = $e;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->resourcesIniError = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummary()
|
||||||
|
{
|
||||||
|
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Backend') . '</h2>';
|
||||||
|
$backendDescription = '<p>' . sprintf(
|
||||||
|
mt(
|
||||||
|
'monitoring',
|
||||||
|
'Icinga Web 2 will retrieve information from your monitoring environment'
|
||||||
|
. ' using a backend called "%s" and the specified resource below:'
|
||||||
|
),
|
||||||
|
$this->data['backendConfig']['name']
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
|
if ($this->data['resourceConfig']['type'] === 'db') {
|
||||||
|
$resourceTitle = '<h3>' . mt('monitoring', 'Database Resource') . '</h3>';
|
||||||
|
$resourceHtml = ''
|
||||||
|
. '<table>'
|
||||||
|
. '<tbody>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Resource Name') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['name'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Database Type') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['db'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Host') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['host'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Port') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['port'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Database Name') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['dbname'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Username') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['username'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Password') . '</strong></td>'
|
||||||
|
. '<td>' . str_repeat('*', strlen($this->data['resourceConfig']['password'])) . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '</tbody>'
|
||||||
|
. '</table>';
|
||||||
|
} else { // $this->data['resourceConfig']['type'] === 'livestatus'
|
||||||
|
$resourceTitle = '<h3>' . mt('monitoring', 'Livestatus Resource') . '</h3>';
|
||||||
|
$resourceHtml = ''
|
||||||
|
. '<table>'
|
||||||
|
. '<tbody>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Resource Name') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['name'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . t('Socket') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['resourceConfig']['socket'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '</tbody>'
|
||||||
|
. '</table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pageTitle . '<div class="topic">' . $backendDescription . $resourceTitle . $resourceHtml . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReport()
|
||||||
|
{
|
||||||
|
$report = '';
|
||||||
|
if ($this->backendIniError === false) {
|
||||||
|
$message = mt('monitoring', 'Monitoring backend configuration has been successfully written to: %s');
|
||||||
|
$report .= '<p>' . sprintf($message, Config::resolvePath('modules/monitoring/backends.ini')) . '</p>';
|
||||||
|
} elseif ($this->backendIniError !== null) {
|
||||||
|
$message = mt(
|
||||||
|
'monitoring',
|
||||||
|
'Monitoring backend configuration could not be written to: %s; An error occured:'
|
||||||
|
);
|
||||||
|
$report .= '<p class="error">' . sprintf(
|
||||||
|
$message,
|
||||||
|
Config::resolvePath('modules/monitoring/backends.ini')
|
||||||
|
) . '</p><p>' . $this->backendIniError->getMessage() . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->resourcesIniError === false) {
|
||||||
|
$message = mt('monitoring', 'Resource configuration has been successfully updated: %s');
|
||||||
|
$report .= '<p>' . sprintf($message, Config::resolvePath('resources.ini')) . '</p>';
|
||||||
|
} elseif ($this->resourcesIniError !== null) {
|
||||||
|
$message = mt('monitoring', 'Resource configuration could not be udpated: %s; An error occured:');
|
||||||
|
$report .= '<p class="error">' . sprintf($message, Config::resolvePath('resources.ini')) . '</p>'
|
||||||
|
. '<p>' . $this->resourcesIniError->getMessage() . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Installation;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Zend_Config;
|
||||||
|
use Icinga\Web\Setup\Step;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Config\PreservingIniWriter;
|
||||||
|
|
||||||
|
class InstanceStep extends Step
|
||||||
|
{
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
protected $error;
|
||||||
|
|
||||||
|
public function __construct(array $data)
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply()
|
||||||
|
{
|
||||||
|
$instanceConfig = $this->data['instanceConfig'];
|
||||||
|
$instanceName = $instanceConfig['name'];
|
||||||
|
unset($instanceConfig['name']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => new Zend_Config(array($instanceName => $instanceConfig)),
|
||||||
|
'filename' => Config::resolvePath('modules/monitoring/instances.ini'),
|
||||||
|
'filemode' => octdec($this->data['fileMode'])
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->error = $e;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->error = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummary()
|
||||||
|
{
|
||||||
|
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Instance') . '</h2>';
|
||||||
|
|
||||||
|
if (isset($this->data['instanceConfig']['host'])) {
|
||||||
|
$pipeHtml = '<p>' . 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['instanceConfig']['path']
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
|
$pipeHtml .= ''
|
||||||
|
. '<table>'
|
||||||
|
. '<tbody>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . mt('monitoring', 'Remote Host') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['instanceConfig']['host'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . mt('monitoring', 'Remote SSH Port') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['instanceConfig']['port'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . mt('monitoring', 'Remote SSH User') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['instanceConfig']['user'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '</tbody>'
|
||||||
|
. '</table>';
|
||||||
|
} else {
|
||||||
|
$pipeHtml = '<p>' . sprintf(
|
||||||
|
mt(
|
||||||
|
'monitoring',
|
||||||
|
'Icinga Web 2 will use the named pipe located at "%s"'
|
||||||
|
. ' to send commands to your monitoring instance.'
|
||||||
|
),
|
||||||
|
$this->data['instanceConfig']['path']
|
||||||
|
) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pageTitle . '<div class="topic">' . $pipeHtml . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReport()
|
||||||
|
{
|
||||||
|
if ($this->error === false) {
|
||||||
|
$message = mt('monitoring', 'Monitoring instance configuration has been successfully created: %s');
|
||||||
|
return '<p>' . sprintf($message, Config::resolvePath('modules/monitoring/instances.ini')) . '</p>';
|
||||||
|
} elseif ($this->error !== null) {
|
||||||
|
$message = mt(
|
||||||
|
'monitoring',
|
||||||
|
'Monitoring instance configuration could not be written to: %s; An error occured:'
|
||||||
|
);
|
||||||
|
return '<p class="error">' . sprintf($message, Config::resolvePath('modules/monitoring/instances.ini'))
|
||||||
|
. '</p><p>' . $this->error->getMessage() . '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Installation;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Zend_Config;
|
||||||
|
use Icinga\Web\Setup\Step;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Config\PreservingIniWriter;
|
||||||
|
|
||||||
|
class SecurityStep extends Step
|
||||||
|
{
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
protected $error;
|
||||||
|
|
||||||
|
public function __construct(array $data)
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply()
|
||||||
|
{
|
||||||
|
$config = array();
|
||||||
|
$config['security'] = $this->data['securityConfig'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => new Zend_Config($config),
|
||||||
|
'filename' => Config::resolvePath('modules/monitoring/config.ini'),
|
||||||
|
'filemode' => octdec($this->data['fileMode'])
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->error = $e;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->error = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummary()
|
||||||
|
{
|
||||||
|
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Security') . '</h2>';
|
||||||
|
$pageDescription = '<p>' . mt(
|
||||||
|
'monitoring',
|
||||||
|
'Icinga Web 2 will protect your monitoring environment against'
|
||||||
|
. ' prying eyes using the configuration specified below:'
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
|
$pageHtml = ''
|
||||||
|
. '<table>'
|
||||||
|
. '<tbody>'
|
||||||
|
. '<tr>'
|
||||||
|
. '<td><strong>' . mt('monitoring', 'Protected Custom Variables') . '</strong></td>'
|
||||||
|
. '<td>' . $this->data['securityConfig']['protected_customvars'] . '</td>'
|
||||||
|
. '</tr>'
|
||||||
|
. '</tbody>'
|
||||||
|
. '</table>';
|
||||||
|
|
||||||
|
return $pageTitle . '<div class="topic">' . $pageDescription . $pageHtml . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReport()
|
||||||
|
{
|
||||||
|
if ($this->error === false) {
|
||||||
|
$message = mt('monitoring', 'Monitoring security configuration has been successfully created: %s');
|
||||||
|
return '<p>' . sprintf($message, Config::resolvePath('modules/monitoring/config.ini')) . '</p>';
|
||||||
|
} elseif ($this->error !== null) {
|
||||||
|
$message = mt(
|
||||||
|
'monitoring',
|
||||||
|
'Monitoring security configuration could not be written to: %s; An error occured:'
|
||||||
|
);
|
||||||
|
return '<p class="error">' . sprintf($message, Config::resolvePath('modules/monitoring/config.ini'))
|
||||||
|
. '</p><p>' . $this->error->getMessage() . '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
192
modules/monitoring/library/Monitoring/Setup.php
Normal file
192
modules/monitoring/library/Monitoring/Setup.php
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Wizard;
|
||||||
|
use Icinga\Web\Request;
|
||||||
|
use Icinga\Web\Setup\Installer;
|
||||||
|
use Icinga\Web\Setup\MakeDirStep;
|
||||||
|
use Icinga\Web\Setup\EnableModuleStep;
|
||||||
|
use Icinga\Web\Setup\SetupWizard;
|
||||||
|
use Icinga\Web\Setup\Requirements;
|
||||||
|
use Icinga\Module\Monitoring\Installation\BackendStep;
|
||||||
|
use Icinga\Module\Monitoring\Installation\InstanceStep;
|
||||||
|
use Icinga\Module\Monitoring\Installation\SecurityStep;
|
||||||
|
use Icinga\Form\Setup\SummaryPage;
|
||||||
|
use Icinga\Form\Setup\RequirementsPage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\WelcomePage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\BackendPage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\InstancePage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\SecurityPage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\IdoResourcePage;
|
||||||
|
use Icinga\Module\Monitoring\Form\Setup\LivestatusResourcePage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitoring Module Setup Wizard
|
||||||
|
*/
|
||||||
|
class Setup extends Wizard implements SetupWizard
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see Wizard::init()
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->addPage(new WelcomePage());
|
||||||
|
$this->addPage(new RequirementsPage());
|
||||||
|
$this->addPage(new BackendPage());
|
||||||
|
$this->addPage(new IdoResourcePage());
|
||||||
|
$this->addPage(new LivestatusResourcePage());
|
||||||
|
$this->addPage(new InstancePage());
|
||||||
|
$this->addPage(new SecurityPage());
|
||||||
|
$this->addPage(new SummaryPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Wizard::setupPage()
|
||||||
|
*/
|
||||||
|
public function setupPage(Form $page, Request $request)
|
||||||
|
{
|
||||||
|
if ($page->getName() === 'setup_requirements') {
|
||||||
|
$page->setRequirements($this->getRequirements());
|
||||||
|
} elseif ($page->getName() === 'setup_summary') {
|
||||||
|
$page->setSummary($this->getInstaller()->getSummary());
|
||||||
|
$page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject'));
|
||||||
|
} elseif (
|
||||||
|
$this->getDirection() === static::FORWARD
|
||||||
|
&& ($page->getName() === 'setup_monitoring_ido' || $page->getName() === 'setup_monitoring_livestatus')
|
||||||
|
) {
|
||||||
|
if ((($dbResourceData = $this->getPageData('setup_db_resource')) !== null
|
||||||
|
&& $dbResourceData['name'] === $request->getPost('name'))
|
||||||
|
|| (($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null
|
||||||
|
&& $ldapResourceData['name'] === $request->getPost('name'))
|
||||||
|
) {
|
||||||
|
$page->addError(mt('monitoring', 'The given resource name is already in use.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Wizard::getNewPage()
|
||||||
|
*/
|
||||||
|
protected function getNewPage($requestedPage, Form $originPage)
|
||||||
|
{
|
||||||
|
$skip = false;
|
||||||
|
$newPage = parent::getNewPage($requestedPage, $originPage);
|
||||||
|
if ($newPage->getName() === 'setup_monitoring_ido') {
|
||||||
|
$backendData = $this->getPageData('setup_monitoring_backend');
|
||||||
|
$skip = $backendData['type'] !== 'ido';
|
||||||
|
} elseif ($newPage->getName() === 'setup_monitoring_livestatus') {
|
||||||
|
$backendData = $this->getPageData('setup_monitoring_backend');
|
||||||
|
$skip = $backendData['type'] !== 'livestatus';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($skip) {
|
||||||
|
if ($this->hasPageData($newPage->getName())) {
|
||||||
|
$pageData = & $this->getPageData();
|
||||||
|
unset($pageData[$newPage->getName()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pages = $this->getPages();
|
||||||
|
if ($this->getDirection() === static::FORWARD) {
|
||||||
|
$nextPage = $pages[array_search($newPage, $pages, true) + 1];
|
||||||
|
$newPage = $this->getNewPage($nextPage->getName(), $newPage);
|
||||||
|
} else { // $this->getDirection() === static::BACKWARD
|
||||||
|
$previousPage = $pages[array_search($newPage, $pages, true) - 1];
|
||||||
|
$newPage = $this->getNewPage($previousPage->getName(), $newPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Wizard::addButtons()
|
||||||
|
*/
|
||||||
|
protected function addButtons(Form $page)
|
||||||
|
{
|
||||||
|
parent::addButtons($page);
|
||||||
|
|
||||||
|
$pages = $this->getPages();
|
||||||
|
$index = array_search($page, $pages, true);
|
||||||
|
if ($index === 0) {
|
||||||
|
// Used t() here as "Start" is too generic and already translated in the icinga domain
|
||||||
|
$page->getElement(static::BTN_NEXT)->setLabel(t('Start', 'setup.welcome.btn.next'));
|
||||||
|
} elseif ($index === count($pages) - 1) {
|
||||||
|
$page->getElement(static::BTN_NEXT)->setLabel(
|
||||||
|
mt('monitoring', 'Install the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SetupWizard::getInstaller()
|
||||||
|
*/
|
||||||
|
public function getInstaller()
|
||||||
|
{
|
||||||
|
$pageData = $this->getPageData();
|
||||||
|
$installer = new Installer();
|
||||||
|
|
||||||
|
$installer->addStep(
|
||||||
|
new MakeDirStep(
|
||||||
|
array($this->getConfigDir() . '/modules/monitoring'),
|
||||||
|
$pageData['setup_general_config']['global_filemode']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$installer->addStep(
|
||||||
|
new BackendStep(array(
|
||||||
|
'backendConfig' => $pageData['setup_monitoring_backend'],
|
||||||
|
'resourceConfig' => isset($pageData['setup_monitoring_ido'])
|
||||||
|
? array_diff_key($pageData['setup_monitoring_ido'], array('skip_validation' => null))
|
||||||
|
: array_diff_key($pageData['setup_monitoring_livestatus'], array('skip_validation' => null)),
|
||||||
|
'fileMode' => $pageData['setup_general_config']['global_filemode']
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
$installer->addStep(
|
||||||
|
new InstanceStep(array(
|
||||||
|
'instanceConfig' => $pageData['setup_monitoring_instance'],
|
||||||
|
'fileMode' => $pageData['setup_general_config']['global_filemode']
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
$installer->addStep(
|
||||||
|
new SecurityStep(array(
|
||||||
|
'securityConfig' => $pageData['setup_monitoring_security'],
|
||||||
|
'fileMode' => $pageData['setup_general_config']['global_filemode']
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
$installer->addStep(new EnableModuleStep('monitoring'));
|
||||||
|
|
||||||
|
return $installer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SetupWizard::getRequirements()
|
||||||
|
*/
|
||||||
|
public function getRequirements()
|
||||||
|
{
|
||||||
|
return new Requirements();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the configuration directory of Icinga Web 2
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getConfigDir()
|
||||||
|
{
|
||||||
|
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) {
|
||||||
|
$configDir = $_SERVER['ICINGAWEB_CONFIGDIR'];
|
||||||
|
} else {
|
||||||
|
$configDir = '/etc/icingaweb';
|
||||||
|
}
|
||||||
|
|
||||||
|
$canonical = realpath($configDir);
|
||||||
|
return $canonical ? $canonical : $configDir;
|
||||||
|
}
|
||||||
|
}
|
@ -149,8 +149,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#setup table.requirements {
|
#setup table.requirements {
|
||||||
margin-top: -1em;
|
margin: -1em -1em 0;
|
||||||
margin-left: -1em;
|
|
||||||
border-spacing: 1em;
|
border-spacing: 1em;
|
||||||
border-collapse: separate;
|
border-collapse: separate;
|
||||||
|
|
||||||
@ -300,6 +299,7 @@
|
|||||||
|
|
||||||
div.info {
|
div.info {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
max-width: 66%;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
border-radius: 1em;
|
border-radius: 1em;
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
@ -346,6 +346,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#setup_monitoring_welcome {
|
||||||
|
.welcome-page;
|
||||||
|
margin-top: 0;
|
||||||
|
padding: 1em;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#setup {
|
#setup {
|
||||||
div.module-wizard {
|
div.module-wizard {
|
||||||
width: auto;
|
width: auto;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user