Feat: 添加详细的MAC地址解析调试日志

- 输出邻居MAC解析详情
- 输出每个接口的MAC地址状态
- 输出收集的MAC地址总数
- 帮助诊断为什么MAC地址为空
This commit is contained in:
Your Name
2026-04-26 01:20:00 +08:00
parent c28c6ad128
commit 096e752459
+8
View File
@@ -47,11 +47,14 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
for _, iface := range device.Interfaces {
if iface.MAC != "" {
macSet[iface.MAC] = true
} else {
fmt.Printf(" Interface %s has no MAC address\n", iface.Name)
}
}
for mac := range macSet {
device.MACAddresses = append(device.MACAddresses, mac)
}
fmt.Printf(" Collected %d unique MAC addresses for device %s\n", len(macSet), device.IP)
}
// 解析ARP表用于MAC到IP映射(允许失败)
@@ -289,6 +292,7 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) []
mac := strings.TrimSpace(strings.ToLower(macParts[0]))
// 保存MAC地址
currentNeighbor.RemoteMAC = mac
fmt.Printf(" Parsed neighbor MAC: %s (from line: %s)\n", mac, line)
// 通过ARP表查找IP(如果有)
if ip, ok := arpTable[mac]; ok {
@@ -298,7 +302,11 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) []
// 如果ARP表中没有,使用MAC地址作为标识(但RemoteIP仍为空)
currentNeighbor.RemoteDevice = mac
}
} else {
fmt.Printf(" WARNING: Could not parse MAC from ChassisID line: %s\n", line)
}
} else {
fmt.Printf(" WARNING: ChassisID line has no colon: %s\n", line)
}
}