mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
endpoint/inspect: add inspection for our peers
This commit is contained in:
parent
b2cb3183c8
commit
a93bcee68a
@ -6,4 +6,32 @@ use Icinga\Module\Director\Web\Controller\ObjectController;
|
|||||||
|
|
||||||
class EndpointController extends ObjectController
|
class EndpointController extends ObjectController
|
||||||
{
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
if ($this->isPeer()) {
|
||||||
|
$params['endpoint'] = $this->object->object_name;
|
||||||
|
|
||||||
|
$this->getTabs()->add('inspect', array(
|
||||||
|
'url' => 'director/inspect/types',
|
||||||
|
'urlParams' => $params,
|
||||||
|
'label' => $this->translate('Inspect')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isPeer()
|
||||||
|
{
|
||||||
|
if (! $this->object) return false;
|
||||||
|
|
||||||
|
$apiconfig = $this->Config()->getSection('api');
|
||||||
|
$host = $apiconfig->get('address');
|
||||||
|
$port = $apiconfig->get('port');
|
||||||
|
|
||||||
|
if ($host === $this->object->host
|
||||||
|
&& $port === $this->object->port
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Controllers;
|
namespace Icinga\Module\Director\Controllers;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Core\CoreApi;
|
||||||
|
use Icinga\Module\Director\Core\RestApiClient;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaEndpoint;
|
||||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
|
|
||||||
class InspectController extends ActionController
|
class InspectController extends ActionController
|
||||||
{
|
{
|
||||||
public function typesAction()
|
public function typesAction()
|
||||||
{
|
{
|
||||||
$this->view->title = $this->translate('Icinga2 object types');
|
$this->view->title = sprintf(
|
||||||
|
$this->translate('Icinga2 Objects: %s'),
|
||||||
|
$this->view->endpoint
|
||||||
|
);
|
||||||
$api = $this->api();
|
$api = $this->api();
|
||||||
$types = $api->getTypes();
|
$types = $api->getTypes();
|
||||||
$rootNodes = array();
|
$rootNodes = array();
|
||||||
@ -30,6 +36,10 @@ class InspectController extends ActionController
|
|||||||
public function typeAction()
|
public function typeAction()
|
||||||
{
|
{
|
||||||
$typeName = $this->params->get('name');
|
$typeName = $this->params->get('name');
|
||||||
|
$this->view->title = sprintf(
|
||||||
|
$this->translate('Object type "%s"'),
|
||||||
|
$typeName
|
||||||
|
);
|
||||||
$this->view->type = $type = $this->api()->getType($typeName);
|
$this->view->type = $type = $this->api()->getType($typeName);
|
||||||
if ($type->abstract) {
|
if ($type->abstract) {
|
||||||
return;
|
return;
|
||||||
@ -84,4 +94,15 @@ class InspectController extends ActionController
|
|||||||
$this->view->status = $status = $this->api()->getStatus();
|
$this->view->status = $status = $this->api()->getStatus();
|
||||||
print_r($status); exit;
|
print_r($status); exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function api()
|
||||||
|
{
|
||||||
|
$this->view->endpoint = $this->params->get('endpoint');
|
||||||
|
$endpoint = IcingaEndpoint::load($this->view->endpoint, $this->db());
|
||||||
|
$apiconfig = $this->Config()->getSection('api');
|
||||||
|
$client = new RestApiClient($endpoint->host, $endpoint->port);
|
||||||
|
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
|
||||||
|
$api = new CoreApi($client);
|
||||||
|
return $api;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<pre>
|
<pre>
|
||||||
<?= $this->escape(print_r($this->object, 1)) ?>
|
<?= $this->renderPlainObject($this->object) ?>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
<?php if ($this->objects): ?>
|
||||||
<table class="common-table table-row-selectable" data-base-target="_next">
|
<table class="common-table table-row-selectable" data-base-target="_next">
|
||||||
<thead><tr><th><?= $this->translate('Object name') ?></th></tr></thead>
|
<thead><tr><th><?= $this->translate('Object name') ?></th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -11,10 +12,16 @@
|
|||||||
<tr><td><?= $this->qlink(
|
<tr><td><?= $this->qlink(
|
||||||
str_replace('!', ': ', $object),
|
str_replace('!', ': ', $object),
|
||||||
'director/inspect/object',
|
'director/inspect/object',
|
||||||
array('type' => $this->type->name, 'plural' => $this->type->plural_name, 'name' => $object)
|
array(
|
||||||
|
'endpoint' => $this->endpoint,
|
||||||
|
'type' => $this->type->name,
|
||||||
|
'plural' => $this->type->plural_name,
|
||||||
|
'name' => $object
|
||||||
|
)
|
||||||
) ?></td></tr>
|
) ?></td></tr>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<pre><?= $this->escape(print_r($this->type, 1)) ?></pre>
|
<?php endif ?>
|
||||||
|
<pre><?= $this->renderPlainObject($this->type) ?></pre>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,20 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function dumpTree($tree, $self, $level = 0)
|
function dumpTree($tree, $self, $showLinks = false, $level = 0)
|
||||||
{
|
{
|
||||||
$html = '';
|
$html = '';
|
||||||
foreach ($tree as $name => $node) {
|
foreach ($tree as $name => $node) {
|
||||||
$html .= '<li>';
|
$html .= '<li>';
|
||||||
|
|
||||||
|
if ($showLinks || $name === 'ConfigObject') {
|
||||||
$link = $self->qlink(
|
$link = $self->qlink(
|
||||||
$name,
|
$name,
|
||||||
'director/inspect/type',
|
'director/inspect/type',
|
||||||
array('name' => $name),
|
array('endpoint' => $self->endpoint, 'name' => $name),
|
||||||
array('class' => $node->abstract ? 'abstract' : 'object')
|
array('class' => $node->abstract ? 'abstract' : 'object')
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$link = sprintf(
|
||||||
|
'<a class="%s" href="#">%s</a>',
|
||||||
|
$node->abstract ? 'abstract' : 'object',
|
||||||
|
$name
|
||||||
|
);
|
||||||
|
}
|
||||||
if (property_exists($node, 'children')) {
|
if (property_exists($node, 'children')) {
|
||||||
$html .= '<span class="handle"> </span>';
|
$html .= '<span class="handle"> </span>';
|
||||||
$html .= $link;
|
$html .= $link;
|
||||||
$html .= '<ul>' . dumpTree($node->children, $self, $level + 1) . '</ul>';
|
$html .= '<ul>' . dumpTree(
|
||||||
|
$node->children,
|
||||||
|
$self,
|
||||||
|
$showLinks || $name === 'ConfigObject',
|
||||||
|
$level + 1
|
||||||
|
) . '</ul>';
|
||||||
} else {
|
} else {
|
||||||
$html .= $link;
|
$html .= $link;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user