2016-10-13 11:13:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2020-01-10 17:41:13 +01:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2017-08-16 23:51:15 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaServiceSetForm;
|
2016-10-13 11:13:21 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
|
|
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
2017-08-16 23:51:15 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
2020-01-10 17:41:13 +01:00
|
|
|
use Icinga\Module\Director\Web\Table\IcingaHostsMatchingFilterTable;
|
2017-08-16 23:51:15 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\IcingaServiceSetHostTable;
|
|
|
|
use Icinga\Module\Director\Web\Table\IcingaServiceSetServiceTable;
|
2019-05-02 13:23:06 +02:00
|
|
|
use gipfl\IcingaWeb2\Link;
|
2016-10-13 11:13:21 +02:00
|
|
|
|
|
|
|
class ServicesetController extends ObjectController
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaHost */
|
2016-10-13 11:13:21 +02:00
|
|
|
protected $host;
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
protected function checkDirectorPermissions()
|
|
|
|
{
|
|
|
|
$this->assertPermission('director/servicesets');
|
|
|
|
}
|
|
|
|
|
2016-10-13 11:13:21 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
if (null !== ($host = $this->params->get('host'))) {
|
2016-10-13 11:13:21 +02:00
|
|
|
$this->host = IcingaHost::load($host, $this->db());
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::init();
|
2016-10-26 01:01:18 +02:00
|
|
|
if ($this->object) {
|
2017-08-16 23:51:15 +02:00
|
|
|
$this->addServiceSetTabs();
|
2016-10-26 01:01:18 +02:00
|
|
|
}
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
protected function onObjectFormLoaded(DirectorObjectForm $form)
|
2016-10-20 09:22:08 +02:00
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
if ($this->host) {
|
|
|
|
/** @var IcingaServiceSetForm $form */
|
2016-10-20 09:22:08 +02:00
|
|
|
$form->setHost($this->host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 01:01:18 +02:00
|
|
|
public function addAction()
|
|
|
|
{
|
|
|
|
parent::addAction();
|
|
|
|
if ($this->host) {
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->addTitle(
|
2016-10-26 01:01:18 +02:00
|
|
|
$this->translate('Add a service set to "%s"'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$this->host->getObjectName()
|
2016-10-26 01:01:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function servicesAction()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaServiceSet $set */
|
2016-10-26 01:01:18 +02:00
|
|
|
$set = $this->object;
|
2017-08-16 23:51:15 +02:00
|
|
|
$name = $set->getObjectName();
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->tabs()->activate('services');
|
|
|
|
$this->addTitle(
|
2016-10-26 01:01:18 +02:00
|
|
|
$this->translate('Services in this set: %s'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$name
|
2016-10-26 01:01:18 +02:00
|
|
|
);
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
$this->translate('Add service'),
|
|
|
|
'director/service/add',
|
2017-08-16 23:51:15 +02:00
|
|
|
['set' => $name],
|
2017-07-04 01:34:50 +02:00
|
|
|
['class' => 'icon-plus']
|
|
|
|
));
|
|
|
|
|
2022-09-20 12:54:28 +02:00
|
|
|
IcingaServiceSetServiceTable::load($set)
|
|
|
|
->setBranch($this->getBranch())
|
|
|
|
->renderTo($this);
|
2016-10-26 01:01:18 +02:00
|
|
|
}
|
|
|
|
|
2016-11-11 15:33:11 +01:00
|
|
|
public function hostsAction()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaServiceSet $set */
|
2016-11-11 15:33:11 +01:00
|
|
|
$set = $this->object;
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->tabs()->activate('hosts');
|
|
|
|
$this->addTitle(
|
2016-11-11 15:33:11 +01:00
|
|
|
$this->translate('Hosts using this set: %s'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$set->getObjectName()
|
2016-11-11 15:33:11 +01:00
|
|
|
);
|
|
|
|
|
2020-01-10 17:41:13 +01:00
|
|
|
$table = IcingaServiceSetHostTable::load($set);
|
|
|
|
if ($table->count()) {
|
|
|
|
$table->renderTo($this);
|
|
|
|
}
|
|
|
|
$filter = $set->get('assign_filter');
|
2021-12-23 10:06:38 +01:00
|
|
|
if ($filter !== null && \strlen($filter) > 0) {
|
2020-01-10 17:41:13 +01:00
|
|
|
$this->content()->add(
|
|
|
|
IcingaHostsMatchingFilterTable::load(Filter::fromQueryString($filter), $this->db())
|
|
|
|
);
|
|
|
|
}
|
2017-08-16 23:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function addServiceSetTabs()
|
|
|
|
{
|
2022-09-05 12:23:13 +02:00
|
|
|
$hexUuid = $this->object->getUniqueId()->toString();
|
2017-08-16 23:51:15 +02:00
|
|
|
$tabs = $this->tabs();
|
|
|
|
$tabs->add('services', [
|
|
|
|
'url' => 'director/serviceset/services',
|
2022-09-05 12:23:13 +02:00
|
|
|
'urlParams' => ['uuid' => $hexUuid],
|
2017-08-16 23:51:15 +02:00
|
|
|
'label' => 'Services'
|
2022-09-20 12:54:28 +02:00
|
|
|
]);
|
|
|
|
if ($this->branch->isBranch()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
$tabs->add('hosts', [
|
2017-08-16 23:51:15 +02:00
|
|
|
'url' => 'director/serviceset/hosts',
|
2022-09-05 12:23:13 +02:00
|
|
|
'urlParams' => ['uuid' => $hexUuid],
|
2017-08-16 23:51:15 +02:00
|
|
|
'label' => 'Hosts'
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-11 15:33:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 11:13:21 +02:00
|
|
|
protected function loadObject()
|
|
|
|
{
|
|
|
|
if ($this->object === null) {
|
2017-08-16 23:51:15 +02:00
|
|
|
if (null !== ($name = $this->params->get('name'))) {
|
|
|
|
$params = ['object_name' => $name];
|
2016-10-13 11:13:21 +02:00
|
|
|
$db = $this->db();
|
|
|
|
|
|
|
|
if ($this->host) {
|
2017-08-16 23:51:15 +02:00
|
|
|
$params['host_id'] = $this->host->get('id');
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->object = IcingaServiceSet::load($params, $db);
|
|
|
|
} else {
|
|
|
|
parent::loadObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->object;
|
|
|
|
}
|
|
|
|
}
|