diff --git a/cleanup.php b/cleanup.php
index 664b054fb..729876d8e 100755
--- a/cleanup.php
+++ b/cleanup.php
@@ -58,8 +58,8 @@ while($row = mysql_fetch_array($data)) {
if($response != $index) {
mysql_query("DELETE from interfaces where interface_id = '" . $row['interface_id'] . "'");
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $row['interface_id'] . "'");
- mysql_query("DELETE from `links` WHERE `src_if` = '" . $row['interface_id'] . "'");
- mysql_query("DELETE from `links` WHERE `dst_if` = '" . $row['interface_id'] . "'");
+ mysql_query("DELETE from `links` WHERE `local_interface_id` = '" . $row['interface_id'] . "'");
+ mysql_query("DELETE from `links` WHERE `remote_interface_id` = '" . $row['interface_id'] . "'");
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '" . $row['interface_id'] . "'");
echo("Removed interface " . $row['ifDescr'] . " from " . $row['hostname'] . "
");
}
@@ -78,11 +78,11 @@ while ($interface = mysql_fetch_array($interface_query)) {
echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at end\n");
echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at start\n");
-$link_query = mysql_query("SELECT id,src_if,dst_if FROM `links`");
+$link_query = mysql_query("SELECT id,local_interface_id,remote_interface_id FROM `links`");
while ($link = mysql_fetch_array($link_query)) {
$id = $link['id'];
- $src = $link['src_if'];
- $dst = $link['dst_if'];
+ $src = $link['local_interface_id'];
+ $dst = $link['remote_interface_id'];
if(mysql_result(mysql_query("SELECT COUNT(interface_id) FROM `interfaces` WHERE `interface_id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `interface_id` = '$dst'"), 0) == '0') {
mysql_query("delete from links where `id` = '$id'");
echo("Deleting link $id \n");
diff --git a/database-update.sql b/database-update.sql
index 4de4504f3..23a06be5c 100644
--- a/database-update.sql
+++ b/database-update.sql
@@ -95,3 +95,7 @@ ALTER TABLE `processors` CHANGE `processor_description` `processor_descr` varch
ALTER TABLE `fanspeed` CHANGE `fan_mibtype` `fan_type` varchar(64) NOT NULL ;
ALTER TABLE `voltage` ADD `volt_index` VARCHAR( 8 ) NOT NULL AFTER `volt_oid`,ADD `volt_type` VARCHAR( 32 ) NOT NULL AFTER `volt_index` ;
ALTER TABLE `processors` ADD `processor_precision` INT( 11 ) NOT NULL DEFAULT '1';
+ALTER TABLE `links` CHANGE `cdp` `vendor` VARCHAR( 11 ) NULL DEFAULT NULL;
+ALTER TABLE `links` ADD `remote_hostname` VARCHAR( 128 ) NOT NULL ,ADD `remote_port` VARCHAR( 128 ) NOT NULL ,ADD `remote_platform` VARCHAR( 128 ) NOT NULL ,ADD `remote_version` VARCHAR( 256 ) NOT NULL ;
+ALTER TABLE `links` CHANGE `src_if` `local_interface_id` INT( 11 ) NULL DEFAULT NULL ,CHANGE `dst_if` `remote_interface_id` INT( 11 ) NULL DEFAULT NULL ;
+ALTER TABLE `links` CHANGE `vendor` `protocol` VARCHAR( 11 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php
index a5ff2f7e2..121eefc4b 100644
--- a/html/includes/print-interface.inc.php
+++ b/html/includes/print-interface.inc.php
@@ -103,7 +103,7 @@
echo("");
echo("
" . generateiflink($link, makeshortif($link['label'])) . " on " . generatedevicelink($link, shorthost($link['hostname'])) . "
Map
diff --git a/html/pages/purgeports.php b/html/pages/purgeports.php
index 3258918f9..d6b15196d 100644
--- a/html/pages/purgeports.php
+++ b/html/pages/purgeports.php
@@ -24,8 +24,8 @@
mysql_query("DELETE FROM `pseudowires` WHERE `interface_id` = '$interface_id'");
mysql_query("DELETE FROM `mac_accounting` WHERE `interface_id` = '$interface_id'");
- mysql_query("DELETE FROM `links` WHERE `src_if` = '$interface_id'");
- mysql_query("DELETE FROM `links` WHERE `dst_if` = '$interface_id'");
+ mysql_query("DELETE FROM `links` WHERE `local_interface_id` = '$interface_id'");
+ mysql_query("DELETE FROM `links` WHERE `remote_interface_id` = '$interface_id'");
mysql_query("DELETE FROM `interfaces_perms` WHERE `interface_id` = '$interface_id'");
mysql_query("DELETE FROM `interfaces` WHERE `interface_id` = '$interface_id'");
}
diff --git a/includes/discovery/cdp-lldp.inc.php b/includes/discovery/cdp-lldp.inc.php
index 15e06ea76..76859f923 100755
--- a/includes/discovery/cdp-lldp.inc.php
+++ b/includes/discovery/cdp-lldp.inc.php
@@ -2,6 +2,35 @@
$community = $device['community'];
+echo("Brocade FDP: ");
+
+$fdp_array = snmpwalk_cache_twopart_oid("snFdpCacheEntry", $device, array(), "FOUNDRY-SN-SWITCH-GROUP-MIB");
+$fdp_array = $fdp_array[$device['device_id']];
+if($fdp_array) {
+ unset($fdp_links);
+ foreach( array_keys($fdp_array) as $key)
+ {
+ $interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
+ $fdp_if_array = $fdp_array[$key];
+ foreach( array_keys($fdp_if_array) as $entry_key)
+ {
+ $fdp = $fdp_if_array[$entry_key];
+ $remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$fdp['snFdpCacheDeviceId']."' OR `hostname`='".$fdp['snFdpCacheDeviceId']."'"), 0);
+ if($remote_device_id) {
+ $if = $fdp['snFdpCacheDevicePort'];
+ $remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
+ } else { $remote_interface_id = "0"; }
+
+ discover_link($interface['interface_id'], $fdp['snFdpCacheVendorId'], $remote_interface_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
+
+
+ }
+ }
+}
+
+echo("\n");
+
+
echo("CISCO-CDP-MIB: ");
unset($cdp_array);
@@ -13,13 +42,14 @@ if($cdp_array) {
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
$cdp_if_array = $cdp_array[$key];
foreach( array_keys($cdp_if_array) as $entry_key) {
- $cdp_entry_array = $cdp_if_array[$entry_key];
- if($device['hostname'] && $interface['ifIndex'] && $cdp_entry_array['cdpCacheDeviceId'] && $cdp_entry_array['cdpCacheDevicePort']){
- if(strpos($cdp_entry_array['cdpCacheDeviceId'], ")")) { list(,$cdp_entry_array['cdpCacheDeviceId']) = explode("(", $cdp_entry_array['cdpCacheDeviceId']); echo($cdp_entry_array['cdpCacheDeviceId']);
- list($cdp_entry_array['cdpCacheDeviceId'],) = explode(")", $cdp_entry_array['cdpCacheDeviceId']); echo($cdp_entry_array['cdpCacheDeviceId']); }
-
- $cdp_links .= $device['hostname'] . "," . $interface['ifIndex'] . "," . $cdp_entry_array['cdpCacheDeviceId'] . "," . $cdp_entry_array['cdpCacheDevicePort'] . "\n";
- echo ".";
+ $cdp = $cdp_if_array[$entry_key];
+ $remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$cdp['cdpCacheDeviceId']."' OR `hostname`='".$cdp['cdpCacheDeviceId']."'"), 0);
+ if($remote_device_id) {
+ $if = $cdp['cdpCacheDevicePort'];
+ $remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
+ } else { $remote_interface_id = "0"; }
+ if($interface['interface_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort']) {
+ discover_link($interface['interface_id'], 'cdp', $remote_interface_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion']);
}
}
}
@@ -37,90 +67,44 @@ if($lldp_array) {
$lldp_if_array = $lldp_array[$key];
foreach( array_keys($lldp_if_array) as $entry_key) {
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$entry_key."'"));
- $lldp_entry_array = $lldp_if_array[$entry_key];
- foreach ( array_keys($lldp_entry_array) as $entry_instance) {
- $lldp_entry_instance_array = $lldp_entry_array[$entry_instance];
- if($device['hostname'] && $interface['ifIndex'] && $lldp_entry_instance_array['lldpRemSysName'] && $lldp_entry_instance_array['lldpRemPortId']){
- if(strpos($lldp_entry_instance_array['lldpRemSysName'], ")")) { list(,$lldp_entry_instance_array['lldpRemSysName']) = explode("(", $lldp_entry_instance_array['lldpRemSysName']); echo($lldp_entry_instance_array['lldpRemSysName']);
- list($lldp_entry_instance_array['lldpRemSysName'],) = explode(")", $lldp_entry_instance_array['lldpRemSysName']); echo($lldp_entry_instance_array['lldpRemSysName']); }
+ $lldp_instance = $lldp_if_array[$entry_key];
+ foreach ( array_keys($lldp_instance) as $entry_instance) {
+ $lldp = $lldp_instance[$entry_instance];
+ $remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$lldp['lldpRemSysName']."' OR `hostname`='".$lldp['lldpRemSysName']."'"), 0);
+ if($remote_device_id) {
+ $if = $lldp['lldpRemPortDesc'];
+ $remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
+ } else { $remote_interface_id = "0"; }
- $lldp_links .= $device['hostname'] . "," . $interface['ifIndex'] . "," . $lldp_entry_instance_array['lldpRemSysName'] . "," . str_replace('"','',$lldp_entry_instance_array['lldpRemPortId']) . "\n";
- echo ".";
+ if($interface['interface_id'] && $lldp['lldpRemSysDesc'] && $lldp['lldpRemPortDesc']) {
+ discover_link($interface['interface_id'], 'lldp', $remote_interface_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortDesc'], NULL, $lldp['lldpRemSysDesc']);
}
}
}
}
}
-if($debug) {echo("$lldp_links");}
-$discovered_links = (isset($cdp_links) ? $cdp_links : '') . (isset($lldp_links) ? $lldp_links : '');
-if($discovered_links != "\n") {
- foreach ( explode("\n" ,$discovered_links) as $link ) {
- if ($link == "") { break; }
- list($src_host,$src_if, $dst_host, $dst_if) = explode(",", $link);
- $dst_host = strtolower($dst_host);
- $dst_if = strtolower($dst_if);
- $src_host = strtolower($src_host);
- $src_if = strtolower($src_if);
- $ip = gethostbyname($dst_host);
- if ( match_network($config['nets'], $ip) ) {
- if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host' OR `hostname`='$dst_host'"), 0) == '0' ) {
- if($config['lldp_autocreate']) {
- echo("++ Creating: $dst_host \n");
- createHost ($dst_host, $community, "v2c");
- }
- } else {
- echo(".");
- }
- } else {
- echo("!($dst_host)");
+if($debug) { print_r($link_exists); }
+
+$sql = "SELECT * FROM `links` AS L, `interfaces` AS I WHERE L.local_interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'";
+if ($query = mysql_query($sql))
+{
+ while ($test = mysql_fetch_array($query))
+ {
+ $local_interface_id = $test['local_interface_id'];
+ $remote_hostname = $test['remote_hostname'];
+ $remote_port = $test['remote_port'];
+ if($debug) { echo("$local_interface_id -> $remote_hostname -> $remote_port \n"); }
+ if(!$link_exists[$local_interface_id][$remote_hostname][$remote_port]) {
+ echo("-");
+ mysql_query("DELETE FROM `links` WHERE id = '" . $test['id'] . "'");
+ if($debug) {echo(mysql_affected_rows()." deleted ");}
}
-
- $dst_if_id = @mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE (`ifDescr` = '$dst_if' OR `ifName`='$dst_if') AND (sysName = '$dst_host' OR hostname='$dst_host') AND D.device_id = I.device_id"), 0);
-
- if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host' OR `hostname`='$dst_host'"), 0) == '1' &&
- mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$src_host'"), 0) == '1' &&
- $dst_if_id &&
- mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` AS I, `devices` AS D WHERE `ifIndex` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0) == '1')
- {
- $src_if_id = mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE `ifIndex` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0);
- $link_exists[] = $src_if_id . "," . $dst_if_id;
- if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `links` WHERE `dst_if` = '$dst_if_id' AND `src_if` = '$src_if_id'"),0) == '0')
- {
- $sql = "INSERT INTO `links` (`src_if`, `dst_if`) VALUES ('$src_if_id', '$dst_if_id')";
- mysql_query($sql);
- echo("\n++($src_host $src_if -> $dst_host $dst_if)");
- } else {
- echo("..");
- }
- } else {
-
- }
}
}
+unset($link_exists); echo("\n");
-$sql = "SELECT * FROM `links` AS L, `interfaces` AS I, `devices` AS D WHERE L.src_if = I.interface_id AND I.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
-$query = mysql_query($sql);
-
-while ($test_link = mysql_fetch_array($query)) {
- unset($exists);
- $i = 0;
- while ($i < count($link_exists) && !isset($exists)) {
- $this_link = $test_link['src_if'] . ",". $test_link['dst_if'];
- if ($link_exists[$i] == $this_link) { $exists = 1; }
- $i++;
- }
- if(!isset($exists)) {
- echo("-");
- mysql_query("DELETE FROM `links` WHERE `src_if` = '".$test_link['src_if']."' AND `dst_if` = '".$test_link['dst_if']."'");
- if($debug) { echo($link_exists[$i] . " REMOVED \n"); }
- } else {
- if($debug) { echo($link_exists[$i] . " VALID \n"); }
- }
-}
-
-echo("\n");
?>
diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php
index 7123d0991..d860c4326 100644
--- a/includes/discovery/functions.inc.php
+++ b/includes/discovery/functions.inc.php
@@ -1,5 +1,32 @@