From 9fb547a849500ccb989bf8efe7f02fe61ea09ef2 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 25 Aug 2016 10:16:00 +0000 Subject: [PATCH] IcingaCommand/TimePeriod: use internalized templates Icinga 2.5 moved a few default templates from ITL to the core itself and deprecated directly setting execute & similar properties. This change will break config deployment for 2.4.x environments without 'include ', but this would rarely be the case. This commit also changed how we work with inherited properties to render the right object type based on 'execute' if none is set (but got inherited). fixes #12443 fixes #12543 --- library/Director/Objects/IcingaCommand.php | 38 +++++++++++++++---- library/Director/Objects/IcingaTimePeriod.php | 8 +++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index 0d799e52..1b1d0cf9 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -39,6 +39,20 @@ class IcingaCommand extends IcingaObject protected static $pluginDir; + protected $hiddenExecuteTemplates = array( + 'PluginCheck' => 'plugin-check-command', + 'PluginNotification' => 'plugin-notification-command', + 'PluginEvent' => 'plugin-event-command', + + // Special, internal: + 'IcingaCheck' => 'icinga-check-command', + 'ClusterCheck' => 'cluster-check-command', + 'ClusterZoneCheck' => 'plugin-check-command', + 'IdoCheck' => 'ido-check-command', + 'RandomCheck' => 'random-check-command', + 'CrlCheck' => 'clr-check-command', + ); + /** * Render the 'medhods_execute' property as 'execute' * @@ -52,19 +66,27 @@ class IcingaCommand extends IcingaObject protected function renderMethods_execute() { // @codingStandardsIgnoreEnd - return c::renderKeyValue('execute', $this->methods_execute); + return ''; } protected function renderObjectHeader() { - $execute = $this->getResolvedProperty('methods_execute'); - - if ($execute === 'PluginNotification') { - return $this->renderObjectHeaderWithType('NotificationCommand'); - } elseif ($execute === 'PluginEvent') { - return $this->renderObjectHeaderWithType('EventCommand'); + if ($this->methods_execute) { + $itlImport = sprintf( + ' import "%s"' . "\n", + $this->hiddenExecuteTemplates[$this->methods_execute] + ); } else { - return parent::renderObjectHeader(); + $itlImport = ''; + } + + $execute = $this->getResolvedProperty('methods_execute'); + if ($execute === 'PluginNotification') { + return $this->renderObjectHeaderWithType('NotificationCommand') . $itlImport; + } elseif ($execute === 'PluginEvent') { + return $this->renderObjectHeaderWithType('EventCommand') . $itlImport; + } else { + return parent::renderObjectHeader() . $itlImport; } } diff --git a/library/Director/Objects/IcingaTimePeriod.php b/library/Director/Objects/IcingaTimePeriod.php index 6f766f5c..c912eb02 100644 --- a/library/Director/Objects/IcingaTimePeriod.php +++ b/library/Director/Objects/IcingaTimePeriod.php @@ -37,7 +37,13 @@ class IcingaTimePeriod extends IcingaObject public function renderUpdate_method() { // @codingStandardsIgnoreEnd - return c::renderKeyValue('update', $this->update_method); + return ''; + } + + protected function renderObjectHeader() + { + return parent::renderObjectHeader() + . ' import "legacy-timeperiod"' . "\n"; } public function isActive($now = null)