CustomVariables: extend overrides to allow...

...overrides from multiple templates to be merged

fixes #813
This commit is contained in:
Thomas Gelf 2017-09-12 12:19:05 +02:00
parent 22e575f9b0
commit 53242894a8
2 changed files with 26 additions and 5 deletions

View File

@ -23,6 +23,8 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
private $position = 0;
private $overrideKeyName;
protected $idx = array();
protected static $allTables = array(
@ -111,7 +113,6 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
return array_key_exists($this->position, $this->idx);
}
/**
* Generic setter
*
@ -302,6 +303,12 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
return sha1(implode('|', $sums), true);
}
public function setOverrideKeyName($name)
{
$this->overrideKeyName = $name;
return $this;
}
public function toConfigString($renderExpressions = false)
{
$out = '';
@ -360,10 +367,18 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
*/
protected function renderSingleVar($key, $var, $renderExpressions = false)
{
return c::renderKeyValue(
$this->renderKeyName($key),
$var->toConfigStringPrefetchable($renderExpressions)
);
if ($key === $this->overrideKeyName) {
return c::renderKeyOperatorValue(
$this->renderKeyName($key),
'+=',
$var->toConfigStringPrefetchable($renderExpressions)
);
} else {
return c::renderKeyValue(
$this->renderKeyName($key),
$var->toConfigStringPrefetchable($renderExpressions)
);
}
}
protected function renderKeyName($key)

View File

@ -1220,6 +1220,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
} else {
$this->vars = CustomVariables::loadForStoredObject($this);
}
if ($this->getShortTableName() === 'host') {
$this->vars->setOverrideKeyName(
$this->getConnection()->settings()->override_services_varname
);
}
} else {
$this->vars = new CustomVariables();
}