mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
parent
58accea801
commit
2691081349
158
application/controllers/HosttemplateController.php
Normal file
158
application/controllers/HosttemplateController.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\Controller\Extension\DirectorDb;
|
||||
use Icinga\Module\Director\Web\Table\ObjectsTableHost;
|
||||
use Icinga\Module\Director\Web\Table\TemplatesTable;
|
||||
use Icinga\Module\Director\Web\Table\TemplateUsageTable;
|
||||
use ipl\Html\FormattedString;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\CompatController;
|
||||
use ipl\Web\Component\UnorderedList;
|
||||
|
||||
class HosttemplateController extends CompatController
|
||||
{
|
||||
use DirectorDb;
|
||||
|
||||
public function objectsAction()
|
||||
{
|
||||
$template = $this->requireTemplate();
|
||||
$this
|
||||
->addSingleTab($this->translate('Hosts'))
|
||||
->setAutorefreshInterval(10)
|
||||
->addTitle(
|
||||
$this->translate('Hosts based on %s'),
|
||||
$template->getObjectName()
|
||||
)->addBackToUsageLink($template);
|
||||
|
||||
$table = new ObjectsTableHost($this->db());
|
||||
$table->setAuth($this->Auth());
|
||||
$table->filterTemplate($template, $this->params->get('inheritance', 'direct'));
|
||||
$table->renderTo($this);
|
||||
}
|
||||
|
||||
public function templatesAction()
|
||||
{
|
||||
$template = $this->requireTemplate();
|
||||
$this
|
||||
->addSingleTab($this->translate('Host Templates'))
|
||||
->setAutorefreshInterval(10)
|
||||
->addTitle(
|
||||
$this->translate('Host templates based on %s'),
|
||||
$template->getObjectName()
|
||||
)->addBackToUsageLink($template);
|
||||
|
||||
$table = TemplatesTable::create('host', $this->db());
|
||||
$table->filterTemplate($template, $this->params->get('inheritance', 'direct'));
|
||||
$table->renderTo($this);
|
||||
}
|
||||
|
||||
protected function addBackToUsageLink(IcingaObject $template)
|
||||
{
|
||||
$this->actions()->add(
|
||||
Link::create(
|
||||
$this->translate('Back'),
|
||||
'director/hosttemplate/usage',
|
||||
['name' => $template->getObjectName()],
|
||||
['class' => 'icon-left-big']
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function usageAction()
|
||||
{
|
||||
$template = $this->requireTemplate();
|
||||
$templateName = $template->getObjectName();
|
||||
|
||||
$this
|
||||
->addSingleTab($this->translate('Host Template Usage'))
|
||||
->addTitle($this->translate('Template: %s'), $templateName)
|
||||
->setAutorefreshInterval(10);
|
||||
|
||||
$this->actions()->add([
|
||||
Link::create(
|
||||
$this->translate('Modify'),
|
||||
'director/host/edit',
|
||||
['name' => $templateName],
|
||||
['class' => 'icon-edit']
|
||||
),
|
||||
Link::create(
|
||||
$this->translate('Preview'),
|
||||
'director/host/render',
|
||||
['name' => $templateName],
|
||||
[
|
||||
'title' => $this->translate('Template rendering preview'),
|
||||
'class' => 'icon-doc-text'
|
||||
]
|
||||
),
|
||||
Link::create(
|
||||
$this->translate('History'),
|
||||
'director/host/history',
|
||||
['name' => $templateName],
|
||||
[
|
||||
'title' => $this->translate('Template history'),
|
||||
'class' => 'icon-history'
|
||||
]
|
||||
)
|
||||
]);
|
||||
|
||||
$this->content()->addPrintf(
|
||||
$this->translate(
|
||||
'This is the "%s" Host Template. Based on this, you might want to:'
|
||||
),
|
||||
$templateName
|
||||
)->add(
|
||||
new UnorderedList([
|
||||
new FormattedString($this->translate('Create new Service Checks for %s'), [
|
||||
Link::create(
|
||||
$this->translate('specific Hosts'),
|
||||
'director/servicetemplate/addhost',
|
||||
['name' => $templateName]
|
||||
)
|
||||
]),
|
||||
new FormattedString($this->translate('Assign this Template multiple times using %s'), [
|
||||
Link::create(
|
||||
$this->translate('Apply Rules'),
|
||||
'director/service/add',
|
||||
['apply' => $templateName]
|
||||
)
|
||||
]),
|
||||
new FormattedString($this->translate('Create a new %s inheriting from this one'), [
|
||||
Link::create(
|
||||
$this->translate('Template'),
|
||||
'director/servicetemplate/addhost',
|
||||
['name' => $templateName]
|
||||
)
|
||||
]),
|
||||
new FormattedString($this->translate('Make a Service based on this Template member of a %s'), [
|
||||
Link::create(
|
||||
$this->translate('Service Set'),
|
||||
'director/servicetemplate/addtoset',
|
||||
['name' => $templateName]
|
||||
),
|
||||
])
|
||||
], [
|
||||
'class' => 'vertical-action-list'
|
||||
])
|
||||
)->add(
|
||||
Html::tag('h2', null, $this->translate('Current Template Usage'))
|
||||
);
|
||||
|
||||
$this->content()->add(
|
||||
TemplateUsageTable::forTemplate($template)
|
||||
);
|
||||
}
|
||||
|
||||
protected function requireTemplate()
|
||||
{
|
||||
return IcingaHost::load([
|
||||
'object_name' => $this->params->get('name')
|
||||
], $this->db());
|
||||
}
|
||||
}
|
22
library/Director/Web/Table/HostTemplateUsageTable.php
Normal file
22
library/Director/Web/Table/HostTemplateUsageTable.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
class HostTemplateUsageTable extends TemplateUsageTable
|
||||
{
|
||||
public function getTypes()
|
||||
{
|
||||
return [
|
||||
'templates' => $this->translate('Templates'),
|
||||
'objects' => $this->translate('Objects'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTypeSummaryDefinitions()
|
||||
{
|
||||
return [
|
||||
'templates' => $this->getSummaryLine('template'),
|
||||
'objects' => $this->getSummaryLine('object'),
|
||||
];
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Db\IcingaObjectFilterHelper;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Restriction\HostgroupRestriction;
|
||||
use Icinga\Module\Director\Restriction\ObjectRestriction;
|
||||
@ -81,6 +82,20 @@ class ObjectsTable extends ZfQueryBasedTable
|
||||
return $this->showColumns;
|
||||
}
|
||||
|
||||
public function filterTemplate(
|
||||
IcingaObject $template,
|
||||
$inheritance = Db\IcingaObjectFilterHelper::INHERIT_DIRECT
|
||||
) {
|
||||
IcingaObjectFilterHelper::filterByTemplate(
|
||||
$this->getQuery(),
|
||||
$template,
|
||||
'o',
|
||||
$inheritance
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getMainLinkLabel($row)
|
||||
{
|
||||
return $row->object_name;
|
||||
|
@ -8,6 +8,8 @@ class ObjectsTableHost extends ObjectsTable
|
||||
{
|
||||
use MultiSelect;
|
||||
|
||||
protected $type = 'host';
|
||||
|
||||
protected $searchColumns = [
|
||||
'o.object_name',
|
||||
'o.display_name',
|
||||
|
@ -38,20 +38,6 @@ class ObjectsTableService extends ObjectsTable
|
||||
);
|
||||
}
|
||||
|
||||
public function filterTemplate(
|
||||
IcingaService $template,
|
||||
$inheritance = IcingaObjectFilterHelper::INHERIT_DIRECT
|
||||
) {
|
||||
IcingaObjectFilterHelper::filterByTemplate(
|
||||
$this->getQuery(),
|
||||
$template,
|
||||
'o',
|
||||
$inheritance
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
|
@ -116,7 +116,8 @@ abstract class TemplateUsageTable extends Table
|
||||
);
|
||||
//$indirect->templates = count($ids) - 1;
|
||||
$total = [];
|
||||
foreach (['templates', 'objects', 'applyrules', 'setmembers'] as $type) {
|
||||
$types = array_keys($this->getTypes());
|
||||
foreach ($types as $type) {
|
||||
$total[$type] = $direct->$type + $indirect->$type;
|
||||
}
|
||||
|
||||
|
@ -48,16 +48,9 @@ class TemplatesTable extends ZfQueryBasedTable
|
||||
)
|
||||
];
|
||||
|
||||
// TODO: remove this once we have host template usage
|
||||
if ($type === 'host') {
|
||||
$url = Url::fromPath("director/host", [
|
||||
'name' => $row->object_name
|
||||
]);
|
||||
} else {
|
||||
$url = Url::fromPath("director/${type}template/usage", [
|
||||
'name' => $row->object_name
|
||||
]);
|
||||
}
|
||||
$url = Url::fromPath("director/${type}template/usage", [
|
||||
'name' => $row->object_name
|
||||
]);
|
||||
|
||||
return $this::tr([
|
||||
$this::td(new Link($caption, $url)),
|
||||
|
Loading…
x
Reference in New Issue
Block a user