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 vlans` sometimes return empty under packets #1827

Closed gertzakis closed 2 months ago

gertzakis commented 2 months ago
ISSUE TYPE
TEMPLATE USING
Value Required VLAN_ID (\d+)
Value List INTERFACES ([\w\./-]+)
Value List IP_ADDRESSES (\S+)
Value List IPV6_ADDRESSES (\S+)

Start
  ^VLAN\s+ID:\s+${VLAN_ID} -> Data
  ^Virtual\s+LAN\s+ID\:\s+${VLAN_ID} -> Data
  ^No\s+Virtual\s+LANs\s+configured
  ^\s*$$
  ^. -> Error

Data
  ^Virtual\s+LAN\s+ID\:\s+\d.* -> Continue.Record
  ^Virtual\s+LAN\s+ID\:\s+${VLAN_ID}.*
  ^VLAN\s+ID:\s+\d+ -> Continue.Record
  ^VLAN\s+ID:\s+${VLAN_ID}
  ^\s+This\s+is\s+configured\s+as\s+native\s+Vlan\s+for\s+the\s+following\s+interface\(s\)\s+:\s*$$
  ^\S+(\s+Native-vlan\s+Tx-type:\s+\S+)?\s*$$
  ^\s+Protocols\s+Configured
  ^\s+IP\s+\d+\s+\d+
  ^\s+MPLS\s+\d+\s+\d+
  ^\s+MPLS\:\s+\S+
  ^\s+[vV]LAN\s+Trunk\s+Interfaces?\:\s+${INTERFACES} -> Interface
  ^VLAN\s+trunk\s+interfaces -> Interface
  ^[\w\./]+\s*$$
  ^${INTERFACES}\s+\(\d+\)\s*$$
  ^\s+IP:\s+${IP_ADDRESSES}\s*$$
  ^\s+IP\s+${IP_ADDRESSES}\s+\d+\s+\d+
  ^\s+IPv6:\s+${IPV6_ADDRESSES}\s*$$
  ^\s+IPv6\s+${IPV6_ADDRESSES}\s+\d+\s+\d+
  ^\s+Other\s+\d+\s+\d+
  ^\s+IPv6\s+\d+\s+\d+
  ^\s+Total\s\d+
  ^\s+\d+\s+packets,
  ^\s*$$
  ^. -> Error Data

Interface
  ^\s*${INTERFACES}\s*$$
  ^\s*\S+\s+\(\S+\)$$
  ^\s+Total\s+\d+\s+
  ^\s+IP\:\s+${IP_ADDRESSES}
  ^\s+IPv6\:\s+${IPV6_ADDRESSES}
  ^\s+MPLS\:\s+
  ^\s+Protocols\s+Configured\: -> Data
  ^\s+This\s+is\s+configured\s+as\s+native\s+Vlan -> Data
  ^Virtual\s+LAN\s+ID\:\s+\d.* -> Continue.Record
  ^Virtual\s+LAN\s+ID\:\s+${VLAN_ID}.* -> Data
  ^VLAN\s+ID:\s+\d+ -> Continue.Record
  ^VLAN\s+ID:\s+${VLAN_ID} -> Data
  ^. -> Error Interface
SAMPLE COMMAND OUTPUT
Virtual LAN ID:  1 (IEEE 802.1Q Encapsulation)

   vLAN Trunk Interfaces:  GigabitEthernet8
GigabitEthernet9

 This is configured as native Vlan for the following interface(s) :
GigabitEthernet8    Native-vlan Tx-type: Untagged
GigabitEthernet9    Native-vlan Tx-type: Untagged

   Protocols Configured:   Address:              Received:        Transmitted:

GigabitEthernet8 (1)
           IP              10.249.2.6           903996720           917275590
        Other                                           0             6689172

   861876081 packets, 104351032620 bytes input
   886447918 packets, 315385944437 bytes output

GigabitEthernet9 (1)
           IP              10.252.202.197 
        Other                                           0             6689172

   43228243 packets, 8882119957 bytes input
   37516844 packets, 4952240355 bytes output
SUMMARY

On some devices IOS the show vlans command returns empty under packets and this causes the parsing to fail.

STEPS TO REPRODUCE
EXPECTED RESULTS

The output to be parsed successfully.

ACTUAL RESULTS
"Error: Data. Rule Line: 38. Input Line:            IP              10.252.202.197 ."
mjbear commented 2 months ago

Ah, I see in some cases the Received/Transmitted fields have no numbers (not even a zero).

mjbear commented 2 months ago

@jmcgill298 This ticket is resolved by #1828 and can be resolved as well. Thank you!