Added perfdata to CLI monitoring list command, still disabled

This commit is contained in:
Thomas Gelf 2013-10-22 20:38:16 +00:00
parent 3ac869981a
commit 7893572319

View File

@ -7,6 +7,8 @@ use Icinga\Module\Monitoring\Cli\CliUtils;
use Icinga\Util\Format; use Icinga\Util\Format;
use Icinga\Cli\Command; use Icinga\Cli\Command;
use Icinga\File\Csv; use Icinga\File\Csv;
use Icinga\Module\Monitoring\Plugin\PerfdataSet;
use Exception;
/** /**
* Icinga monitoring objects * Icinga monitoring objects
@ -148,6 +150,7 @@ class ListCommand extends Command
'service_in_downtime', 'service_in_downtime',
'service_handled', 'service_handled',
'service_output', 'service_output',
'service_perfdata',
'service_last_state_change' 'service_last_state_change'
); );
$query = $this->getQuery('status', $columns) $query = $this->getQuery('status', $columns)
@ -256,6 +259,33 @@ class ListCommand extends Command
. $emptySpace . $emptySpace
. ' ' . $straight . ' '; . ' ' . $straight . ' ';
$perf = '';
try {
$pset = PerfdataSet::fromString($row->service_perfdata);
$perfs = array();
foreach ($pset->getAll() as $perfName => $p) {
if ($percent = $p->getPercentage()) {
if ($percent < 0 || $percent > 300) {
continue;
}
$perfs[] = ' '
. $perfName
. ': '
. $this->getPercentageSign($percent)
. ' '
. number_format($percent, 2, ',', '.')
. '%';
}
}
if (! empty($perfs)) {
$perf = ', ' . implode($perfs);
}
// TODO: fix wordwarp, then remove this line:
$perf = '';
} catch (Exception $e) {
// Ignoring perfdata errors right now, we could show some hint
}
$wrappedOutput = wordwrap( $wrappedOutput = wordwrap(
preg_replace('~\@{3,}~', '@@@', $row->service_output), preg_replace('~\@{3,}~', '@@@', $row->service_output),
$maxCols - 13 $maxCols - 13
@ -264,7 +294,7 @@ class ListCommand extends Command
" %1s─ %s%s (since %s)", " %1s─ %s%s (since %s)",
$leaf, $leaf,
$screen->underline($row->service_description), $screen->underline($row->service_description),
$screen->colorize($utils->objectStateFlags('service', $row), 'lightblue'), $screen->colorize($utils->objectStateFlags('service', $row) . $perf, 'lightblue'),
Format::timeSince($row->service_last_state_change) Format::timeSince($row->service_last_state_change)
); );
if ($this->isVerbose) { if ($this->isVerbose) {
@ -281,5 +311,24 @@ class ListCommand extends Command
$out .= "\n"; $out .= "\n";
return $out; return $out;
} }
protected function getPercentageSign($percent)
{
$circles = array(
0 => '○',
15 => '◔',
40 => '◑',
65 => '◕',
90 => '●',
);
$last = $circles[0];
foreach ($circles as $cur => $circle) {
if ($percent < $cur) {
return $last;
}
$last = $circle;
}
}
} }