diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index e3fdc0b0..af2e3464 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 4748b363..61513582 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 eb2dea41..2b1be431 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;