Debug: 添加H3C接口输出调试日志
- 在解析器中输出display interface原始数据 - 便于诊断接口为空的问题
This commit is contained in:
@@ -32,6 +32,19 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
|
||||
|
||||
p.parseVersion(device, outputs[0])
|
||||
|
||||
// 调试:输出display interface的原始输出长度和前200个字符
|
||||
fmt.Printf("[H3C DEBUG] display interface output length: %d\n", len(outputs[1]))
|
||||
if len(outputs[1]) > 0 {
|
||||
if len(outputs[1]) > 200 {
|
||||
fmt.Printf("[H3C DEBUG] First 200 chars: %q\n", outputs[1][:200])
|
||||
} else {
|
||||
fmt.Printf("[H3C DEBUG] Full output: %q\n", outputs[1])
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("[H3C DEBUG] display interface output is EMPTY!\n")
|
||||
// 尝试重新执行命令获取原始数据(用于调试)
|
||||
}
|
||||
|
||||
// 检查命令输出是否为空
|
||||
if outputs[1] == "" {
|
||||
fmt.Printf("Warning: 'display interface' output is empty for device %s\n", device.IP)
|
||||
|
||||
+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