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;
|
2015-07-24 14:24:11 +02:00
|
|
|
use Icinga\Forms\Config\ResourceConfigForm;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\Resource\DbResourceForm;
|
2015-06-29 15:03:46 +02:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
|
|
|
class IdoResourcePage extends Form
|
|
|
|
{
|
2015-06-29 15:03:46 +02:00
|
|
|
/**
|
|
|
|
* Initialize this form
|
|
|
|
*/
|
2014-10-29 15:40:34 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-06-29 15:03:46 +02:00
|
|
|
/**
|
|
|
|
* Create and add elements to this form
|
|
|
|
*
|
|
|
|
* @param array $formData
|
|
|
|
*/
|
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']) {
|
2015-06-29 15:03:46 +02:00
|
|
|
// In case another error occured and the checkbox was displayed before
|
2014-10-29 15:40:34 +01:00
|
|
|
$this->addSkipValidationCheckbox();
|
|
|
|
} else {
|
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
|
|
|
'skip_validation',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'value' => 0
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-29 15:03:46 +02:00
|
|
|
$dbResourceForm = new DbResourceForm();
|
|
|
|
$this->addElements($dbResourceForm->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
|
|
|
}
|
|
|
|
|
2015-06-29 15:03:46 +02:00
|
|
|
/**
|
|
|
|
* Return whether the given values are valid
|
|
|
|
*
|
|
|
|
* @param array $formData The data to validate
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isValid($formData)
|
2014-10-29 15:40:34 +01:00
|
|
|
{
|
2015-06-29 15:03:46 +02:00
|
|
|
if (! parent::isValid($formData)) {
|
2014-10-29 15:40:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-29 15:03:46 +02:00
|
|
|
if (! isset($formData['skip_validation']) || !$formData['skip_validation']) {
|
2015-07-24 14:24:11 +02:00
|
|
|
$inspection = ResourceConfigForm::inspectResource($this);
|
|
|
|
if ($inspection !== null && $inspection->hasError()) {
|
|
|
|
$this->error($inspection->getError());
|
2015-05-15 15:49:57 +02:00
|
|
|
$this->addSkipValidationCheckbox($this->translate(
|
2015-06-29 15:03:46 +02:00
|
|
|
'Check this to not to validate connectivity with the given database server.'
|
2015-05-15 15:49:57 +02:00
|
|
|
));
|
2015-05-11 10:32:34 +02:00
|
|
|
return false;
|
2015-07-24 14:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$configObject = new ConfigObject($this->getValues());
|
|
|
|
if (
|
2015-06-29 15:03:46 +02:00
|
|
|
! BackendConfigForm::isValidIdoSchema($this, $configObject)
|
|
|
|
|| !BackendConfigForm::isValidIdoInstance($this, $configObject)
|
|
|
|
) {
|
2015-05-15 15:49:57 +02:00
|
|
|
$this->addSkipValidationCheckbox($this->translate(
|
2015-06-29 15:03:46 +02:00
|
|
|
'Check this to not to validate the IDO schema in the given database.'
|
2015-05-15 15:49:57 +02:00
|
|
|
));
|
2014-10-29 15:40:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-29 15:03:46 +02:00
|
|
|
* Add a checkbox to the form by which the user can skip the resource validation
|
|
|
|
*
|
|
|
|
* @param string $description
|
2014-10-29 15:40:34 +01:00
|
|
|
*/
|
2015-06-29 15:03:46 +02:00
|
|
|
protected function addSkipValidationCheckbox($description = null)
|
2014-10-29 15:40:34 +01:00
|
|
|
{
|
2015-05-15 15:49:57 +02:00
|
|
|
if (empty($description)) {
|
|
|
|
$description = $this->translate(
|
2015-06-29 15:03:46 +02:00
|
|
|
'Proceed without any further (custom) validation.'
|
2015-05-15 15:49:57 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|