IcingaObject: Render flapping thresholds downwards compatible

Settings are ignored in Icinga < 2.8.0 and a warning is logged.

refs #330
This commit is contained in:
Markus Frosch 2017-12-11 17:32:56 +01:00 committed by Thomas Gelf
parent 6c52a26281
commit 07d830b06f
2 changed files with 34 additions and 0 deletions

View File

@ -516,6 +516,7 @@ class IcingaConfig
)
)->prepend(
"\nconst DirectorStageDir = dirname(dirname(current_filename))\n"
. $this->renderFlappingLogHelper()
. $this->renderHostOverridableVars()
. $this->renderMagicApplyFor()
);
@ -523,6 +524,19 @@ class IcingaConfig
return $this;
}
protected function renderFlappingLogHelper()
{
return '
globals.directorWarnedOnceForThresholds = false;
globals.directorWarnOnceForThresholds = function() {
if (globals.directorWarnedOnceForThresholds == false) {
globals.directorWarnedOnceForThresholds = true
log(LogWarning, "config", "Director: flapping_threshold_high/low is not supported in this Icinga 2 version!")
}
}
';
}
protected function renderHostOverridableVars()
{
$settings = $this->connection->settings();

View File

@ -1664,6 +1664,26 @@ 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(