From d8d12d38b45b3f110a8b0a48af0481b48119a09f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 3 Dec 2015 18:00:48 +0100 Subject: [PATCH] IcingaObject: add new helper methods for seconds --- library/Director/Objects/IcingaCommand.php | 6 +----- library/Director/Objects/IcingaEndpoint.php | 2 +- library/Director/Objects/IcingaObject.php | 11 +++++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index dfa02691..67c47c7b 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -74,11 +74,7 @@ class IcingaCommand extends IcingaObject protected function renderTimeout() { - $value = $this->timeout; - if ($value % 60 === 0) { - $value = ((int) $value / 60) . 'm'; - } - return c::renderKeyValue('timeout', $value); + return $this->renderPropertyAsSecond('timeout'); } public static function setPluginDir($pluginDir) diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index 0c9b7d29..1c8cbb48 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -24,6 +24,6 @@ class IcingaEndpoint extends IcingaObject protected function renderLog_duration() { - return c::renderKeyValue('log_duration', $this->log_duration); + return $this->renderPropertyAsSecond('log_duration'); } } diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 2152cdfc..51745384 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -705,6 +705,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return c::renderKeyValue($key, c::renderBoolean($this->$key)); } + protected function renderPropertyAsSeconds($key) + { + $value = $this->$key; + + if ($value % 60 === 0) { + $value = ((int) $value / 60) . 'm'; + } + + return c::renderKeyValue($key, $value); + } + protected function renderSuffix() { return "}\n\n";