ntc-templates
ntc-templates copied to clipboard
cisco_nxos_show_interfaces_switchport adds additional space to monitor statement
ISSUE TYPE
- Template Issue with error and raw data
TEMPLATE USING
latest "cisco_nxos_show_interfaces_switchport "
SAMPLE COMMAND OUTPUT
nxos-sw1# show interface Eth1/36 switchport
Name: Ethernet1/36
Switchport: Enabled
Switchport Monitor: Enabled
Switchport Block Multicast: Not enabled
Switchport Block Unicast: Not enabled
Operational Mode: access
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Allowed: 1-4094
Administrative private-vlan primary host-association: none
Administrative private-vlan secondary host-association: none
Administrative private-vlan primary mapping: none
Administrative private-vlan secondary mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
nxos-sw1# show interface Po24 switchport
Name: port-channel24
Switchport: Enabled
Switchport Monitor: Not enabled
Switchport Block Multicast: Not enabled
Switchport Block Unicast: Not enabled
Operational Mode: trunk
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Allowed: 120,134,501,800,804
Administrative private-vlan primary host-association: none
Administrative private-vlan secondary host-association: none
Administrative private-vlan primary mapping: none
Administrative private-vlan secondary mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
nxos-sw1#
Iterating over the list of interfaces in python we get:
{'interface': 'Ethernet1/36', 'switchport': 'Enabled', 'switchport_monitor': 'Enabled ', 'mode': 'access', 'access_vlan': '1', 'access_vlan_name': 'default', 'native_vlan': '1', 'native_vlan_name': 'default', 'trunking_vlans': '1-4094', 'voice_vlan': ''}
{'interface': 'port-channel24', 'switchport': 'Enabled', 'switchport_monitor': 'Not enabled ', 'mode': 'trunk', 'access_vlan': '1', 'access_vlan_name': 'default', 'native_vlan': '1', 'native_vlan_name': 'default', 'trunking_vlans': '10-20', 'voice_vlan': ''}
SUMMARY
Of unknown reason, we get an additional space in the "switchport_monitor" string. Thus, having to match "Enabled " and not just Enabled for example.
FIX?
To fix this, I've corrected the template to only allow Enabled/Disabled on switchport statement and Enabled/Not enabled on the switchport_monitor statement.
Value Required INTERFACE (\S+)
Value SWITCHPORT (Enabled|Disabled)
Value SWITCHPORT_MONITOR (Enabled|Not\senabled)
Value MODE (access|trunk)
Works well.
Hello @Mattias3891
I'm a community member volunteering suggestions and possibly to submit a Pull Request (if needed and if you would like).
It's pretty wild how Cisco is adding trailing spaces all of a sudden -- to quite a few things in your example output.
What version of NXOS are you seeing this with?
Conditional Logic Suggestion I'm not saying this issue shouldn't be fixed (not my call), but this could be solved in your :snake: Python code by checking for your desired string in that returned string as opposed to modifying the template.
# use the TextFSM structured data instead of this example dictionary
parsed = {'switchport_monitor': 'this string should contain Enabled <space>'}
if 'Enabled' in parsed['switchport_monitor']:
print('contains Enabled, hooray!')
Reasoning If there's anything I've learned from working with regexes and talking to the NTC team, slightly "looser" regexes mean the templates should parse when vendors and situations tweak the output in minor ways.
If SWITCHPORT and MODE were changed to have specific string values, then if/when there was another value it would not be matched, breaking the template.
https://github.com/networktocode/ntc-templates/blob/master/ntc_templates/templates/cisco_nxos_show_interfaces_switchport.textfsm
@Mattias3891 Making the regexes for the capture group more rigid is a double edged sword based on experience.
Currently:
Value SWITCHPORT_MONITOR (.+)
My suggestion:
Value SWITCHPORT_MONITOR (\S+(?:\s+\S+)?)
I'm working up a fix with my suggestion as it meets your needs and should be flexible enough that it will be less likely to break in the future.
---
parsed_sample:
- access_vlan: "1"
access_vlan_name: "default"
interface: "Ethernet1/36"
mode: "access"
native_vlan: "1"
native_vlan_name: "default"
switchport: "Enabled"
switchport_monitor: "Enabled"
trunking_vlans: "1-4094"
voice_vlan: ""
- access_vlan: "1"
access_vlan_name: "default"
interface: "port-channel24"
mode: "trunk"
native_vlan: "1"
native_vlan_name: "default"
switchport: "Enabled"
switchport_monitor: "Not enabled"
trunking_vlans: "120,134,501,800,804"
voice_vlan: ""
PR #1622 has been submitted for consideration
This has been merged. Can we close this issue?
@ryanmerolle Since #1622 has been merged I'd say yes - let's close this issue ticket.
I don't know why the issues weren't auto-resolving. I'll have to ping Josh to see if there's something contributors can do to link their PRs to issues so they do auto-close.
@jvanderaa would you please close this ticket.