Skip to content

Commit

Permalink
Add statusdat validation
Browse files Browse the repository at this point in the history
refs #3761
  • Loading branch information
Johannes Meyer committed Oct 10, 2013
1 parent 135817f commit d06a195
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
1 change: 0 additions & 1 deletion install/application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ private function getBackendDetails($session)
* Validate the given backend details
*
* @return bool Whether the details are valid
* @todo Validate dat and live connectivity
*/
private function validateBackendDetails($session)
{
Expand Down
27 changes: 26 additions & 1 deletion install/application/forms/BackendConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function create()
}

/**
* Validate the form and check if the provided database details are correct
* Validate the form and check if the provided backend details are correct
*
* @param array $data The submitted details
* @return bool Whether the form and the details are valid
Expand Down Expand Up @@ -266,6 +266,31 @@ public function isValid($data)
}
}

if ($isValid && $data['backend_use_statusdat']) {
$message = $this->checkStatusDat(
new Zend_Config(
array(
'status_file' => $data['backend_statusdat_file'],
'objects_file' => $data['backend_statusdat_objects']
)
)
);
$isValid = $message === 'OK';

if (!$isValid) {
$this->addErrorNote('Invalid Status.dat backend: ' . $message, 2);
}
}

if ($isValid && $data['backend_use_livestatus']) {
$message = $this->checkLiveStatus($data['backend_livestatus_socket']);
$isValid = $message === 'OK';

if (!$isValid) {
$this->addErrorNote('Invalid Livestatus backend: ' . $message, 2);
}
}

return $isValid;
}

Expand Down
34 changes: 34 additions & 0 deletions install/application/forms/WizardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
require_once realpath(__DIR__ . '/../../../library/Icinga/Protocol/Ldap/Connection.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Protocol/Ldap/LdapUtils.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Protocol/Ldap/Query.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Data/DatasourceInterface.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Protocol/Statusdat/IReader.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Protocol/Statusdat/Reader.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Exception/ConfigurationError.php');

use \Exception;
use \Zend_Config;
Expand All @@ -55,6 +59,7 @@
use \Icinga\Installer\Report;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Authentication\Backend\LdapUserBackend;
use \Icinga\Protocol\Statusdat\Reader as StatusdatReader;

/**
* Base form for every wizard page
Expand Down Expand Up @@ -281,4 +286,33 @@ public function checkLdapAuthentication(Zend_Config $config)

return 'OK';
}

/**
* Check the existence of the given paths and whether their content is valid
*
* @param Zend_Config $config The protocol information to use
* @return string OK in case both paths are valid, otherwise an error message
*/
public function checkStatusDat(Zend_Config $config)
{
try {
new StatusdatReader($config);
} catch (Exception $error) {
return $error->getMessage();
}

return 'OK';
}

/**
* Check whether the given path points to a valid Livestatus socket
*
* @param string $socketPath The path to the Livestatus socket
* @return string OK in case the socket is valid, otherwise the error message
* @todo Implement validation logic #4832
*/
public function checkLiveStatus($socketPath)
{
return 'OK';
}
}

0 comments on commit d06a195

Please sign in to comment.