summaryrefslogtreecommitdiffstats
path: root/library/Director/CheckPlugin/Threshold.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--library/Director/CheckPlugin/Threshold.php47
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();
+ }
+}