port_id map $ports_mapped = get_ports_mapped ($device['device_id']); $ports_db = $ports_mapped['ports']; // // Rename any old RRD files still named after the previous ifIndex based naming schema. foreach ($ports_mapped['maps']['ifIndex'] as $ifIndex => $port_id) { foreach (array ('', 'adsl', 'dot3') as $suffix) { $suffix_tmp = ''; if ($suffix) $suffix_tmp = "-$suffix"; $old_rrd_path = trim ($config['rrd_dir']) . '/' . $device['hostname'] . "/port-$ifIndex$suffix_tmp.rrd"; $new_rrd_path = get_port_rrdfile_path ($device['hostname'], $port_id, $suffix); if (is_file ($old_rrd_path)) { rename ($old_rrd_path, $new_rrd_path); } } } // New interface detection foreach ($port_stats as $ifIndex => $port) { // Store ifIndex in port entry and prefetch ifName as we'll need it multiple times $port['ifIndex'] = $ifIndex; $ifName = $port['ifName']; // Get port_id according to port_association_mode used for this device $port_id = get_port_id ($ports_mapped, $port, $port_association_mode); if (is_port_valid($port, $device)) { // Port newly discovered? if (! is_array($ports_db[$port_id])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifName' => $ifName), 'ports'); $ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port_id)); echo 'Adding: '.$ifName.'('.$ifIndex.')('.$port_id.')'; } // Port re-discovered after previous deletion? else if ($ports_db[$port_id]['deleted'] == '1') { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$port_id])); $ports_db[$port_id]['deleted'] = '0'; echo 'U'; } else { echo '.'; } // We've seen it. Remove it from the cache. unset($ports_l[$ifIndex]); } // Port vanished (mark as deleted) else { if (is_array($ports_db[$port_id])) { if ($ports_db[$port_id]['deleted'] != '1') { dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports_db[$port_id])); $ports_db[$port_id]['deleted'] = '1'; echo '-'; } } echo 'X'; }//end if }//end foreach // End New interface detection // Interface Deletion // If it's in our $ports_l list, that means it's not been seen. Mark it deleted. foreach ($ports_l as $ifIndex => $port_id) { if ($ports_db[$ifIndex]['deleted'] == '0') { dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id)); echo '-'.$ifIndex; } } // End interface deletion echo "\n"; // Clear Variables Here unset($port_stats); unset($ports_db);