From 7e749da9825ae6f4f7a9c1c8a708ff729253c644 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 7 Nov 2016 12:42:27 +0100 Subject: [PATCH] IcingaServiceSet: implement target zone for... ...resolved v1 apply rules --- .../IcingaConfig/IcingaConfigFile.php | 11 +++++++ library/Director/Objects/IcingaServiceSet.php | 31 ++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/library/Director/IcingaConfig/IcingaConfigFile.php b/library/Director/IcingaConfig/IcingaConfigFile.php index 0bb12b64..18b1b324 100644 --- a/library/Director/IcingaConfig/IcingaConfigFile.php +++ b/library/Director/IcingaConfig/IcingaConfigFile.php @@ -45,6 +45,17 @@ class IcingaConfigFile return $this; } + public function addContent($content) + { + if ($this->content === null) { + $this->content = $content; + } else { + $this->content .= $content; + } + $this->checksum = null; + return $this; + } + public function getObjectCount() { return $this->cntObject; diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index 44d31e45..8de37411 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -133,7 +133,11 @@ class IcingaServiceSet extends IcingaObject protected function getConfigHeaderComment(IcingaConfig $config) { if ($config->isLegacy()) { - $comment = "## Service Set '%s'\n\n"; + if ($this->get('assign_filter')) { + $comment = "## applied Service Set '%s'\n\n"; + } else { + $comment = "## Service Set '%s' on this host\n\n"; + } } else { $comment = "/** Service Set '%s' **/\n\n"; } @@ -162,12 +166,6 @@ class IcingaServiceSet extends IcingaObject // Loop over all services belonging to this set // generate every service with host_name host1,host2... -> not yet. And Zones? - $file = $config->configFile( - // TODO: zones.d? - 'zones.d/' . $this->getRenderingZone($config) . '/servicesets' - ); - - $file->prepend($this->getConfigHeaderComment($config)); $conn = $this->getConnection(); // Delegating this to the service would look, but this way it's faster @@ -179,22 +177,41 @@ class IcingaServiceSet extends IcingaObject $this->copyVarsToService($service); foreach ($hosts as $hostname) { + $file = $this->legacyHostnameServicesFile($hostname, $config); + $file->addContent($this->getConfigHeaderComment($config)); $service->set('host', $hostname); $file->addLegacyObject($service); } } } else { + foreach ($this->getServiceObjects() as $service) { $service->set('object_type', 'object'); $service->set('host_id', $this->get('host_id')); foreach ($this->vars() as $k => $var) { $service->$k = $var; } + $file = $this->legacyRelatedHostFile($service, $config); + $file->addContent($this->getConfigHeaderComment($config)); $file->addLegacyObject($service); } } } + protected function legacyHostnameServicesFile($hostname, IcingaConfig $config) + { + return $config->configFile( + 'director/' . IcingaHost::load($hostname, $this->getConnection())->getRenderingZone($config) . '/servicesets' + ); + } + + protected function legacyRelatedHostFile(IcingaService $service, IcingaConfig $config) + { + return $config->configFile( + 'director/' . $service->getRelated('host')->getRenderingZone($config) . '/servicesets' + ); + } + public function getRenderingZone(IcingaConfig $config = null) { if ($this->get('host_id') === null) {