From da0f8427204ad57aad08059906df0ea10a7ccf31 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:42:52 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- .../Cube/CubeRenderer/HostStatusCubeRenderer.php | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 library/Cube/CubeRenderer/HostStatusCubeRenderer.php (limited to 'library/Cube/CubeRenderer/HostStatusCubeRenderer.php') diff --git a/library/Cube/CubeRenderer/HostStatusCubeRenderer.php b/library/Cube/CubeRenderer/HostStatusCubeRenderer.php new file mode 100644 index 0000000..89322cb --- /dev/null +++ b/library/Cube/CubeRenderer/HostStatusCubeRenderer.php @@ -0,0 +1,105 @@ +cube->getDimensionAfter($name)) && isset($this->summaries->{$next->getName()})) { + $htm .= ' (' . $this->summaries->{$next->getName()}->hosts_cnt . ')'; + } + + return $htm; + } + + protected function getDimensionClasses($name, $row) + { + $classes = parent::getDimensionClasses($name, $row); + + $sums = $row; + if ($sums->hosts_down > 0) { + $classes[] = 'critical'; + if ((int) $sums->hosts_unhandled_down === 0) { + $classes[] = 'handled'; + } + } elseif ($sums->hosts_unreachable > 0) { + $classes[] = 'unreachable'; + if ((int) $sums->hosts_unhandled_unreachable === 0) { + $classes[] = 'handled'; + } + } else { + $classes[] = 'ok'; + } + + return $classes; + } + + public function renderFacts($facts) + { + $indent = str_repeat(' ', 3); + $parts = array(); + + if ($facts->hosts_unhandled_down > 0) { + $parts['critical'] = $facts->hosts_unhandled_down; + } + + if ($facts->hosts_down > 0 && $facts->hosts_down > $facts->hosts_unhandled_down) { + $parts['critical handled'] = $facts->hosts_down - $facts->hosts_unhandled_down; + } + + if ($facts->hosts_unhandled_unreachable > 0) { + $parts['unreachable'] = $facts->hosts_unhandled_unreachable; + } + + if ($facts->hosts_unreachable > 0 && $facts->hosts_unreachable > $facts->hosts_unhandled_unreachable) { + $parts['unreachable handled'] = $facts->hosts_unreachable - $facts->hosts_unhandled_unreachable; + } + + if ($facts->hosts_cnt > $facts->hosts_down && $facts->hosts_cnt > $facts->hosts_unreachable) { + $parts['ok'] = $facts->hosts_cnt - $facts->hosts_down - $facts->hosts_unreachable; + } + + $main = ''; + $sub = ''; + foreach ($parts as $class => $count) { + if ($main === '') { + $main = $this->makeBadgeHtml($class, $count); + } else { + $sub .= $this->makeBadgeHtml($class, $count); + } + } + if ($sub !== '') { + $sub = $indent + . '' + . "\n " + . $sub + . $indent + . "\n"; + } + + return $main . $sub; + } + + protected function makeBadgeHtml($class, $count) + { + $indent = str_repeat(' ', 3); + return sprintf( + '%s%s', + $indent, + $class, + $count + ) . "\n"; + } + + protected function getDetailsBaseUrl() + { + return 'cube/hosts/details'; + } +} -- cgit v1.2.3