Debug: 添加H3C接口输出调试日志
- 在解析器中输出display interface原始数据 - 便于诊断接口为空的问题
This commit is contained in:
+17
-8
@@ -193,44 +193,53 @@ func (c *Client) ExecuteCommand(command string) (string, error) {
|
||||
|
||||
output := stdoutBuf.String()
|
||||
|
||||
// 调试:输出原始输出长度和前100个字符
|
||||
fmt.Printf("[SSH DEBUG] Raw output length: %d, first 100 chars: %q\n", len(output), output[:min(len(output), 100)])
|
||||
|
||||
// 清理输出:移除命令回显和分页提示
|
||||
lines := strings.Split(output, "\n")
|
||||
var cleanLines []string
|
||||
skipNext := false
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
trimmedLine := strings.TrimSpace(line)
|
||||
|
||||
// 跳过空行
|
||||
if line == "" {
|
||||
if trimmedLine == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 跳过分页提示
|
||||
if strings.Contains(line, "---- More ----") {
|
||||
if strings.Contains(trimmedLine, "---- More ----") {
|
||||
continue
|
||||
}
|
||||
|
||||
// 跳过命令本身的回显
|
||||
if line == command || line == "screen-length disable" {
|
||||
// 跳过命令本身的回显(精确匹配)
|
||||
if trimmedLine == strings.TrimSpace(command) || trimmedLine == "screen-length disable" {
|
||||
skipNext = true
|
||||
fmt.Printf("[SSH DEBUG] Skipping command echo: %s\n", trimmedLine)
|
||||
continue
|
||||
}
|
||||
|
||||
// 跳过提示符行(如 <hostname> 或 [hostname])
|
||||
if regexp.MustCompile(`^[<\[]\S+[>\]]$`).MatchString(line) {
|
||||
if regexp.MustCompile(`^[<\[]\S+[>\]]$`).MatchString(trimmedLine) {
|
||||
fmt.Printf("[SSH DEBUG] Skipping prompt: %s\n", trimmedLine)
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果是 "screen-length disable" 后的第一行(通常是提示符),跳过
|
||||
if skipNext {
|
||||
skipNext = false
|
||||
fmt.Printf("[SSH DEBUG] Skipping line after command: %s\n", trimmedLine)
|
||||
continue
|
||||
}
|
||||
|
||||
cleanLines = append(cleanLines, line)
|
||||
cleanLines = append(cleanLines, trimmedLine)
|
||||
}
|
||||
|
||||
return strings.Join(cleanLines, "\n"), nil
|
||||
cleanOutput := strings.Join(cleanLines, "\n")
|
||||
fmt.Printf("[SSH DEBUG] Clean output length: %d, first 100 chars: %q\n", len(cleanOutput), cleanOutput[:min(len(cleanOutput), 100)])
|
||||
|
||||
return cleanOutput, nil
|
||||
}
|
||||
|
||||
// ExecuteCommands 执行多个命令
|
||||
|
||||
Reference in New Issue
Block a user