diff --git a/library/Director/Objects/Extension/FlappingSupport.php b/library/Director/Objects/Extension/FlappingSupport.php new file mode 100644 index 00000000..74b366a1 --- /dev/null +++ b/library/Director/Objects/Extension/FlappingSupport.php @@ -0,0 +1,38 @@ +renderFlappingThreshold('flapping_threshold_high', $value); + } + + /** + * @param $value + * @return string + */ + protected function renderFlapping_threshold_low($value) + { + // @codingStandardsIgnoreEnd + return $this->renderFlappingThreshold('flapping_threshold_low', $value); + } + + protected function renderFlappingThreshold($key, $value) + { + return sprintf( + " try { // This setting is only available in Icinga >= 2.8.0\n" + . " %s" + . " } except { globals.directorWarnOnceForThresholds() }\n", + c::renderKeyValue($key, c::renderFloat($value)) + ); + } +} diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index fb1bcc7d..a9e9c278 100644 --- a/library/Director/Objects/IcingaHost.php +++ b/library/Director/Objects/IcingaHost.php @@ -8,9 +8,12 @@ use Icinga\Module\Director\Data\PropertiesFilter; use Icinga\Module\Director\Db; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; +use Icinga\Module\Director\Objects\Extension\FlappingSupport; class IcingaHost extends IcingaObject { + use FlappingSupport; + protected $table = 'icinga_host'; protected $defaultProperties = array( @@ -79,11 +82,6 @@ class IcingaHost extends IcingaObject 'retry_interval' => 'retry_interval', ); - protected $numericProperties = array( - 'flapping_threshold_high' => 'flapping_threshold_high', - 'flapping_threshold_low' => 'flapping_threshold_low', - ); - protected $supportsCustomVars = true; protected $supportsGroups = true; diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 79cb9ddd..9a2a27c3 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -106,16 +106,6 @@ 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; @@ -151,11 +141,6 @@ 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); @@ -1672,26 +1657,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer /** * @codingStandardsIgnoreStart */ - protected function renderFlapping_threshold_high() - { - return $this->renderFlappingThreshold('flapping_threshold_high'); - } - - protected function renderFlapping_threshold_low() - { - return $this->renderFlappingThreshold('flapping_threshold_low'); - } - - protected function renderFlappingThreshold($key) - { - return sprintf( - " try { // This setting is only available in Icinga >= 2.8.0\n" - . " %s" - . " } except { globals.directorWarnOnceForThresholds() }\n", - c::renderKeyValue($this->numericProperties[$key], c::renderFloat($this->$key)) - ); - } - protected function renderLegacyHost_id() { return $this->renderLegacyRelationProperty( @@ -1865,13 +1830,6 @@ 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)) ) { diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index aa025f3b..7a99027e 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -10,9 +10,12 @@ use Icinga\Module\Director\Data\PropertiesFilter; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; +use Icinga\Module\Director\Objects\Extension\FlappingSupport; class IcingaService extends IcingaObject { + use FlappingSupport; + protected $table = 'icinga_service'; protected $defaultProperties = array( @@ -82,11 +85,6 @@ class IcingaService extends IcingaObject 'retry_interval' => 'retry_interval', ); - protected $numericProperties = array( - 'flapping_threshold_high' => 'flapping_threshold_high', - 'flapping_threshold_low' => 'flapping_threshold_low', - ); - protected $supportsGroups = true; protected $supportsCustomVars = true;