[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject/Host/Service: provide interval helpers

git at icinga.org git at icinga.org
Sun Feb 28 17:12:40 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Feb 28 14:21:00 2016 +0100

IcingaObject/Host/Service: provide interval helpers

---

 library/Director/Objects/IcingaHost.php    |    5 +++++
 library/Director/Objects/IcingaObject.php  |   24 ++++++++++++++++++++
 library/Director/Objects/IcingaService.php |   33 +++++-----------------------
 3 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php
index e3fdc0b..af2e346 100644
--- a/library/Director/Objects/IcingaHost.php
+++ b/library/Director/Objects/IcingaHost.php
@@ -64,6 +64,11 @@ class IcingaHost extends IcingaObject
         'accept_config'         => 'accept_config'
     );
 
+    protected $intervalProperties = array(
+        'check_interval' => 'check_interval',
+        'retry_interval' => 'retry_interval',
+    );
+
     protected $supportsCustomVars = true;
 
     protected $supportsGroups = true;
diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 4748b36..6151358 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -43,6 +43,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         // property => PropertyClass
     );
 
+    /**
+     * Array of interval property names
+     *
+     * Those will be automagically munged to integers (seconds) and rendered
+     * as durations (e.g. 2m 10s). Array expects (propertyName => renderedKey)
+     *
+     * @var array
+     */
+    protected $intervalProperties = array();
+
     private $vars;
 
     private $groups;
@@ -64,6 +74,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return array_key_exists($property, $this->booleans);
     }
 
+    public function propertyIsInterval($property)
+    {
+        return array_key_exists($property, $this->intervalProperties);
+    }
+
     public function hasRelation($property)
     {
         return array_key_exists($property, $this->relations);
@@ -217,6 +232,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             // TODO: what shall we do if it is a template? Fail?
         }
 
+        if ($this->propertyIsInterval($key)) {
+            return parent::set($key, c::parseInterval($value));
+        }
+
         return parent::set($key, $value);
     }
 
@@ -829,6 +848,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
                             c::renderBoolean($value)
                         );
                     }
+                } elseif ($this->propertyIsInterval($key)) {
+                    $out .= c::renderKeyValue(
+                        $this->intervalProperties[$key],
+                        c::renderInterval($value)
+                    );
                 } elseif (substr($key, -3) === '_id'
                      && $this->hasRelation($relKey = substr($key, 0, -3))
                 ) {
diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php
index eb2dea4..2b1be43 100644
--- a/library/Director/Objects/IcingaService.php
+++ b/library/Director/Objects/IcingaService.php
@@ -57,6 +57,11 @@ class IcingaService extends IcingaObject
         'use_agent'             => 'use_agent',
     );
 
+    protected $intervalProperties = array(
+        'check_interval' => 'check_interval',
+        'retry_interval' => 'retry_interval',
+    );
+
     protected $supportsGroups = true;
 
     protected $supportsCustomVars = true;
@@ -117,34 +122,6 @@ class IcingaService extends IcingaObject
         return '';
     }
 
-    /**
-     * Use duration time renderer helper
-     *
-     * Avoid complaints for method names with underscore:
-     * @codingStandardsIgnoreStart
-     *
-     * @return string
-     */
-    protected function renderCheck_Interval()
-    {
-        // @codingStandardsIgnoreEnd
-        return $this->renderPropertyAsSeconds('check_interval');
-    }
-
-    /**
-     * Use duration time renderer helper
-     *
-     * Avoid complaints for method names with underscore:
-     * @codingStandardsIgnoreStart
-     *
-     * @return string
-     */
-    protected function renderRetry_Interval()
-    {
-        // @codingStandardsIgnoreEnd
-        return $this->renderPropertyAsSeconds('retry_interval');
-    }
-
     public function hasCheckCommand()
     {
         return $this->getResolvedProperty('check_command_id') !== null;



More information about the icinga-checkins mailing list