Index: includes/polling/fdb-table.inc.php
===================================================================
--- includes/polling/fdb-table.inc.php	(revision 6119)
+++ includes/polling/fdb-table.inc.php	(working copy)
@@ -97,6 +97,26 @@
 } else {
   //dot1qTpFdbPort[1][0:0:5e:0:1:1] 50
   //dot1qTpFdbStatus[1][0:0:5e:0:1:1] learned
+
+  if ($device['os'] == 'junos') {
+    // JUNOS doesn't use the actual vlan ids for much in Q-BRIDGE-MIB
+    // but we can get the vlan names and use that to lookup the actual
+    // vlan ids that were found with JUNIPER-VLAN-MIB during discovery
+
+    // Fetch list of active VLANs
+    foreach (dbFetchRows('SELECT `vlan_vlan`,`vlan_name` FROM `vlans` WHERE (`vlan_status` = ? OR `vlan_status` = ?) AND `device_id` = ?', array('active', 'operational', $device['device_id'])) as $vlannameandid) {
+      $vlanidsbyname[$vlannameandid['vlan_name']]=$vlannameandid['vlan_vlan'];
+    }
+    // getting the names as listed by Q-BRIDGE-MIB
+    // and making a mapping to the real vlan ids
+    $dot1qVlanStaticName_table = snmp_walk($device, 'dot1qVlanStaticName', '-OqsX', 'Q-BRIDGE-MIB');
+    foreach (explode("\n", $dot1qVlanStaticName_table) as $text) {
+      list($oid, $value) = explode(" ", $text);
+      preg_match('/(\w+)\[(\d+)\]\s+/', $text, $oid);
+      $fakejunipervlans[$oid[2]]=$vlanidsbyname[$value];
+    }
+  }
+
   $dot1qTpFdbEntry_table = snmp_walk($device, 'dot1qTpFdbEntry', '-OqsX', 'Q-BRIDGE-MIB');
   if ($GLOBALS['snmp_status'] !== FALSE)
   {
@@ -110,7 +130,12 @@
       list($oid, $value) = explode(" ", $text);
       preg_match('/(\w+)\[(\d+)\]\[([a-f0-9:]+)\]/', $text, $oid);
       if (!empty($value)) {
-        $vlan = $oid[2];
+        if (isset($fakejunipervlans[$oid[2]])) {
+	  // if we have a translated vlan id for juniper, use it
+	  $vlan = $fakejunipervlans[$oid[2]];
+        } else {
+          $vlan = $oid[2];
+        }
         $mac = '';
         foreach (explode(':', $oid[3]) as $m) { $mac .= zeropad($m); }
         $fdbs[$vlan][$mac][$oid[1]] = $value;