From a5c3782de7a7ef66d144ac1d59abb83cc5ac4d4a Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 15:20:27 +0200 Subject: [PATCH 1/6] Do not display columns that don't include any values refs #8334 --- .../application/views/helpers/Perfdata.php | 61 +++++++++++-------- .../library/Monitoring/Plugin/Perfdata.php | 2 +- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 36cbaa319..7b3fae266 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -20,44 +20,51 @@ 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') - ) - ) . '' + $columns = array(); + $labels = array_combine( + array('', 'label', 'value', 'min', 'max', 'warn', 'crit'), + 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 ($pieChartData as $perfdata) { + foreach ($perfdata->toArray() as $column => $value) { + if (! empty($value)) { + $columns[$column] = $labels[$column]; + } + } + } + $table = array('' . implode('', $columns) . ''); + 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() . ' '; + } else if (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 . ''; + $data []= empty($value) ? '-' : (string) $value; } } - - $row .= ''; - $table[] = $row; + $table []= '' . implode('', $data) . ''; } } if ($limit > 0) { 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) : '', From 8e35bb446a9541060356b63ddebbd095648df22b Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 16:06:26 +0200 Subject: [PATCH 2/6] Hide columns with useless information in perfdata table Hide columns that don't provide any useful information, to reduce the size of the perfdata table. refs #8334 --- .../application/views/helpers/Perfdata.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 7b3fae266..5e17adea5 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -20,9 +20,10 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract { $pieChartData = PerfdataSet::fromString($perfdataStr)->asArray(); $results = array(); + $keys = array('', 'label', 'value', 'min', 'max', 'warn', 'crit'); $columns = array(); $labels = array_combine( - array('', 'label', 'value', 'min', 'max', 'warn', 'crit'), + $keys, array( '', $this->view->translate('Label'), @@ -37,15 +38,23 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract if ($perfdata->isVisualizable()) { $columns[''] = ''; } - } - foreach ($pieChartData as $perfdata) { foreach ($perfdata->toArray() as $column => $value) { - if (! empty($value)) { - $columns[$column] = $labels[$column]; + if (empty($value) || + $column === 'min' && floatval($value) === 0.0 || + $column === 'max' && $perfdata->isPercentage() && floatval($value) === 100) { + continue; } + $columns[$column] = $labels[$column]; } } - $table = array('' . implode('', $columns) . ''); + // restore original column array sorting sorting + $headers = array(); + foreach ($keys as $i => $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(); From ff01ee4f2007cd9e2fba2d2eabbc17e158c5e098 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 17:07:34 +0200 Subject: [PATCH 3/6] Move perfdata table left to save horizontal space refs #8334 --- public/css/icinga/main-content.less | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/css/icinga/main-content.less b/public/css/icinga/main-content.less index b442723cb..8dd0f1405 100644 --- a/public/css/icinga/main-content.less +++ b/public/css/icinga/main-content.less @@ -142,6 +142,10 @@ table.objectstate tr.state.handled td.state { table.perfdata { min-width: 24em; font-size: 0.9em; + position: relative; + top: 1.8em; + left: -2.6em; + margin-bottom: 1.8em; } table.perfdata th { From 1e8151bed32398a27b0980e57fb8a54b8f5bc081 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 17:09:40 +0200 Subject: [PATCH 4/6] Limit perfdata label size Add paratentheses when perfdata label size exceeds a certain limit. Display the full label as tooltip. refs #8334 --- library/Icinga/Util/String.php | 20 +++++++++++++++++++ .../application/views/helpers/Perfdata.php | 10 ++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) 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 5e17adea5..9c6a11d05 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 { @@ -47,7 +48,7 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract $columns[$column] = $labels[$column]; } } - // restore original column array sorting sorting + // restore original column array sorting $headers = array(); foreach ($keys as $i => $column) { if (isset($columns[$column])) { @@ -70,7 +71,12 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract if (! isset($columns[$column])) { continue; } - $data []= empty($value) ? '-' : (string) $value; + $text = $this->view->escape(empty($value) ? '-' : $value); + $data []= sprintf( + '%s', + $text, + String::ellipsisCenter($text, 24) + ); } } $table []= '' . implode('', $data) . ''; From 198834294f979a9537ec228432f55983161d8aa7 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 17:30:24 +0200 Subject: [PATCH 5/6] Fix table position for perfdata without piecharts refs #8334 --- .../monitoring/application/views/helpers/Perfdata.php | 10 ++++++++-- public/css/icinga/main-content.less | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 9c6a11d05..76e6518ec 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -94,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/public/css/icinga/main-content.less b/public/css/icinga/main-content.less index 8dd0f1405..f05f08886 100644 --- a/public/css/icinga/main-content.less +++ b/public/css/icinga/main-content.less @@ -142,10 +142,11 @@ table.objectstate tr.state.handled td.state { table.perfdata { min-width: 24em; font-size: 0.9em; - position: relative; - top: 1.8em; +} + +table.perfdata.perfdata-piecharts { left: -2.6em; - margin-bottom: 1.8em; + position: relative; } table.perfdata th { From ab129d094bd5e4335f13b489be55030c2ec3daa9 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 2 Jun 2015 17:50:31 +0200 Subject: [PATCH 6/6] remove unneeded code --- modules/monitoring/application/views/helpers/Perfdata.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Perfdata.php b/modules/monitoring/application/views/helpers/Perfdata.php index 76e6518ec..092aeff0f 100644 --- a/modules/monitoring/application/views/helpers/Perfdata.php +++ b/modules/monitoring/application/views/helpers/Perfdata.php @@ -50,7 +50,7 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract } // restore original column array sorting $headers = array(); - foreach ($keys as $i => $column) { + foreach ($keys as $column) { if (isset($columns[$column])) { $headers[$column] = $labels[$column]; } @@ -63,7 +63,7 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract $data = array(); if ($perfdata->isVisualizable()) { $data []= $perfdata->asInlinePie($color)->render() . ' '; - } else if (isset($columns[''])) { + } elseif (isset($columns[''])) { $data []= ''; } if (! $compact) {