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

cisco_ios_show_interfaces_description.textfsm fails to parse #866

Closed
sakabio opened this issue Feb 25, 2021 · 6 comments
Closed

cisco_ios_show_interfaces_description.textfsm fails to parse #866

sakabio opened this issue Feb 25, 2021 · 6 comments

Comments

@sakabio
Copy link

sakabio commented Feb 25, 2021

ISSUE TYPE
  • Bug Report
TEMPLATE USING
Value PORT (\S+)
Value STATUS (up|down|deleted|admin\s+down)
Value PROTOCOL (up|down)
Value DESCRIP (\S.*?)

Start
  ^Interface\s+Status\s+Protocol\s+Description\s*$$ -> Begin
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^. -> Error

Begin
  ^${PORT}\s+${STATUS}\s+${PROTOCOL}(?:\s+${DESCRIP})?\s*$$ -> Record
  ^\s*$$
  ^. -> Error
SAMPLE COMMAND OUTPUT
Interface                      Status         Protocol Description
Gi1/0/6                        down           down     SWP | VLAN 21 | NODOT1X
Gi1/0/7                        down           down     SWP | VLAN 21 | NODOT1X
Gi1/0/8                        down           down     SWP | VLAN 21 | NODOT1X
SUMMARY

Parser does not work when the data is passed to it.

textfsm.parser.TextFSMError: State Error raised. Rule Line: 12. Input Line: show interfaces description

show_int_desc_parsed = parse_output(platform="cisco_ios", command="show interfaces description", data=show_int_desc)

STEPS TO REPRODUCE

Connect to cisco device using Netmiko and run the command "show interfaces description" and pass the output into parse_output

EXPECTED RESULTS

Using textfsm=True should return a JSON data structure

ACTUAL RESULTS
raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 12. Input Line: show interfaces description
@sakabio
Copy link
Author

sakabio commented Feb 26, 2021

@itdependsnetworks @jmcgill298 can you please help

@FragmentedPacket
Copy link
Contributor

It appears the command is in the output you're providing the parse_output command. What does your merino code look like for this call?

@sakabio
Copy link
Author

sakabio commented Feb 26, 2021

from netmiko import Netmiko
from textfsm import TextFSM
from ntc_templates.parse import parse_output
import getpass

net_connect = Netmiko(host='x.x.x.x', username='username', password=password, device_type='cisco_ios')

show_int_desc = net_connect.send_command_timing("show interfaces description", strip_command=False, strip_prompt=False)

show_int_desc_parsed = parse_output(platform="cisco_ios", command="show interfaces description", data=show_int_desc)

print(show_int_desc_parsed)

@diepes
Copy link
Contributor

diepes commented Feb 26, 2021

@sakabio, to better debug add print(show_int_desc) before parse_output

my guess is that the command is included in show_int_desc e.g. "show interface description" and this is tripping up textfsm.

@FragmentedPacket
Copy link
Contributor

You either want to strip command and strip prompt to true or remove them from the output prior via regex or string manipulation

@sakabio
Copy link
Author

sakabio commented Feb 26, 2021

@FragmentedPacket thanks this worked like a charm.

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

3 participants