[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaCommand/TimePeriod: use internalized templates

git at icinga.org git at icinga.org
Thu Aug 25 12:32:21 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 9fb547a849500ccb989bf8efe7f02fe61ea09ef2
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=9fb547a849500ccb989bf8efe7f02fe61ea09ef2

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Aug 25 10:16:00 2016 +0000

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

---

 library/Director/Objects/IcingaCommand.php    |   32 +++++++++++++++++++++----
 library/Director/Objects/IcingaTimePeriod.php |    8 ++++++-
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php
index 0d799e5..1b1d0cf 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 ($this->methods_execute) {
+            $itlImport = sprintf(
+                '    import "%s"' . "\n",
+                $this->hiddenExecuteTemplates[$this->methods_execute]
+            );
+        } else {
+            $itlImport = '';
+        }
 
+        $execute = $this->getResolvedProperty('methods_execute');
         if ($execute === 'PluginNotification') {
-            return $this->renderObjectHeaderWithType('NotificationCommand');
+            return $this->renderObjectHeaderWithType('NotificationCommand') . $itlImport;
         } elseif ($execute === 'PluginEvent') {
-            return $this->renderObjectHeaderWithType('EventCommand');
+            return $this->renderObjectHeaderWithType('EventCommand') . $itlImport;
         } else {
-            return parent::renderObjectHeader();
+            return parent::renderObjectHeader() . $itlImport;
         }
     }
 
diff --git a/library/Director/Objects/IcingaTimePeriod.php b/library/Director/Objects/IcingaTimePeriod.php
index 6f766f5..c912eb0 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)



More information about the icinga-checkins mailing list