From 146b543fef5986095fb6b908c34fbd5c7c75eefc Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 13 Nov 2015 23:50:41 +0100 Subject: [PATCH] CoreApi: first attempts to fetch object instances --- library/Director/Core/CoreApi.php | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index 6ee20cf8..79955674 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -78,6 +78,61 @@ class CoreApi return current($this->listModuleStages('director', true)); } + protected function getDirectorObjects($type, $plural, $map) + { + $attrs = array_merge( + array_keys($map), + array('package', 'templates', 'active') + ); + + $objects = array(); + $result = $this->getObjects('zone', 'zones', $attrs); + + foreach ($result as $name => $row) { + $attrs = $row->attrs; + + $properties = array( + 'object_name' => $name, + 'object_type' => 'object' + ); + + foreach ($map as $key => $prop) { + if (property_exists($attrs, $key)) { + $properties[$prop] = $attrs->$key; + } + } + + $objects[$name] = IcingaObject::createByType($type, $properties, $this->db); + if (property_exists($attrs, 'templates') + && count($attrs->templates) > 1 + && $objects[$name]->supportsImports() + ) { + $imports = $attrs->templates; + array_shift($imports); + // TODO (prefetch?): $objects[$name]->imports = $imports; + } + } + + return $objects; + } + + public function getZoneObjects() + { + return $this->getMyObjects('Zone', 'zones', array( + 'parent' => 'parent', + 'global' => 'is_global', + )); + } + + public function getCheckCommandObjects() + { + return $this->getObjects('CheckCommand', 'CheckCommands'); + return $this->getMyObjects('Zone', 'zones', array( + 'parent' => 'parent', + 'global' => 'is_global', + )); + } + public function listModuleStages($name, $active = null) { $modules = $this->getModules();