IcingaObject/Host/Service: provide interval helpers

This commit is contained in:
Thomas Gelf 2016-02-28 14:21:00 +01:00
parent 466b32ba2e
commit 8bcbf0f45a
3 changed files with 34 additions and 28 deletions

View File

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

View File

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

View File

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