mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 15:54:03 +02:00
Merge branch 'feature/flapping-trait'
This commit is contained in:
commit
d69c5a7cc7
38
library/Director/Objects/Extension/FlappingSupport.php
Normal file
38
library/Director/Objects/Extension/FlappingSupport.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Objects\Extension;
|
||||
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||
|
||||
trait FlappingSupport
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
* @return string
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
protected function renderFlapping_threshold_high($value)
|
||||
{
|
||||
return $this->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))
|
||||
);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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))
|
||||
) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user