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.
This commit is contained in:
Thomas Gelf 2016-06-17 11:55:48 +02:00
parent dc3a2ca999
commit a761bb108b
2 changed files with 19 additions and 2 deletions

View File

@ -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(),

View File

@ -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');