2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2014-05-05 16:16:45 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-27 10:14:41 +02:00
|
|
|
|
2014-05-05 16:16:45 +02:00
|
|
|
use Icinga\Util\Format;
|
2014-03-26 14:56:35 +01:00
|
|
|
use Icinga\Web\Widget\Chart\InlinePie;
|
2014-05-05 16:16:45 +02:00
|
|
|
use Icinga\Module\Monitoring\Plugin\Perfdata;
|
|
|
|
use Icinga\Module\Monitoring\Plugin\PerfdataSet;
|
2013-06-27 10:14:41 +02:00
|
|
|
|
|
|
|
class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|
|
|
{
|
2014-12-23 15:45:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the given perfdata string to the user
|
|
|
|
*
|
|
|
|
* @param $perfdataStr The perfdata string
|
|
|
|
* @param bool $compact Whether to display the perfdata in compact mode
|
|
|
|
* @param $color The color indicating the perfdata state
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function perfdata($perfdataStr, $compact = false, $color = Perfdata::PERFDATA_GREEN)
|
2013-06-27 10:14:41 +02:00
|
|
|
{
|
2014-12-23 15:45:45 +01:00
|
|
|
$pieChartData = PerfdataSet::fromString($perfdataStr)->asArray();
|
2014-07-14 13:48:30 +02:00
|
|
|
|
2013-06-27 10:14:41 +02:00
|
|
|
$result = '';
|
2014-05-05 16:16:45 +02:00
|
|
|
$table = array();
|
2014-12-23 15:45:45 +01:00
|
|
|
foreach ($pieChartData as $perfdata) {
|
|
|
|
if ($perfdata->isVisualizable()) {
|
|
|
|
$pieChart = $perfdata->asInlinePie($color);
|
|
|
|
if ($compact) {
|
|
|
|
$result .= $pieChart->render();
|
|
|
|
} else {
|
|
|
|
$table[] = '<tr><th>' . $pieChart->render()
|
|
|
|
. htmlspecialchars($perfdata->getLabel())
|
|
|
|
. '</th><td> '
|
|
|
|
. htmlspecialchars($this->formatPerfdataValue($perfdata)) .
|
|
|
|
' </td></tr>';
|
2014-06-18 13:53:38 +02:00
|
|
|
}
|
2014-12-23 15:45:45 +01:00
|
|
|
} else {
|
|
|
|
$table[] = (string)$perfdata;
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-05 16:16:45 +02:00
|
|
|
|
2014-07-14 13:48:30 +02:00
|
|
|
if ($compact) {
|
|
|
|
return $result;
|
2014-05-05 16:16:45 +02:00
|
|
|
} else {
|
2014-07-14 13:48:30 +02:00
|
|
|
$pieCharts = empty($table) ? '' : '<table class="perfdata">' . implode("\n", $table) . '</table>';
|
2014-12-23 15:45:45 +01:00
|
|
|
return $pieCharts;
|
2013-07-22 17:10:43 +02:00
|
|
|
}
|
2014-05-05 16:16:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function formatPerfdataValue(Perfdata $perfdata)
|
|
|
|
{
|
|
|
|
if ($perfdata->isBytes()) {
|
|
|
|
return Format::bytes($perfdata->getValue());
|
|
|
|
} elseif ($perfdata->isSeconds()) {
|
|
|
|
return Format::seconds($perfdata->getValue());
|
|
|
|
} elseif ($perfdata->isPercentage()) {
|
|
|
|
return $perfdata->getValue() . '%';
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2013-07-22 17:10:43 +02:00
|
|
|
|
2014-05-05 16:16:45 +02:00
|
|
|
return $perfdata->getValue();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2014-06-18 13:53:38 +02:00
|
|
|
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|