[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaService: render dedicated host before imports

git at icinga.org git at icinga.org
Fri Jun 17 11:57:00 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Jun 17 11:55:48 2016 +0200

IcingaService: render dedicated host before imports

This fixes issues with object and apply types showing different
behaviour in Icinga 2 when inheriting the very same template.

---

 library/Director/Objects/IcingaObject.php  |   19 +++++++++++++++++--
 library/Director/Objects/IcingaService.php |    2 ++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 935fe4c..b7e5da4 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -57,6 +57,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
 
     protected $loadedRelatedSets = array();
 
+    // Will be rendered first, before imports
+    protected $prioritizedProperties = array();
+
     /**
      * Array of interval property names
      *
@@ -1140,11 +1143,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
     protected function renderProperties()
     {
         $out = '';
-        $blacklist = array(
+        $blacklist = array_merge(array(
             'id',
             'object_name',
             'object_type',
-        );
+        ), $this->prioritizedProperties);
 
         foreach ($this->properties as $key => $value) {
             if (in_array($key, $blacklist)) {
@@ -1157,6 +1160,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return $out;
     }
 
+    protected function renderPrioritizedProperties()
+    {
+        $out = '';
+
+        foreach ($this->prioritizedProperties as $key) {
+            $out .= $this->renderObjectProperty($key, $this->properties[$key]);
+        }
+
+        return $out;
+    }
+
     protected function renderObjectProperty($key, $value)
     {
         if (substr($key, -3) === '_id') {
@@ -1351,6 +1365,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
     {
         $str = implode(array(
             $this->renderObjectHeader(),
+            $this->renderPrioritizedProperties(),
             $this->renderImports(),
             $this->renderProperties(),
             $this->renderRanges(),
diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php
index b96818e..207b27e 100644
--- a/library/Director/Objects/IcingaService.php
+++ b/library/Director/Objects/IcingaService.php
@@ -76,6 +76,8 @@ class IcingaService extends IcingaObject
 
     protected $keyName = array('host_id', 'object_name');
 
+    protected $prioritizedProperties = array('host_id');
+
     public function getCheckCommand()
     {
         $id = $this->getResolvedProperty('check_command_id');



More information about the icinga-checkins mailing list