Files
librenms-librenms/includes/html/graphs/graph.inc.php
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.3 KiB
PHP
Raw Normal View History

<?php
use LibreNMS\Config;
2022-10-28 08:06:29 -05:00
use LibreNMS\Data\Graphing\GraphParameters;
use LibreNMS\Enum\ImageFormat;
2021-05-03 09:48:15 -05:00
global $debug;
2022-08-30 12:55:37 -05:00
if (isset($vars['device'])) {
$device = is_numeric($vars['device'])
? device_by_id_cache($vars['device'])
: device_by_name($vars['device']);
2022-10-28 08:06:29 -05:00
DeviceCache::setPrimary($device['device_id']);
}
2022-10-28 08:06:29 -05:00
// variables for included graphs
$graph_params = new GraphParameters($vars);
// set php variables for legacy graphs
$type = $graph_params->type;
$subtype = $graph_params->subtype;
$height = $graph_params->height;
$width = $graph_params->width;
$from = $graph_params->from;
$to = $graph_params->to;
$period = $graph_params->period;
$prev_from = $graph_params->prev_from;
$inverse = $graph_params->inverse;
$in = $graph_params->in;
$out = $graph_params->out;
$float_precision = $graph_params->float_precision;
$title = $graph_params->visible('title');
$nototal = ! $graph_params->visible('total');
$nodetails = ! $graph_params->visible('details');
$noagg = ! $graph_params->visible('aggregate');
2021-05-03 09:48:15 -05:00
$rrd_options = '';
2011-09-22 13:39:03 +00:00
2019-06-23 00:29:12 -05:00
require Config::get('install_dir') . "/includes/html/graphs/$type/auth.inc.php";
2015-07-13 20:10:26 +02:00
if ($auth && is_customoid_graph($type, $subtype)) {
$unit = $vars['unit'];
include Config::get('install_dir') . '/includes/html/graphs/customoid/customoid.inc.php';
2019-06-23 00:29:12 -05:00
} elseif ($auth && is_file(Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php")) {
include Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php";
2016-08-18 20:28:22 -05:00
} else {
graph_error("$type*$subtype ");
// Graph Template Missing");
}
2021-05-03 09:48:15 -05:00
if ($auth === null) {
2012-05-25 12:24:34 +00:00
// We are unauthenticated :(
graph_error($width < 200 ? 'No Auth' : 'No Authorization');
2021-05-03 09:48:15 -05:00
return;
}
2022-10-28 08:06:29 -05:00
$rrd_options = $graph_params . ' ' . $rrd_options;
2021-05-03 09:48:15 -05:00
// command output requested
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'>";
2021-05-13 11:27:05 -05:00
echo escapeshellcmd('rrdtool ' . Rrd::buildCommand('graph', Config::get('temp_dir') . '/' . strgen(), $rrd_options));
2021-05-03 09:48:15 -05:00
echo '</pre>';
try {
Rrd::graph($rrd_options);
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Output</p>";
echo "<pre class='rrd-pre'>";
2021-05-03 09:48:15 -05:00
echo $e->getMessage();
echo '</pre>';
2021-05-03 09:48:15 -05:00
}
echo '</div>';
return;
}
if (empty($rrd_options)) {
graph_error($width < 200 ? 'Def Error' : 'Graph Definition Error');
return;
}
// Generating the graph!
try {
$image_data = Rrd::graph($rrd_options);
// output the graph
if (\LibreNMS\Util\Debug::isEnabled()) {
2022-10-28 08:06:29 -05:00
echo '<img src="data:' . ImageFormat::forGraph()->contentType() . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
2021-05-03 09:48:15 -05:00
} else {
2022-10-28 08:06:29 -05:00
header('Content-type: ' . ImageFormat::forGraph()->contentType());
2021-05-03 09:48:15 -05:00
echo $output === 'base64' ? base64_encode($image_data) : $image_data;
}
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
if (\LibreNMS\Util\Debug::isEnabled()) {
throw $e;
}
2021-05-03 09:48:15 -05:00
if (isset($rrd_filename) && ! Rrd::checkRrdExists($rrd_filename)) {
graph_error($width < 200 ? 'No Data' : 'No Data file ' . basename($rrd_filename));
} else {
2021-05-03 09:48:15 -05:00
graph_error($width < 200 ? 'Draw Error' : 'Error Drawing Graph: ' . $e->getMessage());
}
2010-08-01 17:25:44 +00:00
}