mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix Port Channel (#16227)
* Fix expandable sizing * Temp fix: port_id_{low,high} is actually ifIndex * new PortsStack discovery module, store actual port_ids * Show 4 rows of ports by default * Add test data * Fix up the single port view too * Apply fixes from StyleCI * Update db_schema.yaml * Update base migration because sqlite cannot add primary keys * Fix phpstan failures --------- Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
This commit is contained in:
@@ -41,7 +41,7 @@ use LibreNMS\Interfaces\UI\DeviceTab;
|
||||
|
||||
class PortsController implements DeviceTab
|
||||
{
|
||||
private bool $detail = false;
|
||||
private bool $detail = true;
|
||||
private array $settings = [];
|
||||
private array $defaults = [
|
||||
'perPage' => 32,
|
||||
@@ -121,6 +121,8 @@ class PortsController implements DeviceTab
|
||||
$relationships[] = 'pseudowires.endpoints';
|
||||
$relationships[] = 'ipv4Networks.ipv4';
|
||||
$relationships[] = 'ipv6Networks.ipv6';
|
||||
$relationships['stackParent'] = fn ($q) => $q->select('port_id');
|
||||
$relationships['stackChildren'] = fn ($q) => $q->select('port_id');
|
||||
}
|
||||
|
||||
/** @var Collection<Port>|LengthAwarePaginator<Port> $ports */
|
||||
@@ -205,17 +207,13 @@ class PortsController implements DeviceTab
|
||||
}
|
||||
|
||||
// port stack
|
||||
// fa-expand portlink: local is low port
|
||||
// fa-compress portlink: local is high portPort
|
||||
$stacks = \DB::table('ports_stack')->where('device_id', $port->device_id)
|
||||
->where(fn ($q) => $q->where('port_id_high', $port->port_id)->orWhere('port_id_low', $port->port_id))->get();
|
||||
foreach ($stacks as $stack) {
|
||||
if ($stack->port_id_low) {
|
||||
$this->addPortNeighbor($neighbors, 'stack_low', $stack->port_id_low);
|
||||
}
|
||||
if ($stack->port_id_high) {
|
||||
$this->addPortNeighbor($neighbors, 'stack_high', $stack->port_id_high);
|
||||
}
|
||||
// fa-expand stack_parent: local is a child port
|
||||
// fa-compress stack_child: local is a parent port
|
||||
foreach ($port->stackParent as $stackParent) {
|
||||
$this->addPortNeighbor($neighbors, 'stack_parent', $stackParent->port_id);
|
||||
}
|
||||
foreach ($port->stackChildren as $stackChild) {
|
||||
$this->addPortNeighbor($neighbors, 'stack_child', $stackChild->port_id);
|
||||
}
|
||||
|
||||
// PAGP members/parent
|
||||
|
@@ -871,6 +871,11 @@ class Device extends BaseModel
|
||||
return $this->hasMany(\App\Models\PortsNac::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsStack(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\PortStack::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsStp(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\PortStp::class, 'device_id', 'device_id');
|
||||
|
@@ -50,7 +50,7 @@ class Port extends DeviceRelatedModel
|
||||
// dont have relationships yet
|
||||
DB::table('juniAtmVp')->where('port_id', $port->port_id)->delete();
|
||||
DB::table('ports_perms')->where('port_id', $port->port_id)->delete();
|
||||
DB::table('ports_stack')->where('port_id_low', $port->port_id)->orWhere('port_id_high', $port->port_id)->delete();
|
||||
DB::table('ports_stack')->where('low_port_id', $port->port_id)->orWhere('high_port_id', $port->port_id)->delete();
|
||||
|
||||
\Rrd::purge($port->device?->hostname, \Rrd::portName($port->port_id)); // purge all port rrd files
|
||||
});
|
||||
@@ -373,6 +373,16 @@ class Port extends DeviceRelatedModel
|
||||
return $this->hasMany(Pseudowire::class, 'port_id');
|
||||
}
|
||||
|
||||
public function stackChildren(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Port::class, PortStack::class, 'low_port_id', 'port_id', 'port_id', 'high_port_id');
|
||||
}
|
||||
|
||||
public function stackParent(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Port::class, PortStack::class, 'high_port_id', 'port_id', 'port_id', 'low_port_id');
|
||||
}
|
||||
|
||||
public function statistics(): HasMany
|
||||
{
|
||||
return $this->hasMany(PortStatistic::class, 'port_id');
|
||||
|
25
app/Models/PortStack.php
Normal file
25
app/Models/PortStack.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use LibreNMS\Interfaces\Models\Keyable;
|
||||
|
||||
class PortStack extends DeviceRelatedModel implements Keyable
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'ports_stack';
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'high_ifIndex',
|
||||
'high_port_id',
|
||||
'low_ifIndex',
|
||||
'low_port_id',
|
||||
'ifStackStatus',
|
||||
];
|
||||
|
||||
public function getCompositeKey()
|
||||
{
|
||||
return $this->high_ifIndex . '-' . $this->low_ifIndex;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user