parent
cf8376f478
commit
c3b4ea71d3
|
@ -3,6 +3,10 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Forms\Config;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Data\ConfigObject;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Web\Form;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -271,4 +275,63 @@ class BackendConfigForm extends ConfigForm
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the ido instance schema resource
|
||||
*
|
||||
* @param Form $form
|
||||
* @param ConfigObject $resourceConfig
|
||||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public static function isValidIdoSchema(Form $form, ConfigObject $resourceConfig)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource($resourceConfig);
|
||||
$result = $resource->select()->from('icinga_dbversion', array('version'));
|
||||
$result->fetchOne();
|
||||
} catch (Exception $e) {
|
||||
$form->addError(
|
||||
$form->translate(
|
||||
'IDO schema validation failed, it looks like that the IDO schema is missing in the given database.'
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the ido instance availability
|
||||
*
|
||||
* @param Form $form
|
||||
* @param ConfigObject $resourceConfig
|
||||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public static function isValidIdoInstance(Form $form, ConfigObject $resourceConfig)
|
||||
{
|
||||
$resource = ResourceFactory::createResource($resourceConfig);
|
||||
$result = $resource->select()->from('icinga_instances', array('instance_name'));
|
||||
$instances = $result->fetchAll();
|
||||
|
||||
if (count($instances) === 1) {
|
||||
return true;
|
||||
} elseif (count($instances) > 1) {
|
||||
$form->addError(
|
||||
$form->translate(
|
||||
'WARNING: IDO instance validation failed, because there are multiple instances available.'
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$form->addError(
|
||||
$form->translate(
|
||||
'IDO instance validation failed, because there is no IDO instance available.'
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Forms\Setup;
|
||||
|
||||
use Icinga\Data\ConfigObject;
|
||||
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Forms\Config\Resource\DbResourceForm;
|
||||
|
||||
|
@ -53,7 +55,14 @@ class IdoResourcePage extends Form
|
|||
}
|
||||
|
||||
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
||||
if (false === DbResourceForm::isValidResource($this)) {
|
||||
$configObject = new ConfigObject($this->getValues());
|
||||
if (false === DbResourceForm::isValidResource($this, $configObject)) {
|
||||
$this->addSkipValidationCheckbox();
|
||||
return false;
|
||||
} elseif (false === BackendConfigForm::isValidIdoSchema($this, $configObject)) {
|
||||
$this->addSkipValidationCheckbox();
|
||||
return false;
|
||||
} elseif (false === BackendConfigForm::isValidIdoInstance($this, $configObject)) {
|
||||
$this->addSkipValidationCheckbox();
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue