IcingaService: allow host vars to override vars...

...for applied services

refs #12546
This commit is contained in:
Thomas Gelf 2016-09-08 10:45:02 +00:00
parent fc18e9eb49
commit 4f4b6eb63a
4 changed files with 40 additions and 0 deletions

View File

@ -457,12 +457,34 @@ class IcingaConfig
)
)->prepend(
"\nconst DirectorStageDir = dirname(dirname(current_filename))\n"
. $this->renderHostOverridableVars()
. $this->renderMagicApplyFor()
);
return $this;
}
protected function renderHostOverridableVars()
{
$settings = $this->connection->settings();
return sprintf(
'
const DirectorVarsOverride = "%s"
template Service "%s" {
if (vars) {
vars += host.vars[DirectorVarsOverride][name]
} else {
vars = host.vars[DirectorVarsOverride][name]
}
}
',
$settings->override_services_varname,
$settings->override_services_templatename
);
}
protected function renderMagicApplyFor()
{
if (! $this->usesMagicApplyFor()) {

View File

@ -156,6 +156,20 @@ class IcingaService extends IcingaObject
)->object_type === 'template';
}
protected function renderSuffix()
{
if ($this->isApplyRule()) {
return $this->renderImportHostVarOverrides() . parent::renderSuffix();
} else {
return parent::renderSuffix();
}
}
protected function renderImportHostVarOverrides()
{
return "\n" . ' import "host var overrides (Director)"' . "\n";
}
protected function renderCustomExtensions()
{
// A hand-crafted command endpoint overrides use_agent

View File

@ -10,5 +10,7 @@ apply Service "___TEST___service" {
assign where match("127.*", host.address)
assign where host.vars.env == "test"
import "host var overrides (Director)"
}

View File

@ -10,5 +10,7 @@ apply Service "___TEST___service" {
assign where match("128.*", host.address)
ignore where host.name == "localhost"
import "host var overrides (Director)"
}