Merge branch 'bugfix/perfdata-details-hidden-8334'

fixes #8334
This commit is contained in:
Matthias Jentsch 2015-06-02 17:51:57 +02:00
commit e7a875da26
4 changed files with 84 additions and 31 deletions

View File

@ -54,6 +54,26 @@ class String
return $string;
}
/**
* Add ellipsis in the center of a string when a string is longer than max length
*
* @param string $string
* @param int $maxLength
* @param string $ellipsis
*
* @return string
*/
public static function ellipsisCenter($string, $maxLength, $ellipsis = '...')
{
$start = ceil($maxLength / 2.0);
$end = floor($maxLength / 2.0);
if (strlen($string) > $maxLength) {
return substr($string, 0, $start - strlen($ellipsis)) . $ellipsis . substr($string, - $end);
}
return $string;
}
/**
* Find and return all similar strings in $possibilites matching $string with the given minimum $similarity
*

View File

@ -3,6 +3,7 @@
use Icinga\Module\Monitoring\Plugin\Perfdata;
use Icinga\Module\Monitoring\Plugin\PerfdataSet;
use Icinga\Util\String;
class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
{
@ -20,44 +21,65 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
{
$pieChartData = PerfdataSet::fromString($perfdataStr)->asArray();
$results = array();
$table = array(
'<td><b>' . implode(
'</b></td><td><b>',
array(
'',
$this->view->translate('Label'),
$this->view->translate('Value'),
$this->view->translate('Min'),
$this->view->translate('Max'),
$this->view->translate('Warning'),
$this->view->translate('Critical')
)
) . '<b></td>'
$keys = array('', 'label', 'value', 'min', 'max', 'warn', 'crit');
$columns = array();
$labels = array_combine(
$keys,
array(
'',
$this->view->translate('Label'),
$this->view->translate('Value'),
$this->view->translate('Min'),
$this->view->translate('Max'),
$this->view->translate('Warning'),
$this->view->translate('Critical')
)
);
foreach ($pieChartData as $perfdata) {
if ($perfdata->isVisualizable()) {
$columns[''] = '';
}
foreach ($perfdata->toArray() as $column => $value) {
if (empty($value) ||
$column === 'min' && floatval($value) === 0.0 ||
$column === 'max' && $perfdata->isPercentage() && floatval($value) === 100) {
continue;
}
$columns[$column] = $labels[$column];
}
}
// restore original column array sorting
$headers = array();
foreach ($keys as $column) {
if (isset($columns[$column])) {
$headers[$column] = $labels[$column];
}
}
$table = array('<td><b>' . implode('</b></td><td><b>', $headers) . '<b></td>');
foreach ($pieChartData as $perfdata) {
if ($compact && $perfdata->isVisualizable()) {
$results[] = $perfdata->asInlinePie($color)->render();
} else {
$row = '<tr>';
$row .= '<td>';
$data = array();
if ($perfdata->isVisualizable()) {
$row .= $perfdata->asInlinePie($color)->render() . '&nbsp;';
$data []= $perfdata->asInlinePie($color)->render() . '&nbsp;';
} elseif (isset($columns[''])) {
$data []= '';
}
$row .= '</td>';
if (! $compact) {
foreach ($perfdata->toArray() as $value) {
if ($value === '') {
$value = '-';
foreach ($perfdata->toArray() as $column => $value) {
if (! isset($columns[$column])) {
continue;
}
$row .= '<td>' . (string) $value . '</td>';
$text = $this->view->escape(empty($value) ? '-' : $value);
$data []= sprintf(
'<span title="%s">%s</span>',
$text,
String::ellipsisCenter($text, 24)
);
}
}
$row .= '</tr>';
$table[] = $row;
$table []= '<tr><td>' . implode('</td><td>', $data) . '</td></tr>';
}
}
if ($limit > 0) {
@ -72,8 +94,14 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
if ($compact) {
return join('', $results);
} else {
$pieCharts = empty($table) ? '' : '<table class="perfdata">' . implode("\n", $table) . '</table>';
return $pieCharts;
if (empty($table)) {
return '';
}
return sprintf(
'<table class="perfdata %s">%s</table>',
isset($columns['']) ? 'perfdata-piecharts' : '',
implode("\n", $table)
);
}
}
}

View File

@ -444,7 +444,7 @@ class Perfdata
public function toArray()
{
$parts = array(
$this->getLabel(),
'label' => $this->getLabel(),
'value' => $this->format($this->getvalue()),
'min' => isset($this->minValue) && !$this->isPercentage() ? $this->format($this->minValue) : '',
'max' => isset($this->maxValue) && !$this->isPercentage() ? $this->format($this->maxValue) : '',

View File

@ -148,6 +148,11 @@ table.perfdata {
font-size: 0.9em;
}
table.perfdata.perfdata-piecharts {
left: -2.6em;
position: relative;
}
table.perfdata th {
padding: 0;
text-align: left;
@ -366,4 +371,4 @@ table.usergroupbackend-list {
td.backend-remove {
text-align: right;
}
}
}