diff --git a/application/controllers/InspectController.php b/application/controllers/InspectController.php new file mode 100644 index 00000000..500e8111 --- /dev/null +++ b/application/controllers/InspectController.php @@ -0,0 +1,44 @@ +view->title = $this->translate('Icinga2 object types'); + $api = $this->api(); + $types = $api->getTypes(); + $rootNodes = array(); + foreach ($types as $name => $type) { + if (property_exists($type, 'base')) { + $base = $type->base; + if (! property_exists($types[$base], 'children')) { + $types[$base]->children = array(); + } + + $types[$base]->children[$name] = $type; + } else { + $rootNodes[$name] = $type; + } + } + $this->view->types = $rootNodes; + } + + public function typeAction() + { + print_r($this->api()->getType($this->params->get('name'))); + exit; + } + + protected function api() + { + $apiconfig = $this->Config()->getSection('api'); + $client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port')); + $client->setCredentials($apiconfig->get('username'), $apiconfig->get('password')); + $api = new CoreApi($client); + return $api; + } +} diff --git a/application/views/scripts/inspect/types.phtml b/application/views/scripts/inspect/types.phtml new file mode 100644 index 00000000..387f10bd --- /dev/null +++ b/application/views/scripts/inspect/types.phtml @@ -0,0 +1,37 @@ + $node) { + $html .= '
  • '; + $link = $self->qlink( + $name, + 'director/inspect/type', + array('name' => $name), + array('class' => $node->abstract ? 'abstract' : 'object') + ); + if (property_exists($node, 'children')) { + $html .= ' '; + $html .= $link; + $html .= ''; + } else { + $html .= $link; + } + $html .= '
  • '; + } + + return $html; +} + +?> +
    +tabs ?> +

    escape($this->title) ?>

    +
    + +
    + +
    diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index 86939476..a8f9947b 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -15,6 +15,28 @@ class CoreApi $this->client = $client; } + public function getTypes() + { + return $this->client->get('types')->getResult('name'); + } + + public function getType($type) + { + $res = $this->client->get('types', array('name' => $type))->getResult('name'); + return $res[$type]; // TODO: error checking + } + + public function listObjects($type, $pluralType) + { + // TODO: more abstraction needed + return $this->client->get( + 'objects/' . $pluralType, + array( + 'attrs' => array($type . '.__name', $type . '.name'), + ) + )->getResult('__name'); + } + public function getModules() { return $this->client->get('config/packages')->getResult('name'); diff --git a/public/img/leaf.gif b/public/img/leaf.gif new file mode 100644 index 00000000..445769d3 Binary files /dev/null and b/public/img/leaf.gif differ diff --git a/public/img/tree.png b/public/img/tree.png new file mode 100644 index 00000000..298343ee Binary files /dev/null and b/public/img/tree.png differ