From 9094cf1f4e2e730153eb0dc3fe6c3fb94bb68a22 Mon Sep 17 00:00:00 2001 From: Rodrigo Araujo Date: Fri, 22 Oct 2021 16:20:15 +0100 Subject: [PATCH] Fix host services losing configuration from parent imports when overriding service values --- .../Director/CustomVariable/CustomVariables.php | 5 ++--- library/Director/IcingaConfig/IcingaConfig.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index 848adb902..fbed9fd56 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -393,10 +393,9 @@ public function toLegacyConfigString() protected function renderSingleVar($key, $var, $renderExpressions = false) { if ($key === $this->overrideKeyName) { - return c::renderKeyOperatorValue( + return c::renderKeyValue( $this->renderKeyName($key), - '+=', - $var->toConfigStringPrefetchable($renderExpressions) + 'directorMergeOverrideConfig('.$this->renderKeyName($key) . ', ' . $var->toConfigStringPrefetchable($renderExpressions).')' ); } else { return c::renderKeyValue( diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 72edd7eeb..6dc5e6944 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -540,6 +540,20 @@ protected function renderHostOverridableVars() ) } } + globals.directorMergeOverrideConfig = function(existing,overrides) { + if (existing) { + for (service => conf in overrides) { + if (existing[service]) { + existing[service] += conf + } else { + existing[service] = conf + } + } + return existing + } else { + return overrides + } + } template Service DirectorOverrideTemplate { /**