Fix: 使用display interface brief替代ip interface brief
- 交换机使用VLAN互联,应该使用display interface brief - 移除ARP表依赖,直接使用LLDP邻居信息 - 简化命令列表从6个减少到5个
This commit is contained in:
@@ -19,20 +19,18 @@ func (p *H3CParser) GetCommands() []string {
|
|||||||
"screen-length disable", // 禁用分页(H3C/华为设备必需)
|
"screen-length disable", // 禁用分页(H3C/华为设备必需)
|
||||||
"display version",
|
"display version",
|
||||||
"display interface",
|
"display interface",
|
||||||
"display ip interface brief",
|
"display interface brief", // 接口简要信息(包含VLAN和物理接口状态)
|
||||||
"display lldp neighbor-information",
|
"display lldp neighbor-information",
|
||||||
"display arp", // ARP表用于MAC到IP的映射
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse 解析H3C设备输出
|
// Parse 解析H3C设备输出
|
||||||
func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
|
func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
|
||||||
if len(outputs) < 6 {
|
if len(outputs) < 5 {
|
||||||
return fmt.Errorf("insufficient command outputs")
|
return fmt.Errorf("insufficient command outputs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// outputs[0] 是 screen-length disable 的输出(通常为空)
|
// 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
|
p.parseVersion(device, outputs[1]) // outputs[1] 是 display version
|
||||||
|
|
||||||
// outputs[2] 是 display interface
|
// outputs[2] 是 display interface
|
||||||
@@ -51,7 +49,8 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
|
|||||||
if outputs[2] == "" {
|
if outputs[2] == "" {
|
||||||
fmt.Printf("Warning: 'display interface' output is empty for device %s\n", device.IP)
|
fmt.Printf("Warning: 'display interface' output is empty for device %s\n", device.IP)
|
||||||
} else {
|
} 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 {
|
if len(device.Interfaces) == 0 {
|
||||||
fmt.Printf("Warning: parsed 0 interfaces for device %s (output length: %d)\n",
|
fmt.Printf("Warning: parsed 0 interfaces for device %s (output length: %d)\n",
|
||||||
device.IP, len(outputs[2]))
|
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[4] 是 display lldp neighbor-information
|
||||||
// outputs[5] 是 display arp
|
|
||||||
|
|
||||||
// 解析ARP表用于MAC到IP映射(允许失败)
|
// 解析LLDP邻居
|
||||||
arpTable := make(map[string]string)
|
device.Neighbors = p.parseNeighbors(outputs[4], nil)
|
||||||
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的映射
|
fmt.Printf("Device %s: %d interfaces, %d neighbors\n",
|
||||||
device.Neighbors = p.parseNeighbors(outputs[4], arpTable)
|
device.IP, len(device.Interfaces), len(device.Neighbors))
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user