mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 11:19:16 +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(
|
)->prepend(
|
||||||
"\nconst DirectorStageDir = dirname(dirname(current_filename))\n"
|
"\nconst DirectorStageDir = dirname(dirname(current_filename))\n"
|
||||||
|
. $this->renderHostOverridableVars()
|
||||||
. $this->renderMagicApplyFor()
|
. $this->renderMagicApplyFor()
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
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()
|
protected function renderMagicApplyFor()
|
||||||
{
|
{
|
||||||
if (! $this->usesMagicApplyFor()) {
|
if (! $this->usesMagicApplyFor()) {
|
||||||
|
@ -156,6 +156,20 @@ class IcingaService extends IcingaObject
|
|||||||
)->object_type === 'template';
|
)->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()
|
protected function renderCustomExtensions()
|
||||||
{
|
{
|
||||||
// A hand-crafted command endpoint overrides use_agent
|
// A hand-crafted command endpoint overrides use_agent
|
||||||
|
@ -10,5 +10,7 @@ apply Service "___TEST___service" {
|
|||||||
|
|
||||||
assign where match("127.*", host.address)
|
assign where match("127.*", host.address)
|
||||||
assign where host.vars.env == "test"
|
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)
|
assign where match("128.*", host.address)
|
||||||
ignore where host.name == "localhost"
|
ignore where host.name == "localhost"
|
||||||
|
|
||||||
|
import "host var overrides (Director)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user