[icinga-checkins] icinga.org: icingaweb2-module-director/feature/object-lists-12965: ObjectsCommand: initial import

git at icinga.org git at icinga.org
Tue Oct 25 00:04:01 CEST 2016


Module: icingaweb2-module-director
Branch: feature/object-lists-12965
Commit: e0d0a4e7b34097333fcef6f57f6deb89e4fae4fe
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=e0d0a4e7b34097333fcef6f57f6deb89e4fae4fe

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 24 19:44:43 2016 +0000

ObjectsCommand: initial import

---

 library/Director/Cli/ObjectsCommand.php |   89 +++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/library/Director/Cli/ObjectsCommand.php b/library/Director/Cli/ObjectsCommand.php
new file mode 100644
index 0000000..f70c605
--- /dev/null
+++ b/library/Director/Cli/ObjectsCommand.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Icinga\Module\Director\Cli;
+
+use Icinga\Module\Director\Cli\Command;
+use Icinga\Module\Director\Objects\IcingaObject;
+
+class ObjectCommand extends Command
+{
+    protected $type;
+
+    private $objects;
+
+    /**
+     * List all objects of this type
+     *
+     * Use this command to get a list of all matching objeccts
+     *
+     * USAGE
+     *
+     * icingacli director <types> list [options]
+     *
+     * OPTIONS
+     *
+     *   --json        Use JSON format
+     *   --no-pretty   JSON is pretty-printed per default (for PHP >= 5.4)
+     *                 Use this flag to enforce unformatted JSON
+     */
+    public function listAction()
+    {
+        $db = $this->db();
+        exit;
+    }
+
+    /**
+     * Delete a specific object
+     *
+     * Use this command to delete a single Icinga object
+     *
+     * USAGE
+     *
+     * icingacli director <types> fetch [options]
+     *
+     * OPTIONS
+     *
+     *   --resolved    Resolve all inherited properties and show a flat
+     *                 object
+     *   --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
+     */
+    public function fetchAction()
+    {
+        if ($this->params->shift('json')) {
+            $res = array();
+            foreach ($this->getObjects() as $object) {
+            }
+        } else {
+            foreach ($this->getObjects() as $object) {
+            }
+        }
+    }
+
+    protected function getObjects()
+    {
+        if ($this->objects === null) {
+            $this->objects = IcingaObject::loadAllByType(
+                $this->getType(),
+                $this->db()
+            );
+        }
+
+        return $this->objects;
+    }
+
+    protected function getType()
+    {
+        if ($this->type === null) {
+            // Extract the command class name...
+            $className = substr(strrchr(get_class($this), '\\'), 1);
+            // ...and strip the Command extension
+            $this->type = rtrim(substr($className, 0, -7), 's');
+        }
+
+        return $this->type;
+    }
+}



More information about the icinga-checkins mailing list