diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 1c774f6e..87651eed 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\IcingaConfig; use Icinga\Application\Benchmark; use Icinga\Application\Hook; use Icinga\Application\Icinga; +use Icinga\Exception\ConfigurationError; use Icinga\Exception\IcingaException; use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Db\Cache\PrefetchCache; @@ -34,6 +35,8 @@ class IcingaConfig protected $generationTime; + protected $configFormat = 'v2'; + public static $table = 'director_generated_config'; public function __construct(Db $connection) @@ -64,6 +67,30 @@ class IcingaConfig return count($this->files); } + public function getConfigFormat() + { + return $this->configFormat; + } + + public function setConfigFormat($format) + { + if (! in_array($format, array('v1', 'v2'))) { + throw new ConfigurationError( + 'Only Icinga v1 and v2 config format is supported, got "%s"', + $format + ); + } + + $this->configFormat = $format; + + return $this; + } + + public function isLegacy() + { + return $this->configFormat === 'v1'; + } + public function getObjectCount() { $cnt = 0; diff --git a/library/Director/IcingaConfig/IcingaConfigFile.php b/library/Director/IcingaConfig/IcingaConfigFile.php index d9f89602..ae5f395e 100644 --- a/library/Director/IcingaConfig/IcingaConfigFile.php +++ b/library/Director/IcingaConfig/IcingaConfigFile.php @@ -81,6 +81,15 @@ class IcingaConfigFile return $this->checksum; } + public function addLegacyObjects($objects) + { + foreach ($objects as $object) { + $this->addLegacyObject($object); + } + + return $this; + } + public function addObjects($objects) { foreach ($objects as $object) { @@ -94,7 +103,18 @@ class IcingaConfigFile { $this->content .= $object->toConfigString(); $this->checksum = null; + return $this->addObjectStats($object); + } + public function addLegacyObject(IcingaObject $object) + { + $this->content .= $object->toLegacyConfigString(); + $this->checksum = null; + return $this->addObjectStats($object); + } + + protected function addObjectStats(IcingaObject $object) + { if ($object->hasProperty('object_type')) { $type = $object->object_type;