Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANSI escape code not stripped from Aruba 2530 series switches #331

Closed
AlexLardschneider opened this issue May 24, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@AlexLardschneider
Copy link

Describe the bug
Trying to add a community driver for Aruba (former HP) 2530 series switches (https://www.hpe.com/psnow/doc/c04111414), but I'm encountering issues with some ANSI escape codes not being stripped from the channel input, and thus pattern matching failing (authentication successful check, prompt detection, etc.).

For some reason, it seems like the switch outputs a lot of escape sequences, for example immediately after login succeeds:

read: b'\x1b[?6l\x1b[1;80r\x1b[?7h\x1b[2J\x1b[1;1H\x1b[1920;1920H\x1b[6n\x1b[1;1HYour previous successful login (as manager) was on 2024-05-24 11:29:02     \n from X.X.X.X\n\x1b[1;80r\x1b[80;1H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[80;1HHOSTNAME# \x1b[80;1H\x1b[80;20H\x1b[80;1H\x1b[?25h\x1b[80;20H\x1b[1;0H\x1b[1M\x1b[80;1H\x1b[1L\x1b[80;20H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[1;80r\x1b[80;1H\x1b[1;80r\x1b[80;1H\x1b[80;1H\x1b[2K\x1b[80;1H\x1b[?25h\x1b[80;1H\x1b[80;1HHOSTNAME# \x1b[80;1H\x1b[80;20H\x1b[80;1H\x1b[?25h\x1b[80;20H'

Even after BaseChannel._strip_ansi() is being called internally by scrapli, I'm still left with a few escape sequences in the output:

b'\x1b[1;80rYour previous successful login (as manager) was on 2024-05-24 11:29:02     \n from X.X.X.X\n\x1b[1;80rHOSTNAME# \x1b[1;80r\x1b[1;80rHOSTNAME# '

I assume that base_channel.ANSI_ESCAPE_PATTERN is missing patterns for these escape codes, however I can't exactly figure out what these codes do. Maybe someone can chime in on this.

I tried manually altering the regex pattern being used internally by scrapli and replacing it with one of the answers mentioned in this Stack Overflow thread, and it seems like all escape sequences get stripped (and I am left with a clean output which matches my regex patterns for prompt matching):

ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
result = ansi_escape.sub('', sometext)

To Reproduce
Steps to reproduce the behavior:

  1. Your script
    Can't really provide a sample script yet, since I'm still trying to piece the community driver together (and currently failing to make it work due to this issue). However, it is based on GenericDriver.

  2. What you're connecting to (vendor, platform, version)
    Aruba (HP/HPE) ProCurve 2530-24G switches, running OS version YA.16.10.0009.

  3. Anything else relevant
    -


Expected behavior
After calling BaseChannel._strip_ansi(), the output should probably be similar to this:

Your previous successful login (as manager) was on 2024-05-24 11:29:02     \n from X.X.X.X\nHOSTNAME# HOSTNAME# 

Stack Trace
-


Screenshots
-

OS (please complete the following information):

  • OS: Docker container based on python:3.11.
  • scrapli version: scrapli==2024.1.30 & scrapli-community==2024.1.30

Additional context
-

@AlexLardschneider AlexLardschneider added the bug Something isn't working label May 24, 2024
@carlmontanari
Copy link
Owner

ahah ansi stuff is really the gift that keeps on giving 🤣

our ol friend chat gpt seems to be handy for helping out with this at least! just made #332 to handle this. try it out and let us know if thats cool? I added a quick test case for it so I think it should be but just want to confirm there aren't other fun ones floating around in there!

@AlexLardschneider
Copy link
Author

It really is ☹️
But it looks like ChatGPT is right, and all escape codes are now stripped (at least on my HPE/Aruba switches).

Thanks for taking a look at this, Carl!

@carlmontanari
Copy link
Owner

boom! great thanks for confirming! will get that merged 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants