Skip to content

Commit

Permalink
IcingaService: render dedicated host before imports
Browse files Browse the repository at this point in the history
This fixes issues with object and apply types showing different
behaviour in Icinga 2 when inheriting the very same template.
  • Loading branch information
Thomas-Gelf committed Jun 17, 2016
1 parent dc3a2ca commit a761bb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions library/Director/Objects/IcingaObject.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -1140,11 +1143,11 @@ protected function renderDisabled()
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)) {
Expand All @@ -1157,6 +1160,17 @@ protected function renderProperties()
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') {
Expand Down Expand Up @@ -1351,6 +1365,7 @@ public function toConfigString()
{
$str = implode(array(
$this->renderObjectHeader(),
$this->renderPrioritizedProperties(),
$this->renderImports(),
$this->renderProperties(),
$this->renderRanges(),
Expand Down
2 changes: 2 additions & 0 deletions library/Director/Objects/IcingaService.php
Expand Up @@ -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');
Expand Down

0 comments on commit a761bb1

Please sign in to comment.