From f8ef03435877f4a7e1e2454d7ddb300ebe4b915f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 19 Apr 2016 21:29:03 +0200 Subject: [PATCH] IcingaObject: add render target helpers --- library/Director/Objects/IcingaObject.php | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index d7885b19..c375936a 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Objects; use Icinga\Module\Director\CustomVariable\CustomVariables; use Icinga\Module\Director\Data\Db\DbObject; use Icinga\Module\Director\Db; +use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Data\Filter\Filter; @@ -1110,6 +1111,41 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer DirectorActivityLog::logRemoval($this, $this->connection); } + public function renderToConfig(IcingaConfig $config) + { + if ($this->isDisabled() || $this->isExternal()) { + return; + } + + $type = $this->getShortTableName(); + + if ($this->isTemplate()) { + $filename = strtolower($type) . '_templates'; + } elseif ($this->isApplyRule()) { + $filename = strtolower($type) . '_apply'; + } else { + $filename = strtolower($type) . 's'; + } + + $config->configFile( + 'zones.d/' . $this->getRenderingZone($config) + )->addObject($this); + } + + public function getRenderingZone(IcingaConfig $config = null) + { + if ($this->zone_id) { + // Config has a lookup cache, is faster: + return $config->getZoneName($this->zone_id); + } + + if ($this->isTemplate() || $this->isApplyRule()) { + return $this->connection->getDefaultGlobalZoneName(); + } + + return $this->connection->getMasterZoneName(); + } + protected function renderImports() { // TODO: parent_host ORDERed by weigth...