IcingaObject: Support numeric properties
Similar to intervalProperties
This commit is contained in:
parent
39ce02b1e5
commit
b9190755a6
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
) {
|
||||
|
|
Loading…
Reference in New Issue