STP fix, only try contexts on Cisco (#13767)

* STP fix, only try contexts on Cisco
Only Cisco is known to support this type of polling

* merge, not push.

* Fix collection construction

* Fixed the function signature in Interface def

* fixed signature here as well

* Lighter code to return a collection of Stp instances

* Type enforced in signatures

* missing implement for Cisco Class

* style

* Collection methods are immutable indeed 😠

* nullable vlan

Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
This commit is contained in:
Tony Murray
2022-02-11 08:37:19 -06:00
committed by GitHub
parent 7d2ade71f1
commit b9f3646a2e
3 changed files with 71 additions and 54 deletions

View File

@@ -31,11 +31,13 @@ use App\Models\Mempool;
use App\Models\PortsNac;
use App\Models\Sla;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\MempoolsDiscovery;
use LibreNMS\Interfaces\Discovery\OSDiscovery;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Discovery\SlaDiscovery;
use LibreNMS\Interfaces\Discovery\StpInstanceDiscovery;
use LibreNMS\Interfaces\Polling\NacPolling;
use LibreNMS\Interfaces\Polling\SlaPolling;
use LibreNMS\OS;
@@ -43,7 +45,14 @@ use LibreNMS\OS\Traits\YamlOSDiscovery;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\IP;
class Cisco extends OS implements OSDiscovery, SlaDiscovery, ProcessorDiscovery, MempoolsDiscovery, NacPolling, SlaPolling
class Cisco extends OS implements
OSDiscovery,
SlaDiscovery,
StpInstanceDiscovery,
ProcessorDiscovery,
MempoolsDiscovery,
NacPolling,
SlaPolling
{
use YamlOSDiscovery {
YamlOSDiscovery::discoverOS as discoverYamlOS;
@@ -520,6 +529,20 @@ class Cisco extends OS implements OSDiscovery, SlaDiscovery, ProcessorDiscovery,
}
}
public function discoverStpInstances(?string $vlan = null): Collection
{
$vlans = $this->getDevice()->vlans;
$instances = new Collection;
// attempt to discover context based vlan instances
foreach ($vlans->isEmpty() ? [null] : $vlans as $vlan) {
$vlan = (empty($vlan->vlan_vlan) || $vlan->vlan_vlan == '1') ? null : (string) $vlan->vlan_vlan;
$instances = $instances->merge(parent::discoverStpInstances($vlan));
}
return $instances;
}
protected function getMainSerial()
{
$serial_output = snmp_get_multi($this->getDeviceArray(), ['entPhysicalSerialNum.1', 'entPhysicalSerialNum.1001'], '-OQUs', 'ENTITY-MIB:OLD-CISCO-CHASSIS-MIB');