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 <itl>', 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
This commit is contained in:
Thomas Gelf 2016-08-25 10:16:00 +00:00
parent 8c42e0f7d6
commit 9fb547a849
2 changed files with 37 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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)