networktocode / ntc-templates

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

some Cisco IP Phone 6901 not supported by template cisco_ios_show_lldp_neighbors_detail.textfsm #1884

Open mcn29 opened 11 hours ago

mcn29 commented 11 hours ago

my quick fix in cisco_ios_show_lldp_neighbors_detail.textfsm :

line 29

^Chassis\s+id:\s+${CHASSIS_ID}\s*$$

changed into :

^Chassis\s+id:\s+(${CHASSIS_ID}\s*$$|::)

ISSUE TYPE
TEMPLATE USING

Value LOCAL_INTERFACE (\S+) Value CHASSIS_ID ([^:]+) Value NEIGHBOR_PORT_ID (.) Value NEIGHBOR_INTERFACE (.) Value NEIGHBOR_NAME (.+?) Value NEIGHBOR_DESCRIPTION (.) Value CAPABILITIES (.) Value MGMT_ADDRESS (\S+) Value VLAN_ID (\d+) Value MAC_ADDRESS ([0-9a-fA-F]{4}.[0-9a-fA-F]{4}.[0-9a-fA-F]{4}) Value SERIAL (\S+) Value MANUFACTURER (.) Value HW_REVISION (\S+) Value FW_REVISION (\S+) Value SW_REVISION (\S+) Value PLATFORM (.) Value POWER_PAIR (\S+) Value POWER_CLASS (\d+) Value POWER_DEVICE_TYPE (\S+) Value POWER_PRIORITY (\S+) Value POWER_SOURCE (\S+) Value POWER_REQUESTED (\d+)

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_NAME})\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+${MGMT_ADDRESS}\s*$$ ^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_ID}|-\s+not\s+advertised)\s$$ ^Peer\s+Source\s+MAC:\s+${MAC_ADDRESS} ^\s+(\S+) ^(?:PoE|\s+Power) ^\s-+\s$$ -> Record ^Power\s+via\s+MDI -> PowerMDI ^MED -> Med ^\s\^\s ^\sTotal\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 ^${NEIGHBOR_DESCRIPTION} -> IgnoreDescription

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

PowerMDI ^\s+Power\s+Pair:\s+${POWER_PAIR}\s$$ ^\s+Power\s+Class:\s+${POWER_CLASS}\s$$ ^\s+Power\s+Device\s+Type:\s+${POWER_DEVICE_TYPE}\s$$ ^\s+Power\s+Source:\s+${POWER_SOURCE}\s$$ ^\s+Power\s+Priority:\s+${POWER_PRIORITY}\s$$ ^\s+Power\s+Requested:\s+${POWER_REQUESTED}\s+mW\s$$ ^\s*$$ -> Start

Med ^\s+Serial\s+number:\s+${SERIAL}\s$$ ^\s+Manufacturer:\s+${MANUFACTURER}\s$$ ^\s+Model:\s+${PLATFORM}\s$$ ^\s+H/W revision:\s+${HW_REVISION}\s$$ ^\s+F/W revision:\s+${FW_REVISION}\s$$ ^\s+S/W revision:\s+${SW_REVISION}\s$$ ^\s+\S+ ^\s$$ ^\sTotal\s+entries\s+displayed -> Record ^\s-+\s$$ -> Continue.Record ^\s-+\s$$ -> Start ^.* -> Error

SAMPLE COMMAND OUTPUT

sh lldp nei det

Local Intf: Gi1/0/22 Chassis id: :: Port id: aabbccddeeff:P1 Port Description: SW PORT System Name: SEPaabbccddeeff.phones.mycompany.domain

System Description: Cisco IP Phone 6901,SCCP6901.9-3-1-SR2-2

Time remaining: 108 seconds System Capabilities: T Enabled Capabilities: T Management Addresses: IP: 10.20.30.40 IPV6: :: Auto Negotiation - supported, enabled Physical media capabilities: 100base-TX(FD) 100base-TX(HD) 10base-T(FD) 10base-T(HD) Media Attachment Unit type: 16 Vlan ID: 999 Peer Source MAC: abcd.1234.efef

MED Information:

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

H/W revision: 1.0
F/W revision: 6901.0-0-0-01-05
S/W revision: SCCP6901.9-3-1-SR2-2
Serial number: FCH26192GVM
Manufacturer: Cisco Systems, Inc.
Model: CP-6901
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN data, untagged, Layer-2 priority: 5, DSCP: 46
Network Policy(Voice Signal): VLAN data, untagged, Layer-2 priority: 3, DSCP: 46
PD device, Power source: Unknown, Power Priority: Unknown, Wattage: 2.6
Location - not advertised
SUMMARY

exception when using netmiko send_command('show lldp neighbors detail',use_textfsm="True") on a cisco IOS switch (C9200L-48P-4X 17.09.05 CAT9K_LITE_IOSXE)

STEPS TO REPRODUCE

Use the raw output of the command as typed on the switch

EXPECTED RESULTS

{'local_interface': 'Gi1/0/22', 'chassis_id': '', 'neighbor_port_id': 'aabbccddeeff:P1', 'neighbor_interface': 'SW PORT', 'neighbor_name': 'SEPaabbccddeeff.phones.company.domain', 'neighbor_description': 'Cisco IP Phone 6901,SCCP6901.9-3-1-SR2-2', 'capabilities': 'T', 'mgmt_address': '10.20.30.40', 'vlan_id': '999', 'mac_address': 'abcd.1234.efef', 'serial': 'FCH26192GVM', 'manufacturer': 'Cisco Systems, Inc.', 'hw_revision': '1.0', 'fw_revision': '6901.0-0-0-01-05', 'sw_revision': 'SCCP6901.9-3-1-SR2-2', 'platform': 'CP-6901', 'power_pair': '', 'power_class': '', 'power_device_type': '', 'power_priority': '', 'power_source': '', 'power_requested': ''}

ACTUAL RESULTS
            lldp_nei = net_conn_acc.send_command('show lldp neighbors detail',use_textfsm="True")

Traceback (most recent call last): File "C:\Users\A0007473-R\Documents\automatisation\scripts\audit_lan_user_switches_v0.45.py", line 3960, in audit_usr_stack lldp_nei = net_conn_acc.send_command('show lldp neighbors detail',use_textfsm="True") File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\base_connection.py", line 111, in wrapper_decorator return_val = func(self, *args, *kwargs) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\utilities.py", line 596, in wrapper_decorator return func(self, args, **kwargs) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\base_connection.py", line 1834, in send_command return_val = structured_data_converter( File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\utilities.py", line 560, in structured_data_converter structured_output_tfsm = get_structured_data_textfsm( File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\utilities.py", line 380, in get_structured_data_textfsm output = _textfsm_parse(textfsm_obj, raw_output, attrs) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\netmiko\utilities.py", line 344, in _textfsm_parse tfsm_parse(raw_output, attrs) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\textfsm\clitable.py", line 282, in ParseCmd self.table = self._ParseCmdItem(self.raw, template_file=template_files[0]) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\textfsm\clitable.py", line 315, in _ParseCmdItem for record in fsm.ParseText(cmd_input): File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\textfsm\parser.py", line 895, in ParseText self._CheckLine(line) File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\site-packages\textfsm\parser.py", line 944, in _CheckLine if self._Operations(rule, line): File "C:\Users\A0007473-R\AppData\Roaming\Python\Python39\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: 69. Input Line: Chassis id: ::

jmcgill298 commented 9 hours ago

@mcn29 can you put in a PR to fix this?

mcn29 commented 9 hours ago

@jmcgill298 assuming a PR means a pull request, I'll give it a try, it will take me some time as I'm a network admin, coding is new for me :-[

jvanderaa commented 3 hours ago

Nothing better than working on these templates as a way to get started (personal opinion here). Thank you for opening the issue and working on it. Let us know if we can help @mcn29