2015-06-30 11:19:31 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2017-04-18 11:42:33 +02:00
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
use Icinga\Data\Filter\FilterChain;
|
|
|
|
use Icinga\Data\Filter\FilterExpression;
|
2017-08-21 19:55:24 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaAddServiceForm;
|
2017-11-10 14:13:52 +01:00
|
|
|
use Icinga\Module\Director\Forms\IcingaAddServiceSetForm;
|
2017-04-18 11:42:33 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
2015-06-30 11:19:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ObjectsController;
|
2017-10-09 15:23:27 +02:00
|
|
|
use dipl\Html\Link;
|
2015-06-30 11:19:31 +02:00
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
class HostsController extends ObjectsController
|
2015-06-30 11:19:31 +02:00
|
|
|
{
|
2016-10-14 20:32:34 +02:00
|
|
|
protected $multiEdit = array(
|
|
|
|
'imports',
|
2016-12-13 16:05:07 +01:00
|
|
|
'groups',
|
|
|
|
'disabled'
|
2016-10-14 20:32:34 +02:00
|
|
|
);
|
2016-11-03 16:06:18 +01:00
|
|
|
|
|
|
|
protected function checkDirectorPermissions()
|
|
|
|
{
|
|
|
|
$this->assertPermission('director/hosts');
|
|
|
|
}
|
2017-04-18 11:42:33 +02:00
|
|
|
|
|
|
|
public function editAction()
|
|
|
|
{
|
|
|
|
$url = clone($this->getRequest()->getUrl());
|
|
|
|
$url->setPath('director/hosts/addservice');
|
|
|
|
|
2017-11-10 14:20:33 +01:00
|
|
|
$urlSet = clone($url);
|
|
|
|
$urlSet->setPath('director/hosts/addserviceset');
|
|
|
|
|
2017-04-18 11:42:33 +02:00
|
|
|
parent::editAction();
|
|
|
|
|
2017-07-13 16:30:04 +02:00
|
|
|
$this->actions()->add(Link::create(
|
2017-04-18 11:42:33 +02:00
|
|
|
$this->translate('Add Service'),
|
|
|
|
$url,
|
|
|
|
null,
|
2017-07-13 16:30:04 +02:00
|
|
|
['class' => 'icon-plus']
|
2017-11-10 14:13:52 +01:00
|
|
|
))->add(Link::create(
|
|
|
|
$this->translate('Add Service Set'),
|
2017-11-10 14:20:33 +01:00
|
|
|
$urlSet,
|
2017-11-10 14:13:52 +01:00
|
|
|
null,
|
|
|
|
['class' => 'icon-plus']
|
2017-04-18 11:42:33 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addserviceAction()
|
|
|
|
{
|
2017-07-13 16:30:04 +02:00
|
|
|
$this->addSingleTab($this->translate('Add Service'));
|
2017-04-18 11:42:33 +02:00
|
|
|
$filter = Filter::fromQueryString($this->params->toString());
|
|
|
|
|
|
|
|
$objects = array();
|
|
|
|
$db = $this->db();
|
|
|
|
/** @var $filter FilterChain */
|
|
|
|
foreach ($filter->filters() as $sub) {
|
|
|
|
/** @var $sub FilterChain */
|
|
|
|
foreach ($sub->filters() as $ex) {
|
|
|
|
/** @var $ex FilterChain|FilterExpression */
|
|
|
|
if ($ex->isExpression() && $ex->getColumn() === 'name') {
|
|
|
|
$name = $ex->getExpression();
|
|
|
|
$objects[$name] = IcingaHost::load($name, $db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-13 16:30:04 +02:00
|
|
|
$this->addTitle(
|
2017-04-18 11:42:33 +02:00
|
|
|
$this->translate('Add service to %d hosts'),
|
|
|
|
count($objects)
|
|
|
|
);
|
|
|
|
|
2017-07-13 17:02:32 +02:00
|
|
|
$this->content()->add(
|
2017-08-21 19:55:24 +02:00
|
|
|
IcingaAddServiceForm::load()
|
2017-07-13 17:02:32 +02:00
|
|
|
->setHosts($objects)
|
|
|
|
->setDb($this->db())
|
|
|
|
->handleRequest()
|
2017-07-13 16:30:04 +02:00
|
|
|
);
|
2017-04-18 11:42:33 +02:00
|
|
|
}
|
2017-11-10 14:13:52 +01:00
|
|
|
|
|
|
|
public function addservicesetAction()
|
|
|
|
{
|
|
|
|
$this->addSingleTab($this->translate('Add Service Set'));
|
|
|
|
$filter = Filter::fromQueryString($this->params->toString());
|
|
|
|
|
|
|
|
$objects = array();
|
|
|
|
$db = $this->db();
|
|
|
|
/** @var $filter FilterChain */
|
|
|
|
foreach ($filter->filters() as $sub) {
|
|
|
|
/** @var $sub FilterChain */
|
|
|
|
foreach ($sub->filters() as $ex) {
|
|
|
|
/** @var $ex FilterChain|FilterExpression */
|
|
|
|
if ($ex->isExpression() && $ex->getColumn() === 'name') {
|
|
|
|
$name = $ex->getExpression();
|
|
|
|
$objects[$name] = IcingaHost::load($name, $db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('Add Service Set to %d hosts'),
|
|
|
|
count($objects)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->content()->add(
|
|
|
|
IcingaAddServiceSetForm::load()
|
|
|
|
->setHosts($objects)
|
|
|
|
->setDb($this->db())
|
|
|
|
->handleRequest()
|
|
|
|
);
|
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|