瀏覽代碼

Fix: 使用display interface brief替代ip interface brief

- 交换机使用VLAN互联,应该使用display interface brief
- 移除ARP表依赖,直接使用LLDP邻居信息
- 简化命令列表从6个减少到5个
Your Name 1 月之前
父節點
當前提交
db161fa3f2
共有 1 個文件被更改,包括 8 次插入21 次删除
  1. 8 21
      internal/device/h3c.go

+ 8 - 21
internal/device/h3c.go

@@ -19,20 +19,18 @@ func (p *H3CParser) GetCommands() []string {
 		"screen-length disable",  // 禁用分页(H3C/华为设备必需)
 		"display version",
 		"display interface",
-		"display ip interface brief",
+		"display interface brief",  // 接口简要信息(包含VLAN和物理接口状态)
 		"display lldp neighbor-information",
-		"display arp",  // ARP表用于MAC到IP的映射
 	}
 }
 
 // Parse 解析H3C设备输出
 func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
-	if len(outputs) < 6 {
+	if len(outputs) < 5 {
 		return fmt.Errorf("insufficient command outputs")
 	}
 
 	// outputs[0] 是 screen-length disable 的输出(通常为空)
-	fmt.Printf("[H3C DEBUG] screen-length disable output: %q (length: %d)\n", outputs[0], len(outputs[0]))
 	p.parseVersion(device, outputs[1])  // outputs[1] 是 display version
 	
 	// outputs[2] 是 display interface
@@ -51,7 +49,8 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
 	if outputs[2] == "" {
 		fmt.Printf("Warning: 'display interface' output is empty for device %s\n", device.IP)
 	} else {
-		device.Interfaces = p.parseInterfaces(outputs[2], outputs[3])  // outputs[3] 是 display ip interface brief
+		// outputs[3] 是 display interface brief
+		device.Interfaces = p.parseInterfaces(outputs[2], outputs[3])
 		if len(device.Interfaces) == 0 {
 			fmt.Printf("Warning: parsed 0 interfaces for device %s (output length: %d)\n", 
 				device.IP, len(outputs[2]))
@@ -73,24 +72,12 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
 	}
 	
 	// outputs[4] 是 display lldp neighbor-information
-	// outputs[5] 是 display arp
 	
-	// 解析ARP表用于MAC到IP映射(允许失败)
-	arpTable := make(map[string]string)
-	if outputs[5] != "" {
-		arpTable = p.parseARPTable(outputs[5])
-		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的映射
-	device.Neighbors = p.parseNeighbors(outputs[4], arpTable)
+	// 解析LLDP邻居
+	device.Neighbors = p.parseNeighbors(outputs[4], nil)
 	
-	fmt.Printf("Device %s: %d interfaces, %d neighbors, %d ARP entries\n",
-		device.IP, len(device.Interfaces), len(device.Neighbors), len(arpTable))
+	fmt.Printf("Device %s: %d interfaces, %d neighbors\n",
+		device.IP, len(device.Interfaces), len(device.Neighbors))
 
 	return nil
 }