1
0

Feat: 添加详细调试日志输出拓扑构建过程

- 输出每个设备的邻居数量和MAC地址数量
- 输出邻居匹配过程(IP/主机名/MAC)
- 输出匹配失败的详细信息
- 输出创建的连线详情
Bu işleme şunda yer alıyor:
Your Name
2026-04-26 01:16:17 +08:00
ebeveyn 6771858c40
işleme c28c6ad128
+17
Dosyayı Görüntüle
@@ -55,15 +55,23 @@ func (b *Builder) Build() models.TopologyGraph {
// 构建边(基于邻居信息) // 构建边(基于邻居信息)
edgeMap := make(map[string]bool) // 用于去重 edgeMap := make(map[string]bool) // 用于去重
for _, device := range b.devices { for _, device := range b.devices {
fmt.Printf("Building edges for device %s: %d neighbors, %d MAC addresses\n",
device.IP, len(device.Neighbors), len(device.MACAddresses))
for _, neighbor := range device.Neighbors { for _, neighbor := range device.Neighbors {
// 尝试匹配邻居设备 // 尝试匹配邻居设备
targetIP := neighbor.RemoteIP targetIP := neighbor.RemoteIP
matchMethod := "IP"
// 如果没有IP,尝试通过设备名匹配 // 如果没有IP,尝试通过设备名匹配
if targetIP == "" && neighbor.RemoteDevice != "" { if targetIP == "" && neighbor.RemoteDevice != "" {
fmt.Printf(" Neighbor %s has no IP, trying hostname match: %s\n",
neighbor.LocalInterface, neighbor.RemoteDevice)
for _, d := range b.devices { for _, d := range b.devices {
if d.Hostname == neighbor.RemoteDevice { if d.Hostname == neighbor.RemoteDevice {
targetIP = d.IP targetIP = d.IP
matchMethod = "hostname"
fmt.Printf(" Matched by hostname: %s -> %s\n", d.Hostname, d.IP)
break break
} }
} }
@@ -71,10 +79,14 @@ func (b *Builder) Build() models.TopologyGraph {
// 如果还是没有,尝试通过MAC地址匹配(新增) // 如果还是没有,尝试通过MAC地址匹配(新增)
if targetIP == "" && neighbor.RemoteMAC != "" { if targetIP == "" && neighbor.RemoteMAC != "" {
fmt.Printf(" Neighbor %s has no IP/hostname, trying MAC match: %s\n",
neighbor.LocalInterface, neighbor.RemoteMAC)
for _, d := range b.devices { for _, d := range b.devices {
for _, mac := range d.MACAddresses { for _, mac := range d.MACAddresses {
if mac == neighbor.RemoteMAC { if mac == neighbor.RemoteMAC {
targetIP = d.IP targetIP = d.IP
matchMethod = "MAC"
fmt.Printf(" Matched by MAC: %s -> %s\n", mac, d.IP)
break break
} }
} }
@@ -85,8 +97,13 @@ func (b *Builder) Build() models.TopologyGraph {
} }
if targetIP == "" { if targetIP == "" {
fmt.Printf(" Neighbor %s could not be matched (RemoteIP=%s, RemoteMAC=%s, RemoteDevice=%s)\n",
neighbor.LocalInterface, neighbor.RemoteIP, neighbor.RemoteMAC, neighbor.RemoteDevice)
continue continue
} }
fmt.Printf(" Creating edge: %s (%s) -> %s via %s, matched by %s\n",
device.IP, neighbor.LocalInterface, targetIP, neighbor.RemoteInterface, matchMethod)
// 创建唯一的边ID // 创建唯一的边ID
edgeID := fmt.Sprintf("%s-%s-%s", device.IP, neighbor.LocalInterface, targetIP) edgeID := fmt.Sprintf("%s-%s-%s", device.IP, neighbor.LocalInterface, targetIP)