mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
Fix graph argument issues (#12868)
* Fix top devices widget storage graphs referenced the wrong graph, caused it to not work because device was not set. * Handle feedback from rrdtool properly
This commit is contained in:
parent
2c8576ea79
commit
1bf9afb744
@ -556,17 +556,44 @@ class Rrd extends BaseDatastore
|
||||
*/
|
||||
public function graph(string $options): string
|
||||
{
|
||||
$cmd = $this->buildCommand('graph', '-', $options);
|
||||
$process = Process::fromShellCommandline(Config::get('rrdtool') . ' ' . $cmd, $this->rrd_dir);
|
||||
$process = new Process([Config::get('rrdtool', 'rrdtool'), '-'], $this->rrd_dir);
|
||||
$process->setTimeout(300);
|
||||
$process->setIdleTimeout(300);
|
||||
|
||||
$command = $this->buildCommand('graph', '-', $options);
|
||||
$process->setInput($command . "\nquit");
|
||||
$process->run();
|
||||
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new RrdGraphException($process->getErrorOutput(), $process->getExitCode(), $process->getOutput());
|
||||
$feedback_position = strrpos($process->getOutput(), 'OK ');
|
||||
if ($feedback_position !== false) {
|
||||
return substr($process->getOutput(), 0, $feedback_position);
|
||||
}
|
||||
|
||||
return $process->getOutput();
|
||||
// if valid image is returned with error, extract image and feedback
|
||||
$image_type = Config::get('webui.graph_type', 'png');
|
||||
$search = $this->getImageEnd($image_type);
|
||||
if (($position = strrpos($process->getOutput(), $search)) !== false) {
|
||||
$position += strlen($search);
|
||||
throw new RrdGraphException(
|
||||
substr($process->getOutput(), $position),
|
||||
$process->getExitCode(),
|
||||
substr($process->getOutput(), 0, $position)
|
||||
);
|
||||
}
|
||||
|
||||
// only error text was returned
|
||||
$error = trim($process->getOutput() . PHP_EOL . $process->getErrorOutput());
|
||||
throw new RrdGraphException($error, $process->getExitCode(), '');
|
||||
}
|
||||
|
||||
private function getImageEnd(string $type): string
|
||||
{
|
||||
$image_suffixes = [
|
||||
'png' => hex2bin('0000000049454e44ae426082'),
|
||||
'svg' => '</svg>',
|
||||
];
|
||||
|
||||
return $image_suffixes[$type] ?? '';
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
|
@ -73,7 +73,7 @@ if (! empty($command_only)) {
|
||||
echo "<div class='infobox'>";
|
||||
echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Command</p>";
|
||||
echo "<pre class='rrd-pre'>";
|
||||
echo 'rrdtool ' . Rrd::buildCommand('graph', '-', $rrd_options);
|
||||
echo escapeshellcmd('rrdtool ' . Rrd::buildCommand('graph', Config::get('temp_dir') . '/' . strgen(), $rrd_options));
|
||||
echo '</pre>';
|
||||
try {
|
||||
Rrd::graph($rrd_options);
|
||||
|
Loading…
Reference in New Issue
Block a user