Fix: 增加SSH超时时间和详细日志

- 超时从10秒增加到30秒
- 添加每个命令执行的详细日志
- 便于诊断LLDP命令返回0字节的问题
This commit is contained in:
Your Name
2026-04-26 02:41:36 +08:00
parent c93d75b37d
commit c34b29d32c
+6 -3
View File
@@ -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)
}
}