From 1f36e545d99f55c46425bc44b125eb8a66683765 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 May 2015 17:26:56 +0200 Subject: [PATCH 1/5] Implement ::getState() refs #8205 --- .../library/Monitoring/Plugin/Perfdata.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index b1c71cb72..ef91f7f93 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -7,6 +7,7 @@ use Icinga\Util\Format; use InvalidArgumentException; use Icinga\Exception\ProgrammingError; use Icinga\Web\Widget\Chart\InlinePie; +use Icinga\Module\Monitoring\Object\Service; use Zend_Controller_Front; class Perfdata @@ -453,4 +454,30 @@ class Perfdata ); return $parts; } + + /** + * Return the state indicated by this perfdata + * + * @see Service + * + * @return int + */ + public function getState() + { + if ($this->value === null) { + return Service::STATE_UNKNOWN; + } + + if (! ($this->criticalThreshold === null + || $this->value < $this->criticalThreshold)) { + return Service::STATE_CRITICAL; + } + + if (! ($this->warningThreshold === null + || $this->value < $this->warningThreshold)) { + return Service::STATE_WARNING; + } + + return Service::STATE_OK; + } } From 6e24cfd538f31f9093818081a12ed2a3964762a5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 May 2015 17:26:56 +0200 Subject: [PATCH 2/5] Implement ::worseThan() refs #8205 --- .../library/Monitoring/Plugin/Perfdata.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index ef91f7f93..c1af78114 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -480,4 +480,34 @@ class Perfdata return Service::STATE_OK; } + + /** + * Return whether the state indicated by this perfdata is worse than + * the state indicated by the other perfdata + * CRITICAL > UNKNOWN > WARNING > OK + * + * @param Perfdata $rhs the other perfdata + * + * @return bool + */ + public function worseThan(Perfdata $rhs) + { + if (($state = $this->getState()) === ($rhsState = $rhs->getState())) { + return $this->getPercentage() > $rhs->getPercentage(); + } + + if ($state === Service::STATE_CRITICAL) { + return true; + } + + if ($state === Service::STATE_UNKNOWN) { + return $rhsState !== Service::STATE_CRITICAL; + } + + if ($state === Service::STATE_WARNING) { + return $rhsState === Service::STATE_OK; + } + + return false; + } } From 9a141d5e3c458f9c80bdced0529ba9b3dabde9c3 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 May 2015 18:39:16 +0200 Subject: [PATCH 3/5] Sort Perfdata by ::worseThan() DESC refs #8205 --- .../application/views/helpers/Perfdata.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 36cbaa319..1ff59b6ae 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -19,6 +19,19 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract public function perfdata($perfdataStr, $compact = false, $limit = 0, $color = Perfdata::PERFDATA_OK) { $pieChartData = PerfdataSet::fromString($perfdataStr)->asArray(); + + if (1 < ($i = count($pieChartData))) { + while (--$i) { + for ($j = 0, $k = 1; $j < $i; ++$j, ++$k) { + if ($pieChartData[$k]->worseThan($pieChartData[$j])) { + $perfdata = $pieChartData[$k]; + $pieChartData[$k] = $pieChartData[$j]; + $pieChartData[$j] = $perfdata; + } + } + } + } + $results = array(); $table = array( '' . implode( From d7e850da0ef554841d7c48ac148d29ad3690bfda Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 29 May 2015 18:41:07 +0200 Subject: [PATCH 4/5] Show at most 5 pie charts in the services list refs #8205 --- .../monitoring/application/views/scripts/list/services.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 9f87e7c60..c9dae8332 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -60,7 +60,7 @@ if (count($services) === 0) { -
perfdata($service->service_perfdata, true, 8) ?>
+
perfdata($service->service_perfdata, true, 5) ?>
iconImage()->service($service) ?> serviceFlags($service)); ?> qlink( From 36622101ae7c41b3b5b7eca2afe266466b99c34d Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 16 Jun 2015 18:36:12 +0200 Subject: [PATCH 5/5] Use built-in php sort functions refs #8205 --- .../application/views/helpers/Perfdata.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 1ff59b6ae..aaf6b3fee 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -19,19 +19,12 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract public function perfdata($perfdataStr, $compact = false, $limit = 0, $color = Perfdata::PERFDATA_OK) { $pieChartData = PerfdataSet::fromString($perfdataStr)->asArray(); - - if (1 < ($i = count($pieChartData))) { - while (--$i) { - for ($j = 0, $k = 1; $j < $i; ++$j, ++$k) { - if ($pieChartData[$k]->worseThan($pieChartData[$j])) { - $perfdata = $pieChartData[$k]; - $pieChartData[$k] = $pieChartData[$j]; - $pieChartData[$j] = $perfdata; - } - } + uasort( + $pieChartData, + function($a, $b) { + return $a->worseThan($b) ? -1 : ($b->worseThan($a) ? 1 : 0); } - } - + ); $results = array(); $table = array( '' . implode(