2013-06-27 12:45:18 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-27 12:45:18 +02:00
|
|
|
|
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;
|
2015-04-08 15:08:14 +02:00
|
|
|
use Icinga\Web\Controller;
|
2014-11-14 11:17:22 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Config\InstanceConfigForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
|
2014-03-13 15:54:27 +01:00
|
|
|
|
2013-08-20 15:45:04 +02:00
|
|
|
/**
|
|
|
|
* Configuration controller for editing monitoring resources
|
|
|
|
*/
|
2015-04-08 15:08:14 +02:00
|
|
|
class Monitoring_ConfigController extends Controller
|
2014-06-24 21:31:59 +02:00
|
|
|
{
|
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();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Edit Existing Backend'));
|
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();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Add New Backend'));
|
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(
|
2014-11-18 13:12:30 +01:00
|
|
|
'onSuccess' => function ($form) use ($config) {
|
|
|
|
$backendName = $form->getRequest()->getQuery('backend');
|
2014-09-04 11:25:47 +02:00
|
|
|
$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()) {
|
2015-03-02 18:37:54 +01:00
|
|
|
Notification::success(sprintf(
|
|
|
|
$this->translate('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
|
|
|
));
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Remove Existing Backend'));
|
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(
|
2014-11-18 13:12:30 +01:00
|
|
|
'onSuccess' => function ($form) use ($config) {
|
|
|
|
$instanceName = $form->getRequest()->getQuery('instance');
|
2014-09-04 08:47:16 +02:00
|
|
|
$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()) {
|
2015-03-02 18:37:54 +01:00
|
|
|
Notification::success(sprintf(
|
|
|
|
$this->translate('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
|
|
|
));
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Remove Existing Instance'));
|
|
|
|
$form->addDescription($this->translate(
|
|
|
|
'If you have still any environments or views referring to this instance, '
|
|
|
|
. 'you won\'t be able to send commands anymore after deletion.'
|
|
|
|
));
|
|
|
|
$form->addElement(
|
|
|
|
'note',
|
|
|
|
'question',
|
|
|
|
array(
|
|
|
|
'value' => $this->translate('Are you sure you want to remove this instance?'),
|
|
|
|
'decorators' => array(
|
|
|
|
'ViewHelper',
|
|
|
|
array('HtmlTag', array('tag' => 'p'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
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();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Edit Existing Instance'));
|
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();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Add New Instance'));
|
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
|
|
|
}
|