[icinga-checkins] icinga.org: icingaweb2-module-director/next: IcingaServiceSet: implement target zone for...

git at icinga.org git at icinga.org
Mon Nov 7 12:43:24 CET 2016


Module: icingaweb2-module-director
Branch: next
Commit: 7e749da9825ae6f4f7a9c1c8a708ff729253c644
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=7e749da9825ae6f4f7a9c1c8a708ff729253c644

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Nov  7 12:42:27 2016 +0100

IcingaServiceSet: implement target zone for...

...resolved v1 apply rules

---

 library/Director/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 0bb12b6..18b1b32 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 44d31e4..8de3741 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) {



More information about the icinga-checkins mailing list