2014-10-29 15:40:34 +01:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-10-29 15:40:34 +01:00
|
|
|
|
2014-11-14 11:17:22 +01:00
|
|
|
namespace Icinga\Module\Monitoring\Forms\Setup;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
2015-05-11 10:32:34 +02:00
|
|
|
use Icinga\Data\ConfigObject;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
2014-10-29 15:40:34 +01:00
|
|
|
use Icinga\Web\Form;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\Resource\DbResourceForm;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
|
|
|
class IdoResourcePage extends Form
|
|
|
|
{
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('setup_monitoring_ido');
|
2015-03-02 18:36:04 +01:00
|
|
|
$this->setTitle($this->translate('Monitoring IDO Resource', 'setup.page.title'));
|
|
|
|
$this->addDescription($this->translate(
|
|
|
|
'Please fill out the connection details below to access the IDO database of your monitoring environment.'
|
|
|
|
));
|
2014-10-29 15:40:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
|
|
|
'type',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'value' => 'db'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
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());
|
2014-11-11 12:41:02 +01:00
|
|
|
$this->getElement('name')->setValue('icinga_ido');
|
2014-10-29 15:40:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isValid($data)
|
|
|
|
{
|
|
|
|
if (false === parent::isValid($data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
2015-05-11 10:32:34 +02:00
|
|
|
$configObject = new ConfigObject($this->getValues());
|
|
|
|
if (false === DbResourceForm::isValidResource($this, $configObject)) {
|
2015-05-15 15:49:57 +02:00
|
|
|
$this->addSkipValidationCheckbox($this->translate(
|
|
|
|
'Check this to not to validate connectivity with the given database server'
|
|
|
|
));
|
2015-05-11 10:32:34 +02:00
|
|
|
return false;
|
|
|
|
} elseif (false === BackendConfigForm::isValidIdoSchema($this, $configObject)) {
|
2015-05-15 15:49:57 +02:00
|
|
|
$this->addSkipValidationCheckbox($this->translate(
|
|
|
|
'Check this to not to validate the ido schema'
|
|
|
|
));
|
2015-05-11 10:32:34 +02:00
|
|
|
return false;
|
|
|
|
} elseif (false === BackendConfigForm::isValidIdoInstance($this, $configObject)) {
|
2015-05-15 15:49:57 +02:00
|
|
|
$this->addSkipValidationCheckbox($this->translate(
|
|
|
|
'Check this to not to validate the ido instance'
|
|
|
|
));
|
2014-10-29 15:40:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a checkbox to the form by which the user can skip the connection validation
|
|
|
|
*/
|
2015-05-15 15:49:57 +02:00
|
|
|
protected function addSkipValidationCheckbox($description = '')
|
2014-10-29 15:40:34 +01:00
|
|
|
{
|
2015-05-15 15:49:57 +02:00
|
|
|
if (empty($description)) {
|
|
|
|
$description = $this->translate(
|
|
|
|
'Proceed without any further (custom) validation'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:40:34 +01:00
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'skip_validation',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 13:47:01 +01:00
|
|
|
'label' => $this->translate('Skip Validation'),
|
2015-05-15 15:49:57 +02:00
|
|
|
'description' => $description
|
2014-10-29 15:40:34 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|