parent
8a57ca9437
commit
a540fd08aa
|
@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -37,8 +37,8 @@ class ObjectCommand extends Command
|
||||||
* --json Use JSON format
|
* --json Use JSON format
|
||||||
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
|
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
|
||||||
* Use this flag to enforce unformatted JSON
|
* Use this flag to enforce unformatted JSON
|
||||||
* --no-defaults Per default JSON output skips null or default values
|
* --no-defaults Per default JSON output ships null or default values
|
||||||
* With this flag you will get all properties
|
* With this flag you will skip those properties
|
||||||
*/
|
*/
|
||||||
public function showAction()
|
public function showAction()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Icinga\Module\Director\Cli;
|
||||||
use Icinga\Module\Director\Cli\Command;
|
use Icinga\Module\Director\Cli\Command;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
|
||||||
class ObjectCommand extends Command
|
class ObjectsCommand extends Command
|
||||||
{
|
{
|
||||||
protected $type;
|
protected $type;
|
||||||
|
|
||||||
|
@ -29,7 +29,20 @@ class ObjectCommand extends Command
|
||||||
public function listAction()
|
public function listAction()
|
||||||
{
|
{
|
||||||
$db = $this->db();
|
$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
|
* --json Use JSON format
|
||||||
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
|
* --no-pretty JSON is pretty-printed per default (for PHP >= 5.4)
|
||||||
* Use this flag to enforce unformatted JSON
|
* Use this flag to enforce unformatted JSON
|
||||||
* --no-defaults Per default JSON output skips null or default values
|
* --no-defaults Per default JSON output ships null or default values
|
||||||
* With this flag you will get all properties
|
* With this flag you will skip those properties
|
||||||
*/
|
*/
|
||||||
public function fetchAction()
|
public function fetchAction()
|
||||||
{
|
{
|
||||||
|
$resolved = $this->params->shift('resolved');
|
||||||
|
|
||||||
if ($this->params->shift('json')) {
|
if ($this->params->shift('json')) {
|
||||||
$res = array();
|
$noDefaults = $this->params->shift('no-defaults', false);
|
||||||
foreach ($this->getObjects() as $object) {
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->getObjects() as $object) {
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res[$object->getObjectName()] = $object->toPlainObject(false, $noDefaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $this->renderJson($res, !$this->params->shift('no-pretty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getObjects()
|
protected function getObjects()
|
||||||
|
|
Loading…
Reference in New Issue