Object/HostController: delegate preview rendering
This commit is contained in:
parent
fddd4488b5
commit
3d03baff38
|
@ -120,46 +120,4 @@ class HostController extends ObjectController
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function renderAction()
|
||||
{
|
||||
$this->renderAgentExtras();
|
||||
return parent::renderAction();
|
||||
}
|
||||
|
||||
protected function renderAgentExtras()
|
||||
{
|
||||
$host = $this->object;
|
||||
$db = $this->db();
|
||||
if ($host->object_type !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($host->getResolvedProperty('has_agent') !== 'y') {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $host->object_name;
|
||||
if (IcingaEndpoint::exists($name, $db)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$props = array(
|
||||
'object_name' => $name,
|
||||
'object_type' => 'object',
|
||||
'log_duration' => 0
|
||||
);
|
||||
if ($host->getResolvedProperty('master_should_connect') === 'y') {
|
||||
$props['host'] = $host->getResolvedProperty('address');
|
||||
$props['zone_id'] = $host->getResolvedProperty('zone_id');
|
||||
}
|
||||
|
||||
$this->view->extraObjects = array(
|
||||
IcingaEndpoint::create($props),
|
||||
IcingaZone::create(array(
|
||||
'object_name' => $name,
|
||||
'parent' => $db->getMasterZoneName()
|
||||
), $db)->setEndpointList(array($name))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<?php if ($object->disabled === 'y'): ?>
|
||||
<p class="error"><?= $this->translate('This object will not be deployed as it has been disabled') ?></p>
|
||||
<?php endif ?>
|
||||
<?php if ($object->isExternal()): ?>
|
||||
<?php if ($this->isExternal): ?>
|
||||
<p><?= $this->translate(
|
||||
'This is an external object. It has been imported from Icinga 2 throught the'
|
||||
. ' Core API and cannot be managed with the Icinga Director. It is however'
|
||||
|
@ -19,7 +19,11 @@
|
|||
. ' object more enjoyable'
|
||||
) ?></p>
|
||||
<?php endif ?>
|
||||
<pre<?php if ($object->disabled === 'y'): ?> class="disabled"<?php endif ?>><?= $this->escape($object) ?><?php if ($this->extraObjects): ?>
|
||||
<?= implode('', $this->extraObjects) ?>
|
||||
<?php endif ?></pre>
|
||||
<?php foreach ($this->config->getFiles() as $filename => $file): ?>
|
||||
<?php if (! $this->isExternal): ?><h2><?= $this->escape($filename) ?></h2><?php endif ?>
|
||||
<pre<?php if ($this->isDisabled): ?> class="disabled"<?php elseif ($this->isExternal): ?> class="logfile"<?php endif ?>>
|
||||
<?= $this->escape($file->getContent()) ?>
|
||||
</pre>
|
||||
<?php endforeach ?>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@ use Exception;
|
|||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\InvalidPropertyException;
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
|
@ -103,23 +104,22 @@ abstract class ObjectController extends ActionController
|
|||
$type = $this->getType();
|
||||
$this->getTabs()->activate('render');
|
||||
$object = $this->object;
|
||||
$this->view->isDisabled = $object->disabled === 'y';
|
||||
$this->view->isExternal = $object->isExternal();
|
||||
|
||||
if ($this->params->shift('resolved')) {
|
||||
$this->view->object = $object::fromPlainObject(
|
||||
$object = $object::fromPlainObject(
|
||||
$object->toPlainObject(true),
|
||||
$object->getConnection()
|
||||
);
|
||||
|
||||
if ($object->imports()->count() > 0) {
|
||||
$this->view->actionLinks = $this->view->qlink(
|
||||
$this->translate('Show normal'),
|
||||
$this->getRequest()->getUrl()->without('resolved'),
|
||||
null,
|
||||
array('class' => 'icon-resize-small state-warning')
|
||||
);
|
||||
}
|
||||
$this->view->actionLinks = $this->view->qlink(
|
||||
$this->translate('Show normal'),
|
||||
$this->getRequest()->getUrl()->without('resolved'),
|
||||
null,
|
||||
array('class' => 'icon-resize-small state-warning')
|
||||
);
|
||||
} else {
|
||||
$this->view->object = $object;
|
||||
|
||||
if ($object->supportsImports() && $object->imports()->count() > 0) {
|
||||
$this->view->actionLinks = $this->view->qlink(
|
||||
|
@ -131,6 +131,18 @@ abstract class ObjectController extends ActionController
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->view->isExternal) {
|
||||
$object->object_type = 'object';
|
||||
}
|
||||
|
||||
if ($this->view->isDisabledd) {
|
||||
$object->disabled = 'n';
|
||||
}
|
||||
|
||||
$this->view->object = $object;
|
||||
$this->view->config = new IcingaConfig($this->db());
|
||||
$object->renderToConfig($this->view->config);
|
||||
|
||||
$this->view->title = sprintf(
|
||||
$this->translate('Config preview: %s'),
|
||||
$object->object_name
|
||||
|
|
Loading…
Reference in New Issue