From 1ac4a2050c8076eb96e07e83721ebc9db864db94 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:47:21 +0200 Subject: Adding upstream version 0.3.3. Signed-off-by: Daniel Baumann --- library/Toplevelview/Tree/TLVStatus.php | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 library/Toplevelview/Tree/TLVStatus.php (limited to 'library/Toplevelview/Tree/TLVStatus.php') 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 @@ + */ + +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; + } +} -- cgit v1.2.3