cli/objects: provide new commands

fixes #12965
This commit is contained in:
Thomas Gelf 2016-11-03 12:32:51 +01:00
parent 8a57ca9437
commit a540fd08aa
4 changed files with 65 additions and 11 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Module\Director\Cli\ObjectsCommand;
/**
* List Icinga Commands
*
* Use this command to list Icinga Command objects
*/
class CommandsCommand extends ObjectsCommand
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Module\Director\Cli\ObjectsCommand;
/**
* Manage Icinga Hosts
*
* Use this command to list Icinga Host objects
*/
class HostsCommand extends ObjectsCommand
{
}

View File

@ -37,8 +37,8 @@ class ObjectCommand extends Command
* --json Use JSON format
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
* Use this flag to enforce unformatted JSON
* --no-defaults Per default JSON output skips null or default values
* With this flag you will get all properties
* --no-defaults Per default JSON output ships null or default values
* With this flag you will skip those properties
*/
public function showAction()
{

View File

@ -5,7 +5,7 @@ namespace Icinga\Module\Director\Cli;
use Icinga\Module\Director\Cli\Command;
use Icinga\Module\Director\Objects\IcingaObject;
class ObjectCommand extends Command
class ObjectsCommand extends Command
{
protected $type;
@ -29,7 +29,20 @@ class ObjectCommand extends Command
public function listAction()
{
$db = $this->db();
exit;
$result = array();
foreach ($this->getObjects() as $o) {
$result[] = $o->getObjectName();
}
sort($result);
if ($this->params->shift('json')) {
echo $this->renderJson($result, !$this->params->shift('no-pretty'));
} else {
foreach ($result as $name) {
echo $name . "\n";
}
}
}
/**
@ -48,19 +61,30 @@ class ObjectCommand extends Command
* --json Use JSON format
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
* Use this flag to enforce unformatted JSON
* --no-defaults Per default JSON output skips null or default values
* With this flag you will get all properties
* --no-defaults Per default JSON output ships null or default values
* With this flag you will skip those properties
*/
public function fetchAction()
{
$resolved = $this->params->shift('resolved');
if ($this->params->shift('json')) {
$noDefaults = $this->params->shift('no-defaults', false);
} else {
$this->fail('Currently only json is supported when fetching objects');
}
$db = $this->db();
$res = array();
foreach ($this->getObjects() as $object) {
if ($resolved) {
$object = $object::fromPlainObject($object->toPlainObject(true), $db);
}
} else {
foreach ($this->getObjects() as $object) {
}
$res[$object->getObjectName()] = $object->toPlainObject(false, $noDefaults);
}
echo $this->renderJson($res, !$this->params->shift('no-pretty'));
}
protected function getObjects()