IcingaObject: Support numeric properties

Similar to intervalProperties
This commit is contained in:
Markus Frosch 2017-12-06 15:36:11 +01:00 committed by Thomas Gelf
parent 39ce02b1e5
commit b9190755a6
2 changed files with 23 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class IcingaConfigHelper
return (string) $value;
}
protected static function renderFloat($value)
public static function renderFloat($value)
{
// Render .0000 floats as integers, mainly because of some JSON
// implementations:

View File

@ -106,6 +106,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
*/
protected $intervalProperties = array();
/**
* Array of numeric property names
*
* Those values will be put out as raw numbers to Icinga 2's config.
* Array expects (propertyName => renderedKey)
*
* @var array
*/
protected $numericProperties = array();
/** @var Db */
protected $connection;
@ -141,6 +151,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return array_key_exists($property, $this->booleans);
}
public function propertyIsNumeric($property)
{
return array_key_exists($property, $this->numericProperties);
}
public function propertyIsInterval($property)
{
return array_key_exists($property, $this->intervalProperties);
@ -1822,6 +1837,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
);
}
if ($this->propertyIsNumeric($key)) {
return c::renderKeyValue(
$this->numericProperties[$key],
c::renderFloat($value)
);
}
if (substr($key, -3) === '_id'
&& $this->hasRelation($relKey = substr($key, 0, -3))
) {