2013-06-27 12:45:18 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-06-24 21:28:01 +02:00
|
|
|
use Icinga\Web\Notification;
|
2014-09-04 11:25:47 +02:00
|
|
|
use Icinga\Data\ResourceFactory;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\ConfirmRemovalForm;
|
2014-09-04 11:25:47 +02:00
|
|
|
use Icinga\Web\Controller\ModuleActionController;
|
|
|
|
use Icinga\Module\Monitoring\Form\Config\BackendConfigForm;
|
2014-09-04 08:47:16 +02:00
|
|
|
use Icinga\Module\Monitoring\Form\Config\InstanceConfigForm;
|
2014-09-03 15:08:37 +02:00
|
|
|
use Icinga\Module\Monitoring\Form\Config\SecurityConfigForm;
|
2014-03-13 15:54:27 +01:00
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
/**
|
|
|
|
* Configuration controller for editing monitoring resources
|
|
|
|
*/
|
2014-06-24 21:31:59 +02:00
|
|
|
class Monitoring_ConfigController extends ModuleActionController
|
|
|
|
{
|
2013-08-20 15:45:04 +02:00
|
|
|
/**
|
|
|
|
* Display a list of available backends and instances
|
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2014-09-04 11:25:47 +02:00
|
|
|
$this->view->backendsConfig = $this->Config('backends');
|
|
|
|
$this->view->instancesConfig = $this->Config('instances');
|
2014-06-24 21:22:38 +02:00
|
|
|
$this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
|
2013-08-20 15:45:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a form to modify the backend identified by the 'backend' parameter of the request
|
|
|
|
*/
|
|
|
|
public function editbackendAction()
|
|
|
|
{
|
2014-09-04 11:25:47 +02:00
|
|
|
$form = new BackendConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$form->setIniConfig($this->Config('backends'));
|
2014-09-04 11:25:47 +02:00
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2014-07-25 14:55:36 +02:00
|
|
|
|
|
|
|
$this->view->form = $form;
|
2013-08-20 15:45:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 08:39:27 +02:00
|
|
|
* Display a form to create a new backend
|
2013-08-20 15:45:04 +02:00
|
|
|
*/
|
|
|
|
public function createbackendAction()
|
|
|
|
{
|
2014-09-04 11:25:47 +02:00
|
|
|
$form = new BackendConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$form->setIniConfig($this->Config('backends'));
|
2014-09-04 11:25:47 +02:00
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2014-07-25 15:58:44 +02:00
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-21 11:02:53 +02:00
|
|
|
* Display a confirmation form to remove the backend identified by the 'backend' parameter
|
2013-08-20 15:45:04 +02:00
|
|
|
*/
|
|
|
|
public function removebackendAction()
|
|
|
|
{
|
2014-09-04 11:25:47 +02:00
|
|
|
$config = $this->Config('backends');
|
|
|
|
$form = new ConfirmRemovalForm(array(
|
|
|
|
'onSuccess' => function ($request) use ($config) {
|
|
|
|
$backendName = $request->getQuery('backend');
|
|
|
|
$configForm = new BackendConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$configForm->setIniConfig($config);
|
2014-09-04 11:25:47 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$configForm->remove($backendName);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Notification::error($e->getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($configForm->save()) {
|
2014-10-21 17:22:16 +02:00
|
|
|
Notification::success(sprintf(mt('monitoring', 'Backend "%s" successfully removed.'), $backendName));
|
2014-09-04 11:25:47 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-20 15:45:04 +02:00
|
|
|
}
|
2014-09-04 11:25:47 +02:00
|
|
|
));
|
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2013-08-20 15:45:04 +02:00
|
|
|
|
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-25 08:39:27 +02:00
|
|
|
* Display a confirmation form to remove the instance identified by the 'instance' parameter
|
2013-08-20 15:45:04 +02:00
|
|
|
*/
|
|
|
|
public function removeinstanceAction()
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
2014-09-04 08:47:16 +02:00
|
|
|
$config = $this->Config('instances');
|
|
|
|
$form = new ConfirmRemovalForm(array(
|
|
|
|
'onSuccess' => function ($request) use ($config) {
|
|
|
|
$instanceName = $request->getQuery('instance');
|
|
|
|
$configForm = new InstanceConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$configForm->setIniConfig($config);
|
2014-09-04 08:47:16 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$configForm->remove($instanceName);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Notification::error($e->getMessage());
|
|
|
|
return;
|
|
|
|
}
|
2013-08-20 15:45:04 +02:00
|
|
|
|
2014-09-04 08:47:16 +02:00
|
|
|
if ($configForm->save()) {
|
2014-10-21 17:22:16 +02:00
|
|
|
Notification::success(sprintf(mt('monitoring', 'Instance "%s" successfully removed.'), $instanceName));
|
2014-09-04 08:47:16 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-20 15:45:04 +02:00
|
|
|
}
|
2014-09-04 08:47:16 +02:00
|
|
|
));
|
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2013-08-20 15:45:04 +02:00
|
|
|
|
|
|
|
$this->view->form = $form;
|
2013-06-27 12:45:18 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
/**
|
|
|
|
* Display a form to edit the instance identified by the 'instance' parameter of the request
|
|
|
|
*/
|
|
|
|
public function editinstanceAction()
|
|
|
|
{
|
2014-09-04 08:47:16 +02:00
|
|
|
$form = new InstanceConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$form->setIniConfig($this->Config('instances'));
|
2014-09-04 08:47:16 +02:00
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2014-08-11 14:49:42 +02:00
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a form to create a new instance
|
|
|
|
*/
|
|
|
|
public function createinstanceAction()
|
|
|
|
{
|
2014-09-04 08:47:16 +02:00
|
|
|
$form = new InstanceConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$form->setIniConfig($this->Config('instances'));
|
2014-09-04 08:47:16 +02:00
|
|
|
$form->setRedirectUrl('monitoring/config');
|
|
|
|
$form->handleRequest();
|
2014-08-11 14:49:42 +02:00
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
2014-08-22 12:15:02 +02:00
|
|
|
/**
|
|
|
|
* Display a form to adjust security relevant settings
|
|
|
|
*/
|
2014-08-19 11:19:30 +02:00
|
|
|
public function securityAction()
|
|
|
|
{
|
2014-09-03 15:08:37 +02:00
|
|
|
$form = new SecurityConfigForm();
|
2014-09-08 13:31:25 +02:00
|
|
|
$form->setIniConfig($this->Config());
|
2014-09-03 15:08:37 +02:00
|
|
|
$form->handleRequest();
|
2014-08-22 12:30:13 +02:00
|
|
|
|
2014-08-19 14:04:00 +02:00
|
|
|
$this->view->form = $form;
|
2014-09-03 15:08:37 +02:00
|
|
|
$this->view->tabs = $this->Module()->getConfigTabs()->activate('security');
|
2014-08-19 11:19:30 +02:00
|
|
|
}
|
2013-08-14 12:42:32 +02:00
|
|
|
}
|