diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:30:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:30:50 +0000 |
commit | d5f222b7ebf4d2c2d47d20a25adcc9aadf67fbd5 (patch) | |
tree | da9b32212bf99154450a7668f61a75f65617a9fa /library/Toplevelview/Tree/TLVStatus.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-toplevelview-upstream.tar.xz icingaweb2-module-toplevelview-upstream.zip |
Adding upstream version 0.3.3.upstream/0.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Toplevelview/Tree/TLVStatus.php')
-rw-r--r-- | library/Toplevelview/Tree/TLVStatus.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/library/Toplevelview/Tree/TLVStatus.php b/library/Toplevelview/Tree/TLVStatus.php new file mode 100644 index 0000000..afecc1e --- /dev/null +++ b/library/Toplevelview/Tree/TLVStatus.php @@ -0,0 +1,115 @@ +<?php +/* Copyright (C) 2017 Icinga Development Team <info@icinga.com> */ + +namespace Icinga\Module\Toplevelview\Tree; + +class TLVStatus +{ + protected $properties = array( + 'critical_unhandled' => null, + 'critical_handled' => null, + 'warning_unhandled' => null, + 'warning_handled' => null, + 'unknown_unhandled' => null, + 'unknown_handled' => null, + 'downtime_handled' => null, + 'downtime_active' => null, + 'ok' => null, + 'missing' => null, + 'total' => null, + ); + + protected static $statusPriority = array( + 'critical_unhandled', + 'warning_unhandled', + 'unknown_unhandled', // Note: old TLV ignored UNKNOWN basically + 'critical_handled', + 'warning_handled', + 'unknown_handled', + 'ok', + 'downtime_handled', + 'missing', + ); + + protected $meta = array(); + + public function merge(TLVStatus $status) + { + $properties = $status->getProperties(); + foreach (array_keys($this->properties) as $key) { + if ($this->properties[$key] === null) { + $this->properties[$key] = $properties[$key]; + } else { + $this->properties[$key] += $properties[$key]; + } + } + return $this; + } + + public function get($key) + { + return $this->properties[$key]; + } + + public function set($key, $value) + { + $this->properties[$key] = (int) $value; + return $this; + } + + public function getProperties() + { + return $this->properties; + } + + public function add($key, $value = 1) + { + if ($this->properties[$key] === null) { + $this->properties[$key] = 0; + } + $this->properties[$key] += (int) $value; + return $this; + } + + public function zero() + { + foreach (array_keys($this->properties) as $key) { + $this->properties[$key] = 0; + } + return $this; + } + + public function getOverall() + { + foreach (static::$statusPriority as $key) { + if ($this->properties[$key] !== null && $this->properties[$key] > 0) { + return $this->cssFriendly($key); + } + } + return 'missing'; + } + + protected function cssFriendly($key) + { + return str_replace('_', ' ', $key); + } + + public function getMeta($key) + { + if (array_key_exists($key, $this->meta)) { + return $this->meta[$key]; + } else { + return null; + } + } + + public function getAllMeta() + { + return $this->meta; + } + + public function setMeta($key, $value) + { + $this->meta[$key] = $value; + } +} |