From 7893b8bebe2dba8ea545a5669ea05f259a258009 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 17 Nov 2021 16:26:50 -0600 Subject: [PATCH] OSPF issue when devices don't support OSPF-MIB::ospfIfTable (#13530) * OSPF devices return wrong ospfIfTable index * Handle "End of MIB" string --- LibreNMS/Data/Source/SnmpResponse.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/LibreNMS/Data/Source/SnmpResponse.php b/LibreNMS/Data/Source/SnmpResponse.php index 3c18a8480b..c0d0249cc9 100644 --- a/LibreNMS/Data/Source/SnmpResponse.php +++ b/LibreNMS/Data/Source/SnmpResponse.php @@ -112,7 +112,7 @@ class SnmpResponse $values = []; $line = strtok($this->raw, PHP_EOL); while ($line !== false) { - if (Str::contains($line, ['at this OID', 'this MIB View'])) { + if (Str::contains($line, ['at this OID', 'this MIB View', 'End of MIB'])) { // these occur when we seek past the end of data, usually the end of the response, but grab the next line and continue $line = strtok(PHP_EOL); continue; @@ -171,11 +171,15 @@ class SnmpResponse } /** - * Map an snmp table with callback. + * Map an snmp table with callback. If invalid data is encountered, an empty collection is returned. * Variables passed to the callback will be an array of row values followed by each individual index. */ public function mapTable(callable $callback): Collection { + if (! $this->isValid()) { + return new Collection; + } + return collect($this->values()) ->map(function ($value, $oid) { $parts = explode('[', rtrim($oid, ']'), 2);