diff --git a/library/Icinga/Util/String.php b/library/Icinga/Util/String.php index 0d42d0e76..d67035b3f 100644 --- a/library/Icinga/Util/String.php +++ b/library/Icinga/Util/String.php @@ -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 * diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 36cbaa319..092aeff0f 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -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( - '' . implode( - '', - 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') - ) - ) . '' + $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('' . implode('', $headers) . ''); + foreach ($pieChartData as $perfdata) { if ($compact && $perfdata->isVisualizable()) { $results[] = $perfdata->asInlinePie($color)->render(); } else { - $row = ''; - - $row .= ''; + $data = array(); if ($perfdata->isVisualizable()) { - $row .= $perfdata->asInlinePie($color)->render() . ' '; + $data []= $perfdata->asInlinePie($color)->render() . ' '; + } elseif (isset($columns[''])) { + $data []= ''; } - $row .= ''; - if (! $compact) { - foreach ($perfdata->toArray() as $value) { - if ($value === '') { - $value = '-'; + foreach ($perfdata->toArray() as $column => $value) { + if (! isset($columns[$column])) { + continue; } - $row .= '' . (string) $value . ''; + $text = $this->view->escape(empty($value) ? '-' : $value); + $data []= sprintf( + '%s', + $text, + String::ellipsisCenter($text, 24) + ); } } - - $row .= ''; - $table[] = $row; + $table []= '' . implode('', $data) . ''; } } 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) ? '' : '' . implode("\n", $table) . '
'; - return $pieCharts; + if (empty($table)) { + return ''; + } + return sprintf( + '%s
', + isset($columns['']) ? 'perfdata-piecharts' : '', + implode("\n", $table) + ); } } } diff --git a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php index b1c71cb72..df1b6016a 100644 --- a/modules/monitoring/library/Monitoring/Plugin/Perfdata.php +++ b/modules/monitoring/library/Monitoring/Plugin/Perfdata.php @@ -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) : '', diff --git a/public/css/icinga/main-content.less b/public/css/icinga/main-content.less index 2b0e2e50d..18bc03a57 100644 --- a/public/css/icinga/main-content.less +++ b/public/css/icinga/main-content.less @@ -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; } -} \ No newline at end of file +}