summaryrefslogtreecommitdiffstats
path: root/library/Director/Objects/Extension/FlappingSupport.php
blob: a86f10dd4fa83a0ad0cf0238b6c2364dd1057425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace Icinga\Module\Director\Objects\Extension;

use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;

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)
    {
        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))
        );
    }

    protected function renderLegacyEnable_flapping($value)
    {
        return c1::renderKeyValue('flap_detection_enabled', c1::renderBoolean($value));
    }

    protected function renderLegacyFlapping_threshold_high($value)
    {
        return c1::renderKeyValue('high_flap_threshold', $value);
    }

    protected function renderLegacyFlapping_threshold_low($value)
    {
        // @codingStandardsIgnoreEnd
        return c1::renderKeyValue('low_flap_threshold', $value);
    }
}