networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.11k stars 723 forks source link

cisco ios show lldp neighbours details textfsm.parser.TextFSMError: State Error raised. Rule Line: 55. Input Line: Power via MDI: #919

Closed RP-11 closed 3 months ago

RP-11 commented 3 years ago
ISSUE TYPE
TEMPLATE USING
Value LOCAL_INTERFACE (\S+)
Value CHASSIS_ID (\S+)
Value NEIGHBOR_PORT_ID (.*)
Value NEIGHBOR_INTERFACE (.*)
Value NEIGHBOR (.+?)
Value SYSTEM_DESCRIPTION (.*)
Value CAPABILITIES (.*)
Value MANAGEMENT_IP (\S+)
Value VLAN (\d+)
Value SERIAL (\S+)

Start
  ^.*not advertised
  ^.*Invalid input detected -> EOF
  ^.*LLDP is not enabled -> EOF
  ^Local\s+Intf:\s+${LOCAL_INTERFACE}\s*$$
  ^Chassis\s+id:\s+${CHASSIS_ID}\s*$$
  ^Port\s+id:\s+${NEIGHBOR_PORT_ID}\s*$$
  ^Port\s+Description:\s+${NEIGHBOR_INTERFACE}\s*$$
  ^System\s+Name(\s+-\s+not\s+advertised)\s*$$
  ^System\s+Name:?\s*$$
  ^System\s+Name(:\s+${NEIGHBOR})\s*$$
  ^System\s+Description -> GetDescription
  ^Time
  ^System\s+Capabilities
  ^Enabled\s+Capabilities:\s+${CAPABILITIES}\s*$$
  ^Management\s+Addresses
  ^\s+OID
  ^\s+[\d+\.]{8,}
  ^.*IP:\s+${MANAGEMENT_IP}
  ^Auto\s+Negotiation
  ^Physical\s+media
  # Removed \(\s+\) from the template - The line 'Other/unknown' would not be captured
  # Now looks for any text beginning with any space
  ^\s+.+\s*$$
  ^Media\s+Attachment
  ^\s+Inventory
  ^\s+Capabilities
  ^\s+Device\s+type
  ^\s+Network\s+Policies
  ^\s+Power\s+requirements
  ^\s+Location
  ^Time\s+remaining
  ^Vlan\s+ID:\s+(?:${VLAN}|-\s+not\s+advertised)\s*$$
  ^\s+\(\S+\)
  ^(?:PoE|\s+Power)
  ^\s*-+\s*$$ -> Record
  ^MED -> Med
  ^\s*\^\s*
  ^\s*Total\s+entries\s+displayed -> Record
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^.*$$ -> Error

GetDescription
  ^${SYSTEM_DESCRIPTION} -> IgnoreDescription

IgnoreDescription
  ^Time\s+remaining -> Start
  ^\S*
  ^\s*$$
  ^.* -> Error

Med
  ^\s+Serial\s+number:\s+${SERIAL}
  ^\s+\S+
  ^\s*$$
  ^\s*Total\s+entries\s+displayed -> Record
  ^\s*-+\s*$$ -> Continue.Record
  ^\s*-+\s*$$ -> Start
  ^.* -> Error
SAMPLE COMMAND OUTPUT
SW-2960-1#show lldp neighbors detail 
------------------------------------------------
Chassis id: 00ca.e537.af00
Port id: Gi1/0/26
Port Description: LINK TO SWxxx-2960-1 Gig 1/0/49
System Name: SWxxxx-2960-1.dd.gst

System Description: 
Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(2)E3, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2015 by Cisco Systems, Inc.
Compiled Wed 26-Aug-15 07:12 by prod_rel_team

Time remaining: 91 seconds
System Capabilities: B,R
Enabled Capabilities: B
Management Addresses:
    IP: 11.22.33.44
Auto Negotiation - not supported
Physical media capabilities:
    1000baseX(FD)
Media Attachment Unit type: 24
Vlan ID: 1

------------------------------------------------
Chassis id: 90ac.3f07.aa34
Port id: 90ac.3f07.aa34
Port Description: eth0
System Name: xxxxxxx-X8N5C4004005

System Description: 
BrightSign DMP-2K REVN 8.0.127 X8N5C4004005

Time remaining: 90 seconds
System Capabilities: S
Enabled Capabilities: S
Management Addresses:
    IP: 10.89.12.52
    IPV6: FE80::92AC:3FFF:FE07:AA34
Auto Negotiation - supported, enabled
Physical media capabilities:
    1000baseT(FD)
    1000baseT(HD)
    100base-TX(FD)
    100base-TX(HD)
    10base-T(FD)
    10base-T(HD)
Media Attachment Unit type: 30
Vlan ID: - not advertised
Power via MDI:
    Power Pair: Spare
    Power Class: 4
    Power Device Type: 2
    Power Source: Unknown
    Power Priority: Unknown
    Power Requested: 25000 mW

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    S/W revision: 4.1.51-1.18+bs8.0.127
    Capabilities: NP, LI, PS, PD, IN
    Device type: Endpoint Class II
    Network Policies - not advertised
    PD device, Power source: Unknown, Power Priority: Unknown, Wattage: 25.0
    Location - not advertised

------------------------------------------------
SUMMARY

parser is braking on line "Power via MDI" and giving this error. textfsm.parser.TextFSMError: State Error raised. Rule Line: 55. Input Line: Power via MDI:

NOTE. I added another line above: ^(?:PoE|\s+Power)

And now it is not showing the error ^Power\s+via ^(?:PoE|\s+Power)

STEPS TO REPRODUCE

run it on any switch that has "Power via MDI" in the output

EXPECTED RESULTS
ACTUAL RESULTS

textfsm.parser.TextFSMError: State Error raised. Rule Line: 55. Input Line: Power via MDI:

Traceback (most recent call last):
  File "netdiscovery1.7c.py", line 1258, in main
    results = fsm.ParseText(output)
  File "C:\Users\lstonesif1\Desktop\netdiscover\python\App\Python\lib\site-packages\textfsm\parser.py", line 895, in ParseText
    self._CheckLine(line)
  File "C:\Users\lstonesif1\Desktop\netdiscover\python\App\Python\lib\site-packages\textfsm\parser.py", line 944, in _CheckLine
    if self._Operations(rule, line):
  File "C:\Users\lstonesif1\Desktop\netdiscover\python\App\Python\lib\site-packages\textfsm\parser.py", line 1024, in _Operations
    raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 55. Input Line: Power via MDI:
itdependsnetworks commented 3 years ago

I think adding ^Power\s+via\s+\S+: similar to what you have done is the way to address. You will need to create a new test case for this as well if you want to put in a PR to fix the issue.

RP-11 commented 3 years ago

Thx. I will try this out. It may take a bit until I can test it.

mjbear commented 3 months ago

@RP-11 This should have been resolved by PR #919

Could you please test and report back so we know you're all set? Thank you!