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

show mac address-table no dictionary in response #714

Closed
alepodj opened this issue May 21, 2020 · 3 comments
Closed

show mac address-table no dictionary in response #714

alepodj opened this issue May 21, 2020 · 3 comments

Comments

@alepodj
Copy link
Contributor

alepodj commented May 21, 2020

ISSUE TYPE

  • Bug Report? Not certain is an actual bug, i could be doing something wrong!

Context

netmiko==3.1.0
ntc-templates==1.4.1
textfsm==1.1.0
TEMPLATE USING
Value DESTINATION_ADDRESS ([0-9a-fA-F]{4}\.[0-9a-fA-F]{4}\.[0-9a-fA-F]{4})
Value TYPE (\S+)
Value VLAN (\S+)
Value DESTINATION_PORT (\S+)

Start
  ^Destination\s+Address\s+Address\s+Type\s+VLAN\s+Destination\s+Port -> TYPE1
  ^\s+vlan\s+mac address\s+type\s+learn\s+age\s+ports -> TYPE2
  ^\s+vlan\s+mac address\s+type\s+protocols\s+port -> TYPE3
  ^Vlan\s+Mac Address\s+Type\s+Ports -> TYPE4
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is

TYPE1
  ^${DESTINATION_ADDRESS}\s+${TYPE}\s+${VLAN}\s+${DESTINATION_PORT} -> Record
  ^-+\s+-+
  ^Displaying\s+entries
  ^Destination\s+Address\s+Address\s+Type\s+VLAN\s+Destination\s+Port
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE2
  # Order of the group in brackets here matters
  ^\s*(?:\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT} -> Record
  ^-+\+-+
  ^Displaying\s+entries
  ^\s+vlan\s+mac address\s+type\s+learn\s+age\s+ports
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE3
  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record
  ^-+\+-+
  ^Displaying\s+entries
  ^\s+vlan\s+mac address\s+type\s+protocols\s+port
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE4
  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+${DESTINATION_PORT} -> Record
  ^-+\s+-+
  ^Displaying\s+entries
  ^Vlan\s+Mac Address\s+Type\s+Ports
  ^\s*$$
  ^Total\s+Mac\s+Addresses
  ^MultiCast\s+Entries -> End
  ^. -> Error

SAMPLE COMMAND OUTPUT
--> As typed directly on the switch <--
Router#show mac address-table | include 0000.1111.2222|3333.4444.5555|6666.7777.8888
10      0000.1111.2222   dynamic ip,ipx,assigned,other GigabitEthernet2/9
10      3333.4444.5555   dynamic ip,ipx,assigned,other GigabitEthernet2/4
10      6666.7777.8888   dynamic ip,ipx,assigned,other GigabitEthernet2/5
SUMMARY
show mac address table is not returning a dictionary. At first i figure it was cause i was using a pipe to filter the output in cisco, but turns out that same setup works for `show ip arp | include {macs}`
STEPS TO REPRODUCE
import os 
import json
import ntc_templates
from netmiko import Netmiko
from netmiko import NetMikoAuthenticationException

switch = {'device_type': 'cisco_ios',
                'ip': '192.168.0.1',
                'username': 'admin',
                'password': 'admin',
                'secret': 'admin',
                'timeout': 10000,
                'session_timeout': 10000}

macs = '0000.1111.2222|3333.4444.5555|6666.7777.8888'

try: 
    c = Netmiko(**switch)
    c.enable()
    show_mac_addr_table = c.send_command(f'show mac address-table | include {macs}', use_textfsm=True)
    print(show_mac_addr_table)
except Exception as e:
    print(e)
EXPECTED RESULTS
A a list of dictionaries for each line returned as the usual default behavior
ACTUAL RESULTS
Raw data is returned
10      0000.1111.2222   dynamic ip,ipx,assigned,other GigabitEthernet2/9
10      3333.4444.5555   dynamic ip,ipx,assigned,other GigabitEthernet2/4
10      6666.7777.8888   dynamic ip,ipx,assigned,other GigabitEthernet2/5
@itdependsnetworks
Copy link
Contributor

itdependsnetworks commented May 21, 2020

When parsing, there is an assumption that the template receives the entire output. At times, I am sure there is no effect by using an include as you have here, but in this case it does. The header is used to determine which of the four different potential table outputs you could have.

So removing the | include 0000.1111.2222|3333.4444.5555|6666.7777.8888 should return data

@itdependsnetworks
Copy link
Contributor

If you have any other questions, likely easier to continue convo on Slack, can sign up here: https://networktocode.herokuapp.com/ and best to ask on the #networktocode channel within that slack community.

@alepodj
Copy link
Contributor Author

alepodj commented May 21, 2020

Yeah i see now, piping the show mac address-table command responds without table header but so does show ip arp | include xxx which is interesting i see both rules are quite different. Thanks for the heads up

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

2 participants