From 5521002b379bb831080d4db1ceb2af971421d946 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Wed, 3 Feb 2016 21:05:42 +0100 Subject: [PATCH] Fix port association for adsl, etherlike and poe port information. In 2c9df26bbf22af94c354bcf445b55a56eaece81a I broke the association of ports in the DB and ports just polled via SNMP for the adsl, etherlike and poe submodules and no one noticed. This fixes this issue. Sorry. Signed-off-by: Maximilian Wilhelm --- includes/polling/port-adsl.inc.php | 4 ++-- includes/polling/port-etherlike.inc.php | 6 +++--- includes/polling/port-poe.inc.php | 6 +++--- includes/polling/ports.inc.php | 17 ++++++++++++----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/includes/polling/port-adsl.inc.php b/includes/polling/port-adsl.inc.php index e3567e26b5..901fb6d0b9 100644 --- a/includes/polling/port-adsl.inc.php +++ b/includes/polling/port-adsl.inc.php @@ -39,9 +39,9 @@ // adslAturPerfESs.1 = 0 seconds // adslAturPerfValidIntervals.1 = 0 // adslAturPerfInvalidIntervals.1 = 0 -if (isset($port_stats[$port_id]['adslLineCoding'])) { +if (isset($port_stats[$ifIndex]['adslLineCoding'])) { // Check to make sure Port data is cached. - $this_port = &$port_stats[$port_id]; + $this_port = &$port_stats[$ifIndex]; $rrdfile = get_port_rrdfile_path ($device['hostname'], $port_id, 'adsl'); diff --git a/includes/polling/port-etherlike.inc.php b/includes/polling/port-etherlike.inc.php index bf947b92db..ea8b044c2a 100644 --- a/includes/polling/port-etherlike.inc.php +++ b/includes/polling/port-etherlike.inc.php @@ -1,10 +1,10 @@ $port) { dbInsert(array('port_id' => $port_id), 'ports_statistics'); } - // Assure stable mapping - $port_stats[$ifIndex]['port_id'] = $port_id; + /** Assure stable bidirectional port mapping between DB and polled data + * + * Store the *current* ifIndex in the port info array containing all port information + * fetched from the database, as this is the only means we have to map ports_stats we + * just polled from the device to a port in $ports. All code below an includeed below + * will and has to map a port using it's ifIndex. + */ $ports[$port_id]['ifIndex'] = $ifIndex; + $port_stats[$ifIndex]['port_id'] = $port_id; } // Port vanished (mark as deleted) @@ -299,11 +305,12 @@ echo "\n"; // Loop ports in the DB and update where necessary foreach ($ports as $port) { $port_id = $port['port_id']; + $ifIndex = $port['ifIndex']; - echo 'Port ' . $port['ifName'] . ': ' . $port['ifDescr'] . '(' . $port['ifIndex'] . ') '; - if ($port_stats[$port['ifIndex']] && $port['disabled'] != '1') { + echo 'Port ' . $port['ifName'] . ': ' . $port['ifDescr'] . '(' . $ifIndex . ') '; + if ($port_stats[$ifIndex] && $port['disabled'] != '1') { // Check to make sure Port data is cached. - $this_port = &$port_stats[$port['ifIndex']]; + $this_port = &$port_stats[$ifIndex]; if ($device['os'] == 'vmware' && preg_match('/Device ([a-z0-9]+) at .*/', $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1];