mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 01:04:09 +02:00
commit
e7a875da26
@ -54,6 +54,26 @@ class String
|
|||||||
return $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
|
* Find and return all similar strings in $possibilites matching $string with the given minimum $similarity
|
||||||
*
|
*
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
use Icinga\Module\Monitoring\Plugin\Perfdata;
|
use Icinga\Module\Monitoring\Plugin\Perfdata;
|
||||||
use Icinga\Module\Monitoring\Plugin\PerfdataSet;
|
use Icinga\Module\Monitoring\Plugin\PerfdataSet;
|
||||||
|
use Icinga\Util\String;
|
||||||
|
|
||||||
class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
||||||
{
|
{
|
||||||
@ -20,9 +21,10 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||||||
{
|
{
|
||||||
$pieChartData = PerfdataSet::fromString($perfdataStr)->asArray();
|
$pieChartData = PerfdataSet::fromString($perfdataStr)->asArray();
|
||||||
$results = array();
|
$results = array();
|
||||||
$table = array(
|
$keys = array('', 'label', 'value', 'min', 'max', 'warn', 'crit');
|
||||||
'<td><b>' . implode(
|
$columns = array();
|
||||||
'</b></td><td><b>',
|
$labels = array_combine(
|
||||||
|
$keys,
|
||||||
array(
|
array(
|
||||||
'',
|
'',
|
||||||
$this->view->translate('Label'),
|
$this->view->translate('Label'),
|
||||||
@ -32,32 +34,52 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||||||
$this->view->translate('Warning'),
|
$this->view->translate('Warning'),
|
||||||
$this->view->translate('Critical')
|
$this->view->translate('Critical')
|
||||||
)
|
)
|
||||||
) . '<b></td>'
|
|
||||||
);
|
);
|
||||||
foreach ($pieChartData as $perfdata) {
|
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()) {
|
if ($compact && $perfdata->isVisualizable()) {
|
||||||
$results[] = $perfdata->asInlinePie($color)->render();
|
$results[] = $perfdata->asInlinePie($color)->render();
|
||||||
} else {
|
} else {
|
||||||
$row = '<tr>';
|
$data = array();
|
||||||
|
|
||||||
$row .= '<td>';
|
|
||||||
if ($perfdata->isVisualizable()) {
|
if ($perfdata->isVisualizable()) {
|
||||||
$row .= $perfdata->asInlinePie($color)->render() . ' ';
|
$data []= $perfdata->asInlinePie($color)->render() . ' ';
|
||||||
|
} elseif (isset($columns[''])) {
|
||||||
|
$data []= '';
|
||||||
}
|
}
|
||||||
$row .= '</td>';
|
|
||||||
|
|
||||||
if (! $compact) {
|
if (! $compact) {
|
||||||
foreach ($perfdata->toArray() as $value) {
|
foreach ($perfdata->toArray() as $column => $value) {
|
||||||
if ($value === '') {
|
if (! isset($columns[$column])) {
|
||||||
$value = '-';
|
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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$table []= '<tr><td>' . implode('</td><td>', $data) . '</td></tr>';
|
||||||
$row .= '</tr>';
|
|
||||||
$table[] = $row;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($limit > 0) {
|
if ($limit > 0) {
|
||||||
@ -72,8 +94,14 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||||||
if ($compact) {
|
if ($compact) {
|
||||||
return join('', $results);
|
return join('', $results);
|
||||||
} else {
|
} else {
|
||||||
$pieCharts = empty($table) ? '' : '<table class="perfdata">' . implode("\n", $table) . '</table>';
|
if (empty($table)) {
|
||||||
return $pieCharts;
|
return '';
|
||||||
|
}
|
||||||
|
return sprintf(
|
||||||
|
'<table class="perfdata %s">%s</table>',
|
||||||
|
isset($columns['']) ? 'perfdata-piecharts' : '',
|
||||||
|
implode("\n", $table)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ class Perfdata
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
$parts = array(
|
$parts = array(
|
||||||
$this->getLabel(),
|
'label' => $this->getLabel(),
|
||||||
'value' => $this->format($this->getvalue()),
|
'value' => $this->format($this->getvalue()),
|
||||||
'min' => isset($this->minValue) && !$this->isPercentage() ? $this->format($this->minValue) : '',
|
'min' => isset($this->minValue) && !$this->isPercentage() ? $this->format($this->minValue) : '',
|
||||||
'max' => isset($this->maxValue) && !$this->isPercentage() ? $this->format($this->maxValue) : '',
|
'max' => isset($this->maxValue) && !$this->isPercentage() ? $this->format($this->maxValue) : '',
|
||||||
|
@ -148,6 +148,11 @@ table.perfdata {
|
|||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.perfdata.perfdata-piecharts {
|
||||||
|
left: -2.6em;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
table.perfdata th {
|
table.perfdata th {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user