Skip to content

Commit d7771cb

Browse files
committed
remove graph.php usage part 1
1 parent d8bb07f commit d7771cb

4 files changed

Lines changed: 22 additions & 74 deletions

File tree

LibreNMS/Alert/Transport/Grafana.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ public function deliverAlert(array $alert_data): bool
4040
'title' => 'yes',
4141
];
4242

43-
//$graph_url = url('graph.php') . '?' . http_build_query($graph_args);
44-
// FIXME - workaround for https://github.com/grafana/oncall/issues/3031
45-
$graph_url = url('graph.php') . '/' . str_replace('&', '/', http_build_query($graph_args));
46-
4743
$data = [
4844
'alert_uid' => $alert_data['id'],
4945
'title' => $alert_data['title'] ?? null,
50-
'image_url' => $graph_url,
46+
'image_url' => route('graph', $graph_args),
5147
'link_to_upstream_details' => Url::deviceUrl($device),
5248
'state' => ($alert_data['state'] == AlertState::ACTIVE) ? 'alerting' : 'ok',
5349
'raw_state' => $alert_data['state'],

LibreNMS/Util/Url.php

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -298,51 +298,6 @@ public static function sensorUrl($sensor, $vars = [])
298298
return self::generate(['page' => 'device', 'device' => $sensor->device_id, 'tab' => 'health', 'metric' => $sensor->sensor_class], $vars);
299299
}
300300

301-
/**
302-
* @param Port $port
303-
* @return string
304-
*/
305-
public static function portThumbnail($port)
306-
{
307-
$graph_array = [
308-
'port_id' => $port->port_id,
309-
'graph_type' => 'port_bits',
310-
'from' => Carbon::now()->subDay()->timestamp,
311-
'to' => Carbon::now()->timestamp,
312-
'width' => 150,
313-
'height' => 21,
314-
];
315-
316-
return self::portImage($graph_array);
317-
}
318-
319-
/**
320-
* @param Port $port
321-
* @return string
322-
*/
323-
public static function portErrorsThumbnail($port)
324-
{
325-
$graph_array = [
326-
'port_id' => $port->port_id,
327-
'graph_type' => 'port_errors',
328-
'from' => Carbon::now()->subDay()->timestamp,
329-
'to' => Carbon::now()->timestamp,
330-
'width' => 150,
331-
'height' => 21,
332-
];
333-
334-
return self::portImage($graph_array);
335-
}
336-
337-
public static function portImage($args)
338-
{
339-
if (empty($args['bg'])) {
340-
$args['bg'] = 'FFFFFF00';
341-
}
342-
343-
return '<img src="graph-image ' . url('graph.php') . '?type=' . $args['graph_type'] . '&amp;id=' . $args['port_id'] . '&amp;from=' . $args['from'] . '&amp;to=' . $args['to'] . '&amp;width=' . $args['width'] . '&amp;height=' . $args['height'] . '&amp;bg=' . $args['bg'] . '">';
344-
}
345-
346301
public static function generate($vars, $new_vars = [])
347302
{
348303
$vars = array_merge($vars, $new_vars);
@@ -393,17 +348,12 @@ public static function graphPageUrl(string $type, array $args = []): string
393348
}
394349

395350
/**
396-
* @param array $args
351+
* @param string[] $args
397352
* @return string
398353
*/
399-
public static function graphTag($args)
354+
public static function graphTag($args): string
400355
{
401-
$urlargs = [];
402-
foreach ($args as $key => $arg) {
403-
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
404-
}
405-
406-
return '<img class="graph-image" src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;" />';
356+
return '<img class="graph-image" src="' . route('graph', $args) . '" style="border:0;" />';
407357
}
408358

409359
public static function graphPopup($args, $content = null, $link = null)
@@ -438,13 +388,7 @@ public static function graphPopup($args, $content = null, $link = null)
438388

439389
public static function lazyGraphTag($args, string $class = 'img-responsive'): string
440390
{
441-
$urlargs = [];
442-
443-
foreach ($args as $key => $arg) {
444-
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
445-
}
446-
447-
$tag = '<img class="graph-image ' . $class . '" src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;"';
391+
$tag = '<img class="graph-image ' . $class . '" src="' . route('graph', $args) . '" style="border:0;"';
448392

449393
if (LibrenmsConfig::get('enable_lazy_load', true)) {
450394
return $tag . ' loading="lazy" />';
@@ -501,16 +445,24 @@ public static function overlibContent($graph_array, $text)
501445
* @param string $legend
502446
* @param int $width
503447
* @param int $height
504-
* @param string $sep
505448
* @param string $class
506449
* @param int $absolute_size
507450
* @return string
508451
*/
509-
public static function minigraphImage($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&amp;', $class = 'minigraph-image', $absolute_size = 0)
452+
public static function minigraphImage($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $class = 'minigraph-image', $absolute_size = 0): string
510453
{
511-
$vars = ['device=' . $device->device_id, "from=$start", "to=$end", "width=$width", "height=$height", "type=$type", "legend=$legend", "absolute=$absolute_size"];
454+
$vars = [
455+
'device' => $device->device_id,
456+
'from' => $start,
457+
'to' => $end,
458+
'width' => $width,
459+
'height' => $height,
460+
'type' => $type,
461+
'legend' => $legend,
462+
'absolute' => $absolute_size,
463+
];
512464

513-
return '<img class="graph-image ' . $class . '" width="' . $width . '" height="' . $height . '" src="' . url('graph.php') . '?' . implode($sep, $vars) . '">';
465+
return '<img class="graph-image ' . $class . '" width="' . $width . '" height="' . $height . '" src="' . route('graph', $vars) . '">';
514466
}
515467

516468
/**

app/Models/Port.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ public function getLabel()
150150

151151
/**
152152
* Get the shortened label for this device. Replaces things like GigabitEthernet with GE.
153-
*
154-
* @return string
155153
*/
156-
public function getShortLabel()
154+
public function getShortLabel(?int $length = null): string
157155
{
158-
return Rewrite::shortenIfName(Rewrite::normalizeIfName($this->ifName ?: $this->ifDescr));
156+
$name = Rewrite::normalizeIfName($this->ifName ?: $this->ifDescr);
157+
158+
return substr(Rewrite::shortenIfName($name), 0, $length);
159159
}
160160

161161
/**

app/View/Components/Graph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function filterAttributes($value, $key): bool
136136

137137
private function getSrc(): string
138138
{
139-
return url('graph.php') . '?' . http_build_query($this->vars + [
139+
return route('graph', $this->vars + [
140140
'type' => $this->type,
141141
'legend' => $this->legend,
142142
'absolute_size' => $this->absolute_size,

0 commit comments

Comments
 (0)