Fix: 添加详细调试日志诊断拓扑连线问题
- 在拓扑构建时输出每个设备的邻居详情 - 显示邻居的RemoteIP、RemoteDevice、接口信息 - 从数据库加载设备后重建拓扑确保连线正确 - 帮助诊断为什么邻居无法自动连线
This commit is contained in:
@@ -265,6 +265,13 @@ func (app *App) handleGetDevices(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Printf("Error: failed to get devices from database: %v", err)
|
log.Printf("Error: failed to get devices from database: %v", err)
|
||||||
// 降级到 builder获取
|
// 降级到 builder获取
|
||||||
devices = app.builder.GetDevices()
|
devices = app.builder.GetDevices()
|
||||||
|
} else {
|
||||||
|
// 重新构建设备到builder中,确保拓扑正确
|
||||||
|
app.builder = topology.NewBuilder()
|
||||||
|
for _, dev := range devices {
|
||||||
|
app.builder.AddDevice(dev)
|
||||||
|
}
|
||||||
|
log.Printf("Rebuilt topology with %d devices from database", len(devices))
|
||||||
}
|
}
|
||||||
log.Printf("Returning %d devices from storage", len(devices))
|
log.Printf("Returning %d devices from storage", len(devices))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ func (b *Builder) Build() models.TopologyGraph {
|
|||||||
}
|
}
|
||||||
nodeMap[device.IP] = node
|
nodeMap[device.IP] = node
|
||||||
graph.Nodes = append(graph.Nodes, node)
|
graph.Nodes = append(graph.Nodes, node)
|
||||||
|
|
||||||
|
// 调试信息
|
||||||
|
fmt.Printf("Node added: %s (%s) with %d neighbors\n",
|
||||||
|
device.IP, device.Type, len(device.Neighbors))
|
||||||
|
for i, neighbor := range device.Neighbors {
|
||||||
|
fmt.Printf(" Neighbor %d: RemoteIP=%s, RemoteDevice=%s, LocalIf=%s, RemoteIf=%s\n",
|
||||||
|
i+1, neighbor.RemoteIP, neighbor.RemoteDevice,
|
||||||
|
neighbor.LocalInterface, neighbor.RemoteInterface)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建边(基于邻居信息)
|
// 构建边(基于邻居信息)
|
||||||
|
|||||||
Reference in New Issue
Block a user