mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
HostController: refactor all involved tables...
...for single services and sets
This commit is contained in:
parent
6f20e6c35e
commit
23249dcf7d
@ -3,6 +3,7 @@
|
|||||||
namespace Icinga\Module\Director\Controllers;
|
namespace Icinga\Module\Director\Controllers;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Module\Director\CustomVariable\CustomVariableDictionary;
|
||||||
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
||||||
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
@ -12,6 +13,10 @@ use Icinga\Module\Director\Restriction\HostgroupRestriction;
|
|||||||
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
|
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
|
||||||
use Icinga\Module\Director\Web\Controller\ObjectController;
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
||||||
use Icinga\Module\Director\Web\SelfService;
|
use Icinga\Module\Director\Web\SelfService;
|
||||||
|
use Icinga\Module\Director\Web\Table\IcingaHostAppliedForServiceTable;
|
||||||
|
use Icinga\Module\Director\Web\Table\IcingaHostAppliedServicesTable;
|
||||||
|
use Icinga\Module\Director\Web\Table\IcingaHostServiceTable;
|
||||||
|
use Icinga\Module\Director\Web\Table\IcingaServiceSetServiceTable;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use ipl\Html\Link;
|
use ipl\Html\Link;
|
||||||
|
|
||||||
@ -22,153 +27,115 @@ class HostController extends ObjectController
|
|||||||
$this->assertPermission('director/hosts');
|
$this->assertPermission('director/hosts');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadRestrictions()
|
|
||||||
{
|
|
||||||
return [$this->getHostgroupRestriction()];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getHostgroupRestriction()
|
protected function getHostgroupRestriction()
|
||||||
{
|
{
|
||||||
return new HostgroupRestriction($this->db(), $this->Auth());
|
return new HostgroupRestriction($this->db(), $this->Auth());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param IcingaHostForm $form
|
|
||||||
*/
|
|
||||||
protected function beforeHandlingAddRequest($form)
|
|
||||||
{
|
|
||||||
$form->setApi($this->getApiIfAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param IcingaHostForm $form
|
|
||||||
*/
|
|
||||||
protected function beforeHandlingEditRequest($form)
|
|
||||||
{
|
|
||||||
$form->setApi($this->getApiIfAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function editAction()
|
public function editAction()
|
||||||
{
|
{
|
||||||
parent::editAction();
|
parent::editAction();
|
||||||
$host = $this->object;
|
$this->addOptionalMonitoringLink();
|
||||||
try {
|
}
|
||||||
$mon = $this->monitoring();
|
|
||||||
if ($host->isObject() && $mon->isAvailable() && $mon->hasHost($host->object_name)) {
|
public function serviceAction()
|
||||||
$this->actions()->add(Link::create(
|
{
|
||||||
$this->translate('Show'),
|
$host = $this->getHostObject();
|
||||||
'monitoring/host/show',
|
$this->addServicesHeader();
|
||||||
['host' => $host->getObjectName()],
|
$this->addTitle($this->translate('Add Service: %s'), $host->getObjectName());
|
||||||
[
|
}
|
||||||
'class' => 'icon-globe critical',
|
|
||||||
'data-base-target' => '_next'
|
public function servicesetAction()
|
||||||
]
|
{
|
||||||
));
|
$host = $this->getHostObject();
|
||||||
}
|
$this->addServicesHeader();
|
||||||
} catch (Exception $e) {
|
$this->addTitle($this->translate('Add Service Set: %s'), $host->getObjectName());
|
||||||
// Silently ignore errors in the monitoring module
|
}
|
||||||
}
|
|
||||||
|
protected function addServicesHeader()
|
||||||
|
{
|
||||||
|
$host = $this->getHostObject();
|
||||||
|
$hostname = $host->getObjectName();
|
||||||
|
$this->tabs()->activate('services');
|
||||||
|
|
||||||
|
$this->actions()->add(Link::create(
|
||||||
|
$this->translate('Add service'),
|
||||||
|
'director/host/service',
|
||||||
|
['name' => $hostname],
|
||||||
|
['class' => 'icon-plus']
|
||||||
|
))->add(Link::create(
|
||||||
|
$this->translate('Add service set'),
|
||||||
|
'director/serviceset',
|
||||||
|
['host' => $hostname],
|
||||||
|
['class' => 'icon-plus']
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function servicesAction()
|
public function servicesAction()
|
||||||
{
|
{
|
||||||
|
$this->addServicesHeader();
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
$host = $this->getHostObject();
|
$host = $this->getHostObject();
|
||||||
$hostname = $host->getObjectName();
|
|
||||||
|
|
||||||
$this->tabs()->activate('services');
|
|
||||||
$this->addTitle($this->translate('Services: %s'), $host->getObjectName());
|
$this->addTitle($this->translate('Services: %s'), $host->getObjectName());
|
||||||
|
$content = $this->content();
|
||||||
$this->actions()->add(Link::create(
|
$table = IcingaHostServiceTable::load($host)
|
||||||
$this->translate('Add service'),
|
->setTitle($this->translate('Individual Service objects'));
|
||||||
'director/service/add',
|
|
||||||
['host' => $hostname],
|
|
||||||
['class' => 'icon-plus']
|
|
||||||
))->add(Link::create(
|
|
||||||
$this->translate('Add service set'),
|
|
||||||
'director/serviceset/add',
|
|
||||||
['host' => $hostname],
|
|
||||||
['class' => 'icon-plus']
|
|
||||||
));
|
|
||||||
|
|
||||||
$resolver = $this->object->templateResolver();
|
|
||||||
|
|
||||||
$tables = array();
|
|
||||||
$table = $this->loadTable('IcingaHostService')
|
|
||||||
->setHost($host)
|
|
||||||
->setTitle($this->translate('Individual Service objects'))
|
|
||||||
->enforceFilter('host_id', $host->id)
|
|
||||||
->setConnection($db);
|
|
||||||
|
|
||||||
if (count($table)) {
|
if (count($table)) {
|
||||||
$tables[0] = $table;
|
$content->add($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($applied = $host->vars()->get($db->settings()->magic_apply_for)) {
|
if ($applied = $host->vars()->get($db->settings()->magic_apply_for)) {
|
||||||
$table = $this->loadTable('IcingaHostAppliedForService')
|
if ($applied instanceof CustomVariableDictionary) {
|
||||||
->setHost($host)
|
$table = IcingaHostAppliedForServiceTable::load($host, $applied)
|
||||||
->setDictionary($applied)
|
->setTitle($this->translate('Generated from host vars'));
|
||||||
->setTitle($this->translate('Generated from host vars'));
|
if (count($table)) {
|
||||||
|
$content->add($table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var IcingaHost[] $parents */
|
||||||
|
$parents = IcingaTemplateRepository::instanceByObject($this->object)
|
||||||
|
->getTemplatesFor($this->object);
|
||||||
|
foreach ($parents as $parent) {
|
||||||
|
$table = IcingaHostServiceTable::load($parent)->setInheritedBy($host);
|
||||||
if (count($table)) {
|
if (count($table)) {
|
||||||
$tables[1] = $table;
|
$content->add(
|
||||||
|
$table->setTitle(sprintf(
|
||||||
|
'Inherited from %s',
|
||||||
|
$parent->getObjectName()
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$parents = $resolver->fetchResolvedParents();
|
$this->addHostServiceSetTables($host);
|
||||||
foreach ($parents as $parent) {
|
foreach ($parents as $parent) {
|
||||||
$table = $this->loadTable('IcingaHostService')
|
$this->addHostServiceSetTables($parent, $host);
|
||||||
->setHost($parent)
|
|
||||||
->setInheritedBy($host)
|
|
||||||
->enforceFilter('host_id', $parent->id)
|
|
||||||
->setConnection($db);
|
|
||||||
if (! count($table)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// dup dup
|
|
||||||
$title = sprintf(
|
|
||||||
'Inherited from %s',
|
|
||||||
$parent->object_name
|
|
||||||
);
|
|
||||||
|
|
||||||
$tables[$title] = $table->setTitle($title);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addHostServiceSetTables($host, $tables);
|
|
||||||
foreach ($parents as $parent) {
|
|
||||||
$this->addHostServiceSetTables($parent, $tables, $host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$appliedSets = AppliedServiceSetLoader::fetchForHost($host);
|
$appliedSets = AppliedServiceSetLoader::fetchForHost($host);
|
||||||
foreach ($appliedSets as $set) {
|
foreach ($appliedSets as $set) {
|
||||||
$title = sprintf($this->translate('%s (Applied Service set)'), $set->getObjectName());
|
$title = sprintf($this->translate('%s (Applied Service set)'), $set->getObjectName());
|
||||||
$table = $this->loadTable('IcingaServiceSetService')
|
|
||||||
->setServiceSet($set)
|
|
||||||
// ->setHost($host)
|
|
||||||
->setAffectedHost($host)
|
|
||||||
->setTitle($title)
|
|
||||||
->setConnection($db);
|
|
||||||
|
|
||||||
$tables[$title] = $table;
|
$content->add(
|
||||||
|
IcingaServiceSetServiceTable::load($set)
|
||||||
|
// ->setHost($host)
|
||||||
|
->setAffectedHost($host)
|
||||||
|
->setTitle($title)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = $this->translate('Applied services');
|
$table = IcingaHostAppliedServicesTable::load($host)
|
||||||
$table = $this->loadTable('IcingaHostAppliedServices')
|
->setTitle($this->translate('Applied services'));
|
||||||
->setHost($host)
|
|
||||||
->setTitle($title)
|
|
||||||
->setConnection($db);
|
|
||||||
|
|
||||||
if (count($table)) {
|
if (count($table)) {
|
||||||
$tables[$title] = $table;
|
$content->add($table);
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
|
||||||
$this->content()->add($table);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addHostServiceSetTables(IcingaHost $host, & $tables, IcingaHost $affectedHost = null)
|
protected function addHostServiceSetTables(IcingaHost $host, IcingaHost $affectedHost = null)
|
||||||
{
|
{
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
if ($affectedHost === null) {
|
if ($affectedHost === null) {
|
||||||
@ -190,16 +157,15 @@ class HostController extends ObjectController
|
|||||||
)->where('hs.host_id = ?', $host->id);
|
)->where('hs.host_id = ?', $host->id);
|
||||||
|
|
||||||
$sets = IcingaServiceSet::loadAll($db, $query, 'object_name');
|
$sets = IcingaServiceSet::loadAll($db, $query, 'object_name');
|
||||||
|
/** @var IcingaServiceSet $set*/
|
||||||
foreach ($sets as $name => $set) {
|
foreach ($sets as $name => $set) {
|
||||||
$title = sprintf($this->translate('%s (Service set)'), $name);
|
$title = sprintf($this->translate('%s (Service set)'), $name);
|
||||||
$table = $this->loadTable('IcingaServiceSetService')
|
$this->content()->add(
|
||||||
->setServiceSet($set)
|
IcingaServiceSetServiceTable::load($set)
|
||||||
->setHost($host)
|
->setHost($host)
|
||||||
->setAffectedHost($affectedHost)
|
->setAffectedHost($affectedHost)
|
||||||
->setTitle($title)
|
->setTitle($title)
|
||||||
->setConnection($db);
|
);
|
||||||
|
|
||||||
$tables[$title] = $table;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Tables;
|
|
||||||
|
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
|
||||||
use Icinga\Module\Director\CustomVariable\CustomVariableDictionary;
|
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
|
||||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
|
||||||
|
|
||||||
class IcingaHostAppliedForServiceTable extends QuickTable
|
|
||||||
{
|
|
||||||
protected $title;
|
|
||||||
|
|
||||||
protected $host;
|
|
||||||
|
|
||||||
protected $searchColumns = array(
|
|
||||||
'service',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function setDictionary(CustomVariableDictionary $dict)
|
|
||||||
{
|
|
||||||
$data = array();
|
|
||||||
|
|
||||||
foreach ($dict->getValue() as $key => $var) {
|
|
||||||
$data[] = (object) array(
|
|
||||||
'service' => $key,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setConnection(new ArrayDatasource($data));
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
$query = clone($this->getBaseQuery());
|
|
||||||
$this->applyFiltersToQuery($query);
|
|
||||||
return $query->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchData()
|
|
||||||
{
|
|
||||||
$query = $this->getBaseQuery()->columns($this->getColumns());
|
|
||||||
|
|
||||||
if ($this->hasLimit() || $this->hasOffset()) {
|
|
||||||
$query->limit($this->getLimit(), $this->getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->applyFiltersToQuery($query);
|
|
||||||
|
|
||||||
return $query->fetchAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColumns()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'service' => 'service'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHost(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->host = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getActionUrl($row)
|
|
||||||
{
|
|
||||||
$params = array(
|
|
||||||
'name' => $this->host->object_name,
|
|
||||||
'service' => $row->service,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->url('director/host/appliedservice', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitles()
|
|
||||||
{
|
|
||||||
$view = $this->view();
|
|
||||||
return array(
|
|
||||||
'service' => $this->title ?: $view->translate('Servicename'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBaseQuery()
|
|
||||||
{
|
|
||||||
return $this->db()->select();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Tables;
|
|
||||||
|
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
|
||||||
use Icinga\Data\Filter\Filter;
|
|
||||||
use Icinga\Module\Director\Objects\HostApplyMatches;
|
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
|
||||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
|
||||||
|
|
||||||
class IcingaHostAppliedServicesTable extends QuickTable
|
|
||||||
{
|
|
||||||
protected $title;
|
|
||||||
|
|
||||||
protected $host;
|
|
||||||
|
|
||||||
private $allApplyRules;
|
|
||||||
|
|
||||||
private $baseQuery;
|
|
||||||
|
|
||||||
public function getColumns()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'id' => 'id',
|
|
||||||
'name' => 'name',
|
|
||||||
'assign_filter' => 'assign_filter',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitles()
|
|
||||||
{
|
|
||||||
$view = $this->view();
|
|
||||||
return array(
|
|
||||||
'label' => $this->title
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return $this->getBaseQuery()->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHost(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->host = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getActionUrl($row)
|
|
||||||
{
|
|
||||||
$params = array(
|
|
||||||
'name' => $this->host->object_name,
|
|
||||||
'service_id' => $row->id,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->url('director/host/appliedservice', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function renderRow($row)
|
|
||||||
{
|
|
||||||
$row->label = sprintf(
|
|
||||||
$this->view()->translate('%s (where %s)'),
|
|
||||||
$row->name,
|
|
||||||
$row->filter
|
|
||||||
);
|
|
||||||
|
|
||||||
return parent::renderRow($row);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchData()
|
|
||||||
{
|
|
||||||
return $this->getBaseQuery()->fetchAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBaseQuery()
|
|
||||||
{
|
|
||||||
if ($this->baseQuery === null) {
|
|
||||||
$services = array();
|
|
||||||
$matcher = HostApplyMatches::prepare($this->host);
|
|
||||||
foreach ($this->getAllApplyRules() as $rule) {
|
|
||||||
if ($matcher->matchesFilter($rule->filter)) {
|
|
||||||
$services[] = $rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ds = new ArrayDatasource($services);
|
|
||||||
$this->baseQuery = $ds->select();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->baseQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getAllApplyRules()
|
|
||||||
{
|
|
||||||
if ($this->allApplyRules === null) {
|
|
||||||
$this->allApplyRules = $this->fetchAllApplyRules();
|
|
||||||
foreach ($this->allApplyRules as $rule) {
|
|
||||||
$rule->filter = Filter::fromQueryString($rule->assign_filter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->allApplyRules;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function fetchAllApplyRules()
|
|
||||||
{
|
|
||||||
$db = $this->db();
|
|
||||||
$query = $db->select()->from(
|
|
||||||
array('s' => 'icinga_service'),
|
|
||||||
array(
|
|
||||||
'id' => 's.id',
|
|
||||||
'name' => 's.object_name',
|
|
||||||
'assign_filter' => 's.assign_filter',
|
|
||||||
)
|
|
||||||
)->where('object_type = ? AND assign_filter IS NOT NULL', 'apply');
|
|
||||||
|
|
||||||
return $db->fetchAll($query);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Tables;
|
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
|
||||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
|
||||||
|
|
||||||
class IcingaHostServiceTable extends QuickTable
|
|
||||||
{
|
|
||||||
protected $title;
|
|
||||||
|
|
||||||
protected $host;
|
|
||||||
|
|
||||||
protected $inheritedBy;
|
|
||||||
|
|
||||||
protected $searchColumns = array(
|
|
||||||
'service',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function getColumns()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'id' => 's.id',
|
|
||||||
'host_id' => 's.host_id',
|
|
||||||
'host' => 'h.object_name',
|
|
||||||
'service' => 's.object_name',
|
|
||||||
'object_type' => 's.object_type',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHost(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->host = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setInheritedBy(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->inheritedBy = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getActionUrl($row)
|
|
||||||
{
|
|
||||||
if ($target = $this->inheritedBy) {
|
|
||||||
$params = array(
|
|
||||||
'name' => $target->object_name,
|
|
||||||
'service' => $row->service,
|
|
||||||
'inheritedFrom' => $row->host,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->url('director/host/inheritedservice', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($row->object_type === 'apply') {
|
|
||||||
$params['id'] = $row->id;
|
|
||||||
} else {
|
|
||||||
$params = array('name' => $row->service);
|
|
||||||
if ($row->host !== null) {
|
|
||||||
$params['host'] = $row->host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->url('director/service/edit', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitles()
|
|
||||||
{
|
|
||||||
$view = $this->view();
|
|
||||||
return array(
|
|
||||||
'service' => $this->title ?: $view->translate('Servicename'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnfilteredQuery()
|
|
||||||
{
|
|
||||||
return $this->db()->select()->from(
|
|
||||||
array('s' => 'icinga_service'),
|
|
||||||
array()
|
|
||||||
)->joinLeft(
|
|
||||||
array('h' => 'icinga_host'),
|
|
||||||
'h.id = s.host_id',
|
|
||||||
array()
|
|
||||||
)->order('s.object_name');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBaseQuery()
|
|
||||||
{
|
|
||||||
return $this->getUnfilteredQuery()->where(
|
|
||||||
's.host_id = ?',
|
|
||||||
$this->host->id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,173 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Tables;
|
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
|
||||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
|
||||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
|
||||||
|
|
||||||
class IcingaServiceSetServiceTable extends QuickTable
|
|
||||||
{
|
|
||||||
protected $set;
|
|
||||||
|
|
||||||
protected $title;
|
|
||||||
|
|
||||||
/** @var IcingaHost */
|
|
||||||
protected $host;
|
|
||||||
|
|
||||||
protected $affectedHost;
|
|
||||||
|
|
||||||
protected $searchColumns = array(
|
|
||||||
'service',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function getColumns()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'id' => 's.id',
|
|
||||||
'service_set_id' => 's.service_set_id',
|
|
||||||
'host_id' => 'ss.host_id',
|
|
||||||
'service_set' => 'ss.object_name',
|
|
||||||
'service' => 's.object_name',
|
|
||||||
'disabled' => 's.disabled',
|
|
||||||
'object_type' => 's.object_type',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHost(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->host = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAffectedHost(IcingaHost $host)
|
|
||||||
{
|
|
||||||
$this->affectedHost = $host;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setServiceSet(IcingaServiceSet $set)
|
|
||||||
{
|
|
||||||
$this->set = $set;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function renderTitles($row)
|
|
||||||
{
|
|
||||||
if ($this->host || $this->affectedHost) {
|
|
||||||
return $this->renderHostTitles($row);
|
|
||||||
} else {
|
|
||||||
return parent::renderTitles($row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getActionUrl($row)
|
|
||||||
{
|
|
||||||
if ($this->affectedHost) {
|
|
||||||
$params = array(
|
|
||||||
'name' => $this->affectedHost->getObjectName(),
|
|
||||||
'service' => $row->service,
|
|
||||||
'set' => $row->service_set
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->url('director/host/servicesetservice', $params);
|
|
||||||
} else {
|
|
||||||
$params = array(
|
|
||||||
'name' => $row->service,
|
|
||||||
'set' => $row->service_set
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->url('director/service', $params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getRowClasses($row)
|
|
||||||
{
|
|
||||||
if ($row->disabled === 'y') {
|
|
||||||
return ['disabled'];
|
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitles()
|
|
||||||
{
|
|
||||||
$view = $this->view();
|
|
||||||
return array(
|
|
||||||
'service' => $this->title ?: $view->translate('Servicename'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function renderHostTitles($row)
|
|
||||||
{
|
|
||||||
$view = $this->view();
|
|
||||||
// Hint: row is an array of titles!?!?!?
|
|
||||||
$title = $view->escape(array_shift($row));
|
|
||||||
|
|
||||||
$htm = "<thead>\n <tr>\n";
|
|
||||||
if (! $this->host) {
|
|
||||||
$deleteLink = '';
|
|
||||||
} elseif ($this->affectedHost->id !== $this->host->id) {
|
|
||||||
$deleteLink = $view->qlink(
|
|
||||||
$this->host->getObjectName(),
|
|
||||||
'director/host/services',
|
|
||||||
array(
|
|
||||||
'name' => $this->host->getObjectName(),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'class' => 'icon-paste',
|
|
||||||
'style' => 'float: right; font-weight: normal',
|
|
||||||
'data-base-target' => '_next',
|
|
||||||
'title' => sprintf(
|
|
||||||
$view->translate('This set has been inherited from %s'),
|
|
||||||
$this->host->getObjectName()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$deleteLink = $view->qlink(
|
|
||||||
$view->translate('Remove'),
|
|
||||||
'director/host/removeset',
|
|
||||||
array(
|
|
||||||
'name' => $this->host->getObjectName(),
|
|
||||||
'setId' => $this->set->id
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'class' => 'icon-cancel',
|
|
||||||
'style' => 'float: right; font-weight: normal',
|
|
||||||
'title' => $view->translate('Remove this set from this host')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$htm .= ' <th>' . $view->escape($title) . "$deleteLink</th>\n";
|
|
||||||
|
|
||||||
return $htm . " </tr>\n</thead>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnfilteredQuery()
|
|
||||||
{
|
|
||||||
return $this->db()->select()->from(
|
|
||||||
array('s' => 'icinga_service'),
|
|
||||||
array()
|
|
||||||
)->joinLeft(
|
|
||||||
array('ss' => 'icinga_service_set'),
|
|
||||||
'ss.id = s.service_set_id',
|
|
||||||
array()
|
|
||||||
)->order('s.object_name');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBaseQuery()
|
|
||||||
{
|
|
||||||
return $this->getUnfilteredQuery()->where(
|
|
||||||
's.service_set_id = ?',
|
|
||||||
$this->set->id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
|
use Icinga\Module\Director\CustomVariable\CustomVariableDictionary;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
use ipl\Web\Table\SimpleQueryBasedTable;
|
||||||
|
|
||||||
|
class IcingaHostAppliedForServiceTable extends SimpleQueryBasedTable
|
||||||
|
{
|
||||||
|
protected $title;
|
||||||
|
|
||||||
|
protected $host;
|
||||||
|
|
||||||
|
/** @var CustomVariableDictionary */
|
||||||
|
protected $cv;
|
||||||
|
|
||||||
|
protected $searchColumns = [
|
||||||
|
'service',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @param CustomVariableDictionary $dict
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function load(IcingaHost $host, CustomVariableDictionary $dict)
|
||||||
|
{
|
||||||
|
return (new static())->setHost($host)->setDictionary($dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDictionary(CustomVariableDictionary $dict)
|
||||||
|
{
|
||||||
|
$this->cv = $dict;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->host = $host;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderRow($row)
|
||||||
|
{
|
||||||
|
return $this::row([
|
||||||
|
Link::create(
|
||||||
|
$row->service,
|
||||||
|
'director/host/appliedservice',
|
||||||
|
[
|
||||||
|
'name' => $this->host->object_name,
|
||||||
|
'service' => $row->service,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumnsToBeRendered()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->title ?: $this->translate('Service name'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareQuery()
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
foreach ($this->cv->getValue() as $key => $var) {
|
||||||
|
$data[] = (object) array(
|
||||||
|
'service' => $key,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new ArrayDatasource($data))->select();
|
||||||
|
}
|
||||||
|
}
|
114
library/Director/Web/Table/IcingaHostAppliedServicesTable.php
Normal file
114
library/Director/Web/Table/IcingaHostAppliedServicesTable.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\Module\Director\Objects\HostApplyMatches;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
use ipl\Web\Table\SimpleQueryBasedTable;
|
||||||
|
|
||||||
|
class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
|
||||||
|
{
|
||||||
|
protected $title;
|
||||||
|
|
||||||
|
/** @var IcingaHost */
|
||||||
|
protected $host;
|
||||||
|
|
||||||
|
/** @var \Zend_Db_Adapter_Abstract */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
private $allApplyRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function load(IcingaHost $host)
|
||||||
|
{
|
||||||
|
return (new static())->setHost($host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumnsToBeRendered()
|
||||||
|
{
|
||||||
|
return [$this->title];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->host = $host;
|
||||||
|
$this->db = $host->getDb();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderRow($row)
|
||||||
|
{
|
||||||
|
return $this::row([
|
||||||
|
Link::create(
|
||||||
|
sprintf(
|
||||||
|
$this->translate('%s (where %s)'),
|
||||||
|
$row->name,
|
||||||
|
$row->filter
|
||||||
|
),
|
||||||
|
'director/host/appliedservice',
|
||||||
|
[
|
||||||
|
'name' => $this->host->getObjectName(),
|
||||||
|
'service_id' => $row->id,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareQuery()
|
||||||
|
{
|
||||||
|
$services = [];
|
||||||
|
$matcher = HostApplyMatches::prepare($this->host);
|
||||||
|
foreach ($this->getAllApplyRules() as $rule) {
|
||||||
|
if ($matcher->matchesFilter($rule->filter)) {
|
||||||
|
$services[] = $rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ds = new ArrayDatasource($services);
|
||||||
|
return $ds->select()->columns([
|
||||||
|
'id' => 'id',
|
||||||
|
'name' => 'name',
|
||||||
|
'filter' => 'filter',
|
||||||
|
'assign_filter' => 'assign_filter',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getAllApplyRules()
|
||||||
|
{
|
||||||
|
if ($this->allApplyRules === null) {
|
||||||
|
$this->allApplyRules = $this->fetchAllApplyRules();
|
||||||
|
foreach ($this->allApplyRules as $rule) {
|
||||||
|
$rule->filter = Filter::fromQueryString($rule->assign_filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->allApplyRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fetchAllApplyRules()
|
||||||
|
{
|
||||||
|
$db = $this->db;
|
||||||
|
$query = $db->select()->from(
|
||||||
|
['s' => 'icinga_service'],
|
||||||
|
[
|
||||||
|
'id' => 's.id',
|
||||||
|
'name' => 's.object_name',
|
||||||
|
'assign_filter' => 's.assign_filter',
|
||||||
|
]
|
||||||
|
)->where('object_type = ? AND assign_filter IS NOT NULL', 'apply');
|
||||||
|
|
||||||
|
return $db->fetchAll($query);
|
||||||
|
}
|
||||||
|
}
|
118
library/Director/Web/Table/IcingaHostServiceTable.php
Normal file
118
library/Director/Web/Table/IcingaHostServiceTable.php
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
use ipl\Web\Table\ZfQueryBasedTable;
|
||||||
|
|
||||||
|
class IcingaHostServiceTable extends ZfQueryBasedTable
|
||||||
|
{
|
||||||
|
protected $title;
|
||||||
|
|
||||||
|
/** @var IcingaHost */
|
||||||
|
protected $host;
|
||||||
|
|
||||||
|
protected $inheritedBy;
|
||||||
|
|
||||||
|
protected $searchColumns = [
|
||||||
|
'service',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function load(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$table = new static($host->getConnection());
|
||||||
|
$table->setHost($host);
|
||||||
|
$table->attributes()->set('data-base-target', '_self');
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->host = $host;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInheritedBy(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->inheritedBy = $host;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderRow($row)
|
||||||
|
{
|
||||||
|
return $this::row([
|
||||||
|
$this->getServiceLink($row)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getServiceLink($row)
|
||||||
|
{
|
||||||
|
if ($target = $this->inheritedBy) {
|
||||||
|
$params = array(
|
||||||
|
'name' => $target->object_name,
|
||||||
|
'service' => $row->service,
|
||||||
|
'inheritedFrom' => $row->host,
|
||||||
|
);
|
||||||
|
|
||||||
|
return Link::create(
|
||||||
|
$row->service,
|
||||||
|
'director/host/inheritedservice',
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row->object_type === 'apply') {
|
||||||
|
$params['id'] = $row->id;
|
||||||
|
} else {
|
||||||
|
$params = array('name' => $row->service);
|
||||||
|
if ($row->host !== null) {
|
||||||
|
$params['host'] = $row->host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Link::create(
|
||||||
|
$row->service,
|
||||||
|
'director/service/edit',
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumnsToBeRendered()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->title ?: $this->translate('Servicename'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareQuery()
|
||||||
|
{
|
||||||
|
return $this->db()->select()->from(
|
||||||
|
['s' => 'icinga_service'],
|
||||||
|
[
|
||||||
|
'id' => 's.id',
|
||||||
|
'host_id' => 's.host_id',
|
||||||
|
'host' => 'h.object_name',
|
||||||
|
'service' => 's.object_name',
|
||||||
|
'object_type' => 's.object_type',
|
||||||
|
]
|
||||||
|
)->joinLeft(
|
||||||
|
['h' => 'icinga_host'],
|
||||||
|
'h.id = s.host_id',
|
||||||
|
[]
|
||||||
|
)->where(
|
||||||
|
's.host_id = ?',
|
||||||
|
$this->host->get('id')
|
||||||
|
)->order('s.object_name');
|
||||||
|
}
|
||||||
|
}
|
189
library/Director/Web/Table/IcingaServiceSetServiceTable.php
Normal file
189
library/Director/Web/Table/IcingaServiceSetServiceTable.php
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||||
|
use ipl\Html\Element;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
use ipl\Web\Table\ZfQueryBasedTable;
|
||||||
|
|
||||||
|
class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
||||||
|
{
|
||||||
|
/** @var IcingaServiceSet */
|
||||||
|
protected $set;
|
||||||
|
|
||||||
|
protected $title;
|
||||||
|
|
||||||
|
/** @var IcingaHost */
|
||||||
|
protected $host;
|
||||||
|
|
||||||
|
/** @var IcingaHost */
|
||||||
|
protected $affectedHost;
|
||||||
|
|
||||||
|
protected $searchColumns = [
|
||||||
|
'service',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaServiceSet $set
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function load(IcingaServiceSet $set)
|
||||||
|
{
|
||||||
|
$table = new static($set->getConnection());
|
||||||
|
$table->set = $set;
|
||||||
|
$table->attributes()->set('data-base-target', '_self');
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $title
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->host = $host;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAffectedHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$this->affectedHost = $host;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addHeaderColumnsTo(Element $parent)
|
||||||
|
{
|
||||||
|
if ($this->host || $this->affectedHost) {
|
||||||
|
$this->addHostHeaderTo($parent);
|
||||||
|
} else {
|
||||||
|
parent::addHeaderColumnsTo($parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getServiceLink($row)
|
||||||
|
{
|
||||||
|
if ($this->affectedHost) {
|
||||||
|
$params = [
|
||||||
|
'name' => $this->affectedHost->getObjectName(),
|
||||||
|
'service' => $row->service,
|
||||||
|
'set' => $row->service_set
|
||||||
|
];
|
||||||
|
$url = 'director/host/servicesetservice';
|
||||||
|
} else {
|
||||||
|
$params = [
|
||||||
|
'name' => $row->service,
|
||||||
|
'set' => $row->service_set
|
||||||
|
];
|
||||||
|
$url = 'director/service';
|
||||||
|
}
|
||||||
|
|
||||||
|
return Link::create(
|
||||||
|
$row->service,
|
||||||
|
$url,
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderRow($row)
|
||||||
|
{
|
||||||
|
$tr = $this::row([
|
||||||
|
$this->getServiceLink($row)
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($row->disabled === 'y') {
|
||||||
|
$tr->attributes()->add('class', 'disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumnsToBeRendered()
|
||||||
|
{
|
||||||
|
return ['Will not be rendered'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTitle()
|
||||||
|
{
|
||||||
|
return $this->title ?: $this->translate('Servicename');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addHostHeaderTo(Element $parent)
|
||||||
|
{
|
||||||
|
if (! $this->host) {
|
||||||
|
$deleteLink = '';
|
||||||
|
} elseif ($this->affectedHost->get('id') !== $this->host->get('id')) {
|
||||||
|
$host = $this->host;
|
||||||
|
$deleteLink = Link::create(
|
||||||
|
$host->getObjectName(),
|
||||||
|
'director/host/services',
|
||||||
|
['name' => $host->getObjectName()],
|
||||||
|
[
|
||||||
|
'class' => 'icon-paste',
|
||||||
|
'style' => 'float: right; font-weight: normal',
|
||||||
|
'data-base-target' => '_next',
|
||||||
|
'title' => sprintf(
|
||||||
|
$this->translate('This set has been inherited from %s'),
|
||||||
|
$host->getObjectName()
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$deleteLink = Link::create(
|
||||||
|
$this->translate('Remove'),
|
||||||
|
'director/host/removeset',
|
||||||
|
[
|
||||||
|
'name' => $this->host->getObjectName(),
|
||||||
|
'setId' => $this->set->get('id')
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => 'icon-cancel',
|
||||||
|
'style' => 'float: right; font-weight: normal',
|
||||||
|
'title' => $this->translate('Remove this set from this host')
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent->add($this::th([$this->getTitle(), $deleteLink]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareQuery()
|
||||||
|
{
|
||||||
|
return $this->db()->select()->from(
|
||||||
|
['s' => 'icinga_service'],
|
||||||
|
[
|
||||||
|
'id' => 's.id',
|
||||||
|
'service_set_id' => 's.service_set_id',
|
||||||
|
'host_id' => 'ss.host_id',
|
||||||
|
'service_set' => 'ss.object_name',
|
||||||
|
'service' => 's.object_name',
|
||||||
|
'disabled' => 's.disabled',
|
||||||
|
'object_type' => 's.object_type',
|
||||||
|
]
|
||||||
|
)->joinLeft(
|
||||||
|
['ss' => 'icinga_service_set'],
|
||||||
|
'ss.id = s.service_set_id',
|
||||||
|
[]
|
||||||
|
)->where(
|
||||||
|
's.service_set_id = ?',
|
||||||
|
$this->set->get('id')
|
||||||
|
)->order('s.object_name');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user