From a761bb108b4073260110f103ca10079d0a737aa4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 17 Jun 2016 11:55:48 +0200 Subject: [PATCH] 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 935fe4c1..b7e5da44 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 b96818e1..207b27e0 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');