2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2015-02-03 16:27:59 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
|
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
|
2015-01-13 10:59:33 +01:00
|
|
|
{#
|
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
|
|
|
|
*/
|
2015-02-03 16:45:01 +01:00
|
|
|
public function perfdata($perfdataStr, $compact = false, $limit = 0, $color = Perfdata::PERFDATA_OK)
|
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
|
|
|
|
2015-02-03 16:45:01 +01:00
|
|
|
$results = array();
|
2014-12-30 16:31:37 +01:00
|
|
|
$table = array(
|
|
|
|
'<td><b>' . implode(
|
|
|
|
'</b></td><td><b>',
|
|
|
|
array('', t('Label'), t('Value'), t('Min'), t('Max'), t('Warning'), t('Critical'))
|
|
|
|
) . '<b></td>'
|
|
|
|
);
|
2014-12-23 15:45:45 +01:00
|
|
|
foreach ($pieChartData as $perfdata) {
|
2014-12-30 16:31:37 +01:00
|
|
|
|
|
|
|
if ($compact && $perfdata->isVisualizable()) {
|
2015-02-03 16:45:01 +01:00
|
|
|
$results[] = $perfdata->asInlinePie($color)->render();
|
2014-12-23 15:45:45 +01:00
|
|
|
} else {
|
2014-12-30 16:31:37 +01:00
|
|
|
$row = '<tr>';
|
|
|
|
|
|
|
|
$row .= '<td>';
|
|
|
|
if ($perfdata->isVisualizable()) {
|
|
|
|
$row .= $perfdata->asInlinePie($color)->render() . ' ';
|
|
|
|
}
|
|
|
|
$row .= '</td>';
|
|
|
|
|
|
|
|
if (!$compact) {
|
|
|
|
foreach ($perfdata->toArray() as $value) {
|
|
|
|
if ($value === '') {
|
|
|
|
$value = '-';
|
|
|
|
}
|
|
|
|
$row .= '<td>' . (string)$value . '</td>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$row .= '</tr>';
|
|
|
|
$table[] = $row;
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-05 16:16:45 +02:00
|
|
|
|
2015-02-03 16:45:01 +01:00
|
|
|
if ($limit > 0) {
|
2015-02-03 17:33:30 +01:00
|
|
|
$count = max (count($table), count ($results));
|
2015-02-03 16:45:01 +01:00
|
|
|
$table = array_slice ($table, 0, $limit);
|
|
|
|
$results = array_slice ($results, 0, $limit);
|
2015-02-03 17:33:30 +01:00
|
|
|
if ($count > $limit) {
|
|
|
|
$mess = sprintf(t('%d more ...'), $count - $limit);
|
|
|
|
$results[] = '<span title="' . $mess . '">...</span>';
|
|
|
|
}
|
2015-02-03 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2014-07-14 13:48:30 +02:00
|
|
|
if ($compact) {
|
2015-02-03 16:45:01 +01:00
|
|
|
return join('', $results);
|
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
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|