فهرست منبع

Fix: 优化H3C ARP表解析和邻居关联

- 使用display arp命令(已验证可用)
- ARP命令失败时不影响其他数据采集
- 添加详细日志显示ARP条目数量
- 如果ARP表中找不到IP,使用MAC地址作为邻居标识
- 容错处理:ARP表为空时继续处理邻居信息
Your Name 1 ماه پیش
والد
کامیت
84724995b8
1فایلهای تغییر یافته به همراه19 افزوده شده و 4 حذف شده
  1. 19 4
      internal/device/h3c.go

+ 19 - 4
internal/device/h3c.go

@@ -20,7 +20,7 @@ func (p *H3CParser) GetCommands() []string {
 		"display interface",
 		"display interface",
 		"display ip interface brief",
 		"display ip interface brief",
 		"display lldp neighbor-information",
 		"display lldp neighbor-information",
-		"display arp",  // 添加ARP表用于MAC到IP的映射
+		"display arp",  // ARP表用于MAC到IP的映射
 	}
 	}
 }
 }
 
 
@@ -33,11 +33,22 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
 	p.parseVersion(device, outputs[0])
 	p.parseVersion(device, outputs[0])
 	device.Interfaces = p.parseInterfaces(outputs[1], outputs[2])
 	device.Interfaces = p.parseInterfaces(outputs[1], outputs[2])
 	
 	
-	// 解析ARP表用于MAC到IP映射
-	arpTable := p.parseARPTable(outputs[4])
+	// 解析ARP表用于MAC到IP映射(允许失败)
+	arpTable := make(map[string]string)
+	if outputs[4] != "" {
+		arpTable = p.parseARPTable(outputs[4])
+		if len(arpTable) == 0 {
+			fmt.Printf("Warning: ARP table is empty for device %s\n", device.IP)
+		}
+	} else {
+		fmt.Printf("Warning: ARP command output is empty for device %s\n", device.IP)
+	}
 	
 	
 	// 解析LLDP邻居,使用ARP表进行MAC到IP的映射
 	// 解析LLDP邻居,使用ARP表进行MAC到IP的映射
 	device.Neighbors = p.parseNeighbors(outputs[3], arpTable)
 	device.Neighbors = p.parseNeighbors(outputs[3], arpTable)
+	
+	fmt.Printf("Device %s: %d interfaces, %d neighbors, %d ARP entries\n",
+		device.IP, len(device.Interfaces), len(device.Neighbors), len(arpTable))
 
 
 	return nil
 	return nil
 }
 }
@@ -205,7 +216,11 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) []
 						// 通过ARP表查找IP
 						// 通过ARP表查找IP
 						if ip, ok := arpTable[mac]; ok {
 						if ip, ok := arpTable[mac]; ok {
 							currentNeighbor.RemoteIP = ip
 							currentNeighbor.RemoteIP = ip
-							currentNeighbor.RemoteDevice = ip // 暂时用IP作为设备名
+							currentNeighbor.RemoteDevice = ip
+						} else {
+							// 如果ARP表中没有,使用MAC地址作为标识
+							currentNeighbor.RemoteDevice = mac
+							// 注意:RemoteIP为空,拓扑可能无法连线
 						}
 						}
 					}
 					}
 				}
 				}