Skip to content

Commit

Permalink
Merge branch 'bugfix/don-t-show-more-than-the-five-worst-pies-in-list…
Browse files Browse the repository at this point in the history
…-views-8205'

fixes #8205
  • Loading branch information
majentsch committed Jun 16, 2015
2 parents f31f18d + 3662210 commit 3caa5b4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/monitoring/application/views/helpers/Perfdata.php
Expand Up @@ -20,6 +20,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();
uasort(
$pieChartData,
function($a, $b) {
return $a->worseThan($b) ? -1 : ($b->worseThan($a) ? 1 : 0);
}
);
$results = array();
$keys = array('', 'label', 'value', 'min', 'max', 'warn', 'crit');
$columns = array();
Expand Down
Expand Up @@ -60,7 +60,7 @@ if (count($services) === 0) {
</td>

<td>
<div class="sparkline-box"><?= $this->perfdata($service->service_perfdata, true, 8) ?> </div>
<div class="sparkline-box"><?= $this->perfdata($service->service_perfdata, true, 5) ?> </div>
<?= $this->iconImage()->service($service) ?>
<?= implode(' ', $this->serviceFlags($service)); ?>
<?= $this->qlink(
Expand Down
57 changes: 57 additions & 0 deletions modules/monitoring/library/Monitoring/Plugin/Perfdata.php
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Widget\Chart\InlinePie;
use Icinga\Module\Monitoring\Object\Service;
use Zend_Controller_Front;

class Perfdata
Expand Down Expand Up @@ -453,4 +454,60 @@ public function toArray()
);
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;
}

/**
* 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;
}
}

0 comments on commit 3caa5b4

Please sign in to comment.