mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-25 18:59:05 +02:00
IcingaService: allow host vars to override vars...
...for applied services refs #12546
This commit is contained in:
parent
fc18e9eb49
commit
4f4b6eb63a
@ -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()) {
|
||||
|
@ -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
|
||||
|
@ -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)"
|
||||
}
|
||||
|
||||
|
@ -10,5 +10,7 @@ apply Service "___TEST___service" {
|
||||
|
||||
assign where match("128.*", host.address)
|
||||
ignore where host.name == "localhost"
|
||||
|
||||
import "host var overrides (Director)"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user