Fix: 增强SSH会话管理和错误处理
- 添加会话创建重试机制(最多3次) - 允许部分命令失败而不中断整个扫描 - 改进错误提示和日志输出 - 解决H3C设备LLDP命令会话拒绝问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package device
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"network-topology-discovery/pkg/models"
|
||||
sshclient "network-topology-discovery/internal/ssh"
|
||||
)
|
||||
@@ -74,12 +75,17 @@ func DiscoverDevice(ip string, deviceType models.DeviceType, username, password
|
||||
// 获取命令列表
|
||||
commands := parser.GetCommands()
|
||||
|
||||
// 执行命令
|
||||
outputs, err := client.ExecuteCommands(commands)
|
||||
if err != nil {
|
||||
device.ScanStatus = "failed"
|
||||
device.ErrorMessage = err.Error()
|
||||
return device, err
|
||||
// 执行命令 - 允许部分命令失败
|
||||
outputs := make([]string, 0, len(commands))
|
||||
for _, cmd := range commands {
|
||||
output, err := client.ExecuteCommand(cmd)
|
||||
if err != nil {
|
||||
// 记录警告但继续执行其他命令
|
||||
fmt.Printf("Warning: command '%s' failed: %v\n", cmd, err)
|
||||
outputs = append(outputs, "")
|
||||
} else {
|
||||
outputs = append(outputs, output)
|
||||
}
|
||||
}
|
||||
|
||||
// 解析输出
|
||||
|
||||
Reference in New Issue
Block a user