diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/CheckPlugin/Threshold.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/Director/CheckPlugin/Threshold.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/library/Director/CheckPlugin/Threshold.php b/library/Director/CheckPlugin/Threshold.php new file mode 100644 index 0000000..76aac4e --- /dev/null +++ b/library/Director/CheckPlugin/Threshold.php @@ -0,0 +1,47 @@ +<?php + +namespace Icinga\Module\Director\CheckPlugin; + +class Threshold +{ + /** @var Range */ + protected $warning; + + /** @var Range */ + protected $critical; + + public function __construct($warning = null, $critical = null) + { + if ($warning !== null) { + $this->warning = Range::wantRange($warning); + } + + if ($critical !== null) { + $this->critical = Range::wantRange($critical); + } + } + + public static function check($value, $message, $warning = null, $critical = null) + { + $threshold = new static($warning, $critical); + $state = $threshold->checkValue($value); + return new CheckResult($message, $state); + } + + public function checkValue($value) + { + if ($this->critical !== null) { + if (! $this->critical->valueIsValid($value)) { + return PluginState::critical(); + } + } + + if ($this->warning !== null) { + if (! $this->warning->valueIsValid($value)) { + return PluginState::warning(); + } + } + + return PluginState::ok(); + } +} |