From c34b29d32caf2a851e483b56768c42c5e17809f3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 26 Apr 2026 02:41:36 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E5=A2=9E=E5=8A=A0SSH=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=92=8C=E8=AF=A6=E7=BB=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 超时从10秒增加到30秒 - 添加每个命令执行的详细日志 - 便于诊断LLDP命令返回0字节的问题 --- internal/device/parser.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/device/parser.go b/internal/device/parser.go index 5790414..ced7432 100644 --- a/internal/device/parser.go +++ b/internal/device/parser.go @@ -35,11 +35,12 @@ func DiscoverDevice(ip string, deviceType models.DeviceType, username, password Type: deviceType, } - // 创建SSH客户端 - 默认启用不安全加密算法以兼容老旧设备 + // 创建SSH客户端 - 默认启用不安全加密算法以兼容老旧设备,增加超时时间 client := sshclient.NewClient(sshclient.Config{ Host: ip, Username: username, Password: password, + Timeout: 30 * time.Second, // 增加到30秒,防止大输出超时 InsecureCiphers: true, // 启用旧版加密算法支持 }) @@ -75,15 +76,17 @@ func DiscoverDevice(ip string, deviceType models.DeviceType, username, password // 获取命令列表 commands := parser.GetCommands() - // 执行命令 - 允许部分命令失败 + // 执行命令 - 允许部分命令失败,增加详细日志 outputs := make([]string, 0, len(commands)) - for _, cmd := range commands { + for i, cmd := range commands { + fmt.Printf("[PARSER] Executing command %d/%d: %s\n", i+1, len(commands), cmd) output, err := client.ExecuteCommand(cmd) if err != nil { // 记录警告但继续执行其他命令 fmt.Printf("Warning: command '%s' failed: %v\n", cmd, err) outputs = append(outputs, "") } else { + fmt.Printf("[PARSER] Command '%s' returned %d bytes\n", cmd, len(output)) outputs = append(outputs, output) } }