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

Regex for prompt parsing causing inconsistent results #317

Open
khardsonhurley opened this issue Jul 13, 2018 · 1 comment
Open

Regex for prompt parsing causing inconsistent results #317

khardsonhurley opened this issue Jul 13, 2018 · 1 comment

Comments

@khardsonhurley
Copy link

khardsonhurley commented Jul 13, 2018

tl;dr: Regex for prompt parsing of output searches for > as end of the prompt. This causes an issue with command outputs that include >, which causes trigger to think that this is a break for new output.

Consider the output below:
khardson@hostname> show bgp neighbor 1.1.1.1 | match Flags Type: External State: Established Flags: <Sync RSync>

Here is the results that trigger got when running this command:
INFO:twisted:Got results: [' Type: External State: Established Flags: <Sync ', '{master}\r\n']

Notice that RSync> is not in the result, and that there are 2 results for one command.

The logs shows that trigger thinks that RSync> is the prompt, causing it to think there is a non-existent second command's output after the RSync>.

Below are the full logs:

INFO:twisted:[hostname] BYTES: '\r\n'
INFO:twisted:[hostname] BYTES: '  Type: External    State: Established    Flags: <Sync RSync>\r\n'
INFO:twisted:[hostname] STATE: buffer '\rkhardson@hostname> ...\x08\x08\x08\x08\rkhardson@hostmane> ...\x08\x08\x08\x08\rkhardson@hostname> [TRUNCATED]......\x08\x08\x08\x08\r\n  Type: External    State: Established    Flags: <Sync RSync>\r\n'
INFO:twisted:[hostname] STATE: prompt 'RSync>\r'
INFO:twisted:[hostname] STATE: result '  Type: External    State: Established    Flags: <Sync '
INFO:twisted:[hostname] BYTES: '\r\n'
INFO:twisted:[hostname] BYTES: '{master}\r\nkhardson@hostname> '
INFO:twisted:[hostname] STATE: buffer '\r\n{master}\r\nkhardson@hostname> '
INFO:twisted:[hostname] STATE: prompt 'khardson@hostname> '
INFO:twisted:[hostname] STATE: result '{master}\r\n'
INFO:twisted:[hostname] CHANNEL: out of commands, closing connection...
INFO:twisted:[hostname] Forcefully closing transport connection
INFO:twisted:Got disconnect request, reason: 10, desc: 'user closed connection'
INFO:twisted:Disconnecting with error, code 10
reason: user closed connection
INFO:twisted:[hostname] CHANNEL: out of commands, closing connection...
INFO:twisted:[hostname] Forcefully closing transport connection
INFO:twisted:Got disconnect request, reason: 10, desc: 'user closed connection'
> /home/khardson/tmp/timedog/neteng/timedog/plugins/peer_manager/configure.py(801)parse_template()
INFO:twisted:Disconnecting with error, code 10
reason: user closed connection
INFO:twisted:Forcefully closing transport connection!
(Pdb) INFO:twisted:Got disconnect request, reason: 10, desc: 'user closed connection'
INFO:twisted:Disconnecting with error, code 10
reason: user closed connection
INFO:twisted:connection lost
INFO:twisted:Transport connection lost: Connection was closed cleanly.
INFO:twisted:Client connection lost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
]
INFO:twisted:Got results: ['  Type: External    State: Established    Flags: <Sync ', '{master}\r\n']```

@tcuthbert
Copy link
Contributor

tcuthbert commented Jul 13, 2018

So what I think needs to be done here is the default IOS regex prompt pattern (see conf/global_settings.py) needs to use a negative look ahead pattern with the hostname as a capture group. This may not be available in all the Python versions Trigger supports.

A work around for now could be to just setup your own custom prompt patterns for IOS devices to ignore that particular string.

https://www.regular-expressions.info/refcapture.html
https://stackoverflow.com/questions/32862316/negative-lookahead-with-capturing-groups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants