diff --git a/LibreNMS/Modules/Mpls.php b/LibreNMS/Modules/Mpls.php index 0c247dc9d6..a42a19fb79 100644 --- a/LibreNMS/Modules/Mpls.php +++ b/LibreNMS/Modules/Mpls.php @@ -140,13 +140,13 @@ class Mpls implements Module $svcs = $this->syncModels($device, 'mplsServices', $os->pollMplsServices()); } - if ($device->mplsSaps()->exists()) { + if ($device->mplsSaps()->exists() && isset($svcs)) { echo "\nMPLS SAPs: "; ModuleModelObserver::observe(\App\Models\MplsSap::class); $this->syncModels($device, 'mplsSaps', $os->pollMplsSaps($svcs)); } - if ($device->mplsSdpBinds()->exists()) { + if ($device->mplsSdpBinds()->exists() && isset($sdps, $svcs)) { echo "\nMPLS SDP Bindings: "; ModuleModelObserver::observe(\App\Models\MplsSdpBind::class); $this->syncModels($device, 'mplsSdpBinds', $os->pollMplsSdpBinds($sdps, $svcs)); diff --git a/LibreNMS/OS/Timos.php b/LibreNMS/OS/Timos.php index e230540e94..d6b37cc31f 100644 --- a/LibreNMS/OS/Timos.php +++ b/LibreNMS/OS/Timos.php @@ -581,7 +581,10 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco $ip = long2ip(hexdec(str_replace(' ', '', $value['sdpFarEndInetAddress']))); } else { //Fixme implement ipv6 conversion - $ip = $value['sdpFarEndInetAddress']; + //$value['sdpFarEndInetAddress'] might still be any of these: + // -> unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16) + + $ip = $value['sdpFarEndInetAddress'] ?? null; } $sdps->push(new MplsSdp([ 'sdp_oid' => $value['sdpId'], @@ -787,7 +790,11 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco $arhops = new Collection(); foreach ($mplsTunnelArHopCache as $key => $value) { [$mplsTunnelARHopListIndex, $mplsTunnelARHopIndex] = explode('.', $key); - $lsp_path_id = $paths->firstWhere('mplsLspPathTunnelARHopListIndex', $mplsTunnelARHopListIndex)->lsp_path_id; + $firstPath = $paths->firstWhere('mplsLspPathTunnelARHopListIndex', $mplsTunnelARHopListIndex); + if (! isset($firstPath)) { + continue; + } + $lsp_path_id = $firstPath->lsp_path_id; $protection = intval($value['vRtrMplsTunnelARHopProtection'] ?? 0, 16); $localLinkProtection = ($protection & $localAvailable) ? 'true' : 'false'; diff --git a/database/migrations/2023_12_08_184652_mpls_addrtype_fix.php b/database/migrations/2023_12_08_184652_mpls_addrtype_fix.php new file mode 100644 index 0000000000..b664d508fb --- /dev/null +++ b/database/migrations/2023_12_08_184652_mpls_addrtype_fix.php @@ -0,0 +1,34 @@ +dropColumn(['sdpFarEndInetAddressType']); + }); + Schema::table('mpls_sdps', function ($table) { + $table->enum('sdpFarEndInetAddressType', ['unknown', 'ipv4', 'ipv6', 'ipv4z', 'ipv6z', 'dns'])->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('mpls_sdps', function ($table) { + $table->dropColumn(['sdpFarEndInetAddressType']); + }); + Schema::table('mpls_sdps', function ($table) { + $table->enum('sdpFarEndInetAddressType', ['ipv4', 'ipv6'])->nullable(); + }); + } +}; diff --git a/misc/db_schema.yaml b/misc/db_schema.yaml index 55d736c66a..67e80e88e4 100644 --- a/misc/db_schema.yaml +++ b/misc/db_schema.yaml @@ -1078,8 +1078,8 @@ mpls_sdps: - { Field: sdpLastMgmtChange, Type: bigint, 'Null': true, Extra: '' } - { Field: sdpLastStatusChange, Type: bigint, 'Null': true, Extra: '' } - { Field: sdpActiveLspType, Type: "enum('not-applicable','rsvp','ldp','bgp','none','mplsTp','srIsis','srOspf','srTeLsp','fpe')", 'Null': true, Extra: '' } - - { Field: sdpFarEndInetAddressType, Type: "enum('ipv4','ipv6')", 'Null': true, Extra: '' } - { Field: sdpFarEndInetAddress, Type: varchar(46), 'Null': true, Extra: '' } + - { Field: sdpFarEndInetAddressType, Type: "enum('unknown','ipv4','ipv6','ipv4z','ipv6z','dns')", 'Null': true, Extra: '' } Indexes: PRIMARY: { Name: PRIMARY, Columns: [sdp_id], Unique: true, Type: BTREE } mpls_sdps_device_id_index: { Name: mpls_sdps_device_id_index, Columns: [device_id], Unique: false, Type: BTREE } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1fbc39b02b..af61a5dd33 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,16 +50,6 @@ parameters: count: 2 path: LibreNMS/Modules/Mpls.php - - - message: "#^Variable \\$sdps might not be defined\\.$#" - count: 1 - path: LibreNMS/Modules/Mpls.php - - - - message: "#^Variable \\$svcs might not be defined\\.$#" - count: 2 - path: LibreNMS/Modules/Mpls.php - - message: "#^Variable \\$features on left side of \\?\\? is never defined\\.$#" count: 1