From d5c6d0aaf4c3032b2e94caf06bfb8411c327f74f Mon Sep 17 00:00:00 2001 From: Tim de Boer Date: Thu, 2 Nov 2023 06:41:19 +0100 Subject: [PATCH] Fixed BGP Remote peer link and graph in Routing Overview, or just static text when not a device in LibreNMS (#15535) * Fixed BGP Remote peer link and graph in Routing Overview, or just static text when not a device in LibreNMS * Added extra space * Reverted back to overlibLink (due to BGP update graphs on hover) * Added extra space * Remove graph for remote peer, as it is falsely (showed earlier the Updates Graph for local peer) * Removed unnecessary/unused code * Remove graph for remote peer, as it is falsely (showed earlier the Updates Graph for local peer), replaced with just a DeviceLinks * Change Url::deviceLink to return $text if the device doesn't exist. Default to '' Import some of the things to improve readability. * update phpdoc --------- Co-authored-by: Tony Murray --- LibreNMS/Util/Url.php | 8 +++---- includes/html/pages/routing/bgp.inc.php | 29 ++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/LibreNMS/Util/Url.php b/LibreNMS/Util/Url.php index 1ceb882740..dde15a8aa1 100644 --- a/LibreNMS/Util/Url.php +++ b/LibreNMS/Util/Url.php @@ -39,8 +39,8 @@ use Symfony\Component\HttpFoundation\ParameterBag; class Url { /** - * @param Device $device - * @param string $text + * @param Device|null $device + * @param string|null $text * @param array $vars * @param int $start * @param int $end @@ -48,10 +48,10 @@ class Url * @param int $overlib * @return string */ - public static function deviceLink($device, $text = null, $vars = [], $start = 0, $end = 0, $escape_text = 1, $overlib = 1) + public static function deviceLink($device, $text = '', $vars = [], $start = 0, $end = 0, $escape_text = 1, $overlib = 1) { if (! $device instanceof Device || ! $device->hostname) { - return ''; + return (string) $text; } if (! $device->canAccess(Auth::user())) { diff --git a/includes/html/pages/routing/bgp.inc.php b/includes/html/pages/routing/bgp.inc.php index 8ad9e296a9..44597339a1 100644 --- a/includes/html/pages/routing/bgp.inc.php +++ b/includes/html/pages/routing/bgp.inc.php @@ -1,7 +1,11 @@ hasGlobalRead()) { include 'includes/html/error-no-perm.inc.php'; @@ -272,26 +276,26 @@ if (! Auth::user()->hasGlobalRead()) { // display overlib graphs $graph_array = []; $graph_array['type'] = 'bgp_updates'; - $graph_array['id'] = $peer['bgpPeer_id']; $graph_array['to'] = \LibreNMS\Config::get('time.now'); $graph_array['from'] = \LibreNMS\Config::get('time.day'); $graph_array['height'] = '110'; $graph_array['width'] = $width; // Peer Address + $peer_device = Device::whereHas('bgppeers', fn ($q) => $q->where('bgpLocalAddr', $peer['bgpPeerIdentifier']))->first(); + $peeraddresslink = '' . Url::deviceLink($peer_device, $peer_addr, ['tab' => 'routing', 'proto' => 'bgp']) . ''; + + // Local Address + $graph_array['id'] = $peer['bgpPeer_id']; + $graph_array['afi'] = 'ipv4'; + $graph_array['safi'] = 'unicast'; $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = '150'; $graph_array_zoom['width'] = '500'; - $overlib_link = 'device/device=' . $peer['device_id'] . '/tab=routing/proto=bgp/'; - $peeraddresslink = '' . \LibreNMS\Util\Url::overlibLink($overlib_link, $peer_addr, \LibreNMS\Util\Url::graphTag($graph_array_zoom)) . ''; - - // Local Address - $graph_array['afi'] = 'ipv4'; - $graph_array['safi'] = 'unicast'; $graph_array_zoom['afi'] = 'ipv4'; $graph_array_zoom['safi'] = 'unicast'; $overlib_link = 'device/device=' . $peer['device_id'] . '/tab=routing/proto=bgp/'; - $localaddresslink = '' . \LibreNMS\Util\Url::overlibLink($overlib_link, $local_addr, \LibreNMS\Util\Url::graphTag($graph_array_zoom)) . ''; + $localaddresslink = '' . Url::overlibLink($overlib_link, $local_addr, Url::graphTag($graph_array_zoom)) . ''; if ($peer['bgpPeerLastErrorCode'] == 0 && $peer['bgpPeerLastErrorSubCode'] == 0) { $last_error = $peer['bgpPeerLastErrorText']; @@ -313,21 +317,20 @@ if (! Auth::user()->hasGlobalRead()) { } unset($sep); - $peer_device = \App\Models\Device::whereHas('bgppeers', fn ($q) => $q->where('bgpLocalAddr', $peer['bgpPeerIdentifier']))->first(); echo ' ' . $localaddresslink . '
' . generate_device_link($peer, null, ['tab' => 'routing', 'proto' => 'bgp']) . ' » - ' . $peeraddresslink . '
' . \LibreNMS\Util\Url::deviceLink($peer_device, vars: ['tab' => 'routing', 'proto' => 'bgp']) . " + ' . $peeraddresslink . '
' . Url::deviceLink($peer_device, vars: ['tab' => 'routing', 'proto' => 'bgp']) . " $peer_type " . $peer['afi'] . ' AS' . $peer['bgpPeerRemoteAs'] . '
' . $peer['astext'] . ' ' . $peer['bgpPeerDescr'] . " " . $peer['bgpPeerAdminStatus'] . "
" . $peer['bgpPeerState'] . '
' . $last_error . ' - ' . \LibreNMS\Util\Time::formatInterval($peer['bgpPeerFsmEstablishedTime']) . "
- Updates " . \LibreNMS\Util\Number::formatSi($peer['bgpPeerInUpdates'], 2, 3, '') . " - " . \LibreNMS\Util\Number::formatSi($peer['bgpPeerOutUpdates'], 2, 3, '') . ''; + ' . Time::formatInterval($peer['bgpPeerFsmEstablishedTime']) . "
+ Updates " . Number::formatSi($peer['bgpPeerInUpdates'], 2, 3, '') . " + " . Number::formatSi($peer['bgpPeerOutUpdates'], 2, 3, '') . ''; unset($invalid); switch ($vars['graph']) {