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

View File

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