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

textFSM - output not in expected format #1126

Closed
kevindasilva03 opened this issue Mar 7, 2019 · 14 comments
Closed

textFSM - output not in expected format #1126

kevindasilva03 opened this issue Mar 7, 2019 · 14 comments

Comments

@kevindasilva03
Copy link

Possible bug...

Connecting with device type cisco_xe running the following command
mac_int_output = net_conn.send_command(f"show mac address-table", use_textfsm=True)
Results is a string of the entire MAC table.

Just for kicks... I reconnected to the XE device using device type cisco_ios and I get the following:

[{'destination_address': '0008.e3ff.fca8',
'type': 'static',
'vlan': '950',
'destination_port': 'Switch'}]

The result is only the first MAC entry in the table, but the format is what I'm looking for.

How do I go about troubleshooting this further.

Please advise and thanks for your help!

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

ntc_templates doesn't have an index for 'cisco_xe' i.e. they only have a category of 'cisco_ios'. You should be able to just switch to 'cisco_ios' for the device_type since that is identical to 'cisco_xe' from a Netmiko perspective.

@ktbyers ktbyers closed this as completed Mar 7, 2019
@kevindasilva03
Copy link
Author

Thanks Kirk for the quick reply. Just to confirm, when using 'cisco_ios' and the output is only the first line, this is a textFSM issue? If so, I will follow up with them.

Thanks again!

@ktbyers ktbyers reopened this Mar 7, 2019
@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

Okay, I might have misunderstood your issue (or you second issue anyways)...so you are saying you set this to "cisco_ios" and you only get one entry back and you are expecting more than one entry?

[{'destination_address': '0008.e3ff.fca8',
'type': 'static',
'vlan': '950',
'destination_port': 'Switch'}]

@kevindasilva03
Copy link
Author

That is correct...

@kevindasilva03
Copy link
Author

Sample command output:

dd-r-vss#sh mac address-table
Unicast Entries
vlan mac address type protocols port
---------+---------------+--------+---------------------+-------------------------
950 0008.e3ff.fca8 static ip,ipx,assigned,other Switch
1105 0008.e3ff.fca8 static ip,ipx,assigned,other Switch
1105 0008.e3ff.fcac dynamic ip,ipx,assigned,other Port-channel30
1106 0008.e3ff.fca8 static ip,ipx,assigned,other Switch
1106 002a.6a8b.e343 dynamic ip,ipx,assigned,other TenGigabitEthernet1/1/1
1171 0008.e3ff.fca8 static ip,ipx,assigned,other Switch
1171 001b.baf8.ca15 dynamic ip,ipx,assigned,other Port-channel41
1171 001b.baf8.ca31 dynamic ip,ipx,assigned,other Port-channel41

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

I would first see the raw data of what Netmiko is getting back:

mac_int_output = net_conn.send_command(f"show mac address-table")

And print that variable out.

To isolate whether it is a Netmiko issue or a TextFSM issue.

@kevindasilva03
Copy link
Author

kevindasilva03 commented Mar 7, 2019

See below. Sample of output.

In [30]: mac_int_output = net_conn.send_command("show mac address-table")
In [33]: print(mac_int_output)
Unicast Entries
 vlan     mac address     type        protocols               port
---------+---------------+--------+---------------------+-------------------------
 950      0008.e3ff.fca8    static ip,ipx,assigned,other Switch
1105      0008.e3ff.fca8    static ip,ipx,assigned,other Switch
1105      0008.e3ff.fcac   dynamic ip,ipx,assigned,other Port-channel30
1106      0008.e3ff.fca8    static ip,ipx,assigned,other Switch
1106      002a.6a8b.e343   dynamic ip,ipx,assigned,other TenGigabitEthernet1/1/1
1171      0008.e3ff.fca8    static ip,ipx,assigned,other Switch
1171      001b.baf8.ca15   dynamic ip,ipx,assigned,other Port-channel41
1171      001b.baf8.ca31   dynamic ip,ipx,assigned,other Port-channel41
1171      001d.affe.7d33   dynamic ip,ipx,assigned,other Port-channel21

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

Looking at the TextFSM template...it looks like probably a TextFSM bug:

TYPE3
  ^\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record

I think ^\s+ needs changed to ^\s* (i.e. when the VLAN is 4 digits, then there is no leading whitespace).

cisco_ios_show_mac-address-table.template

@kevindasilva03
Copy link
Author

I've made the modification, still no go, but I've opened an issue with them to have it reviewed.

Thanks for your time. It's much appreciated!

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

Works for me (using your output data):

$ python textfsm.py ../ntc-templates/templates/cisco_ios_show_mac-address-table.template show_mac.txt 
FSM Template:
Value DESTINATION_ADDRESS ([0-9a-fA-F]{4}\.[0-9a-fA-F]{4}\.[0-9a-fA-F]{4})
Value TYPE (\w+)
Value VLAN (\w+)
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

TYPE1
  ^${DESTINATION_ADDRESS}\s+${TYPE}\s+${VLAN}\s+${DESTINATION_PORT} -> Record

TYPE2
  ^[\*|\s]\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT} -> Record

TYPE3
  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record

TYPE4
  ^\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+${DESTINATION_PORT} -> Record


FSM Table:
['DESTINATION_ADDRESS', 'TYPE', 'VLAN', 'DESTINATION_PORT']
['0008.e3ff.fca8', 'static', '950', 'Switch']
['0008.e3ff.fca8', 'static', '1105', 'Switch']
['0008.e3ff.fcac', 'dynamic', '1105', 'Port-channel30']
['0008.e3ff.fca8', 'static', '1106', 'Switch']
['002a.6a8b.e343', 'dynamic', '1106', 'TenGigabitEthernet1/1/1']
['0008.e3ff.fca8', 'static', '1171', 'Switch']
['001b.baf8.ca15', 'dynamic', '1171', 'Port-channel41']
['001b.baf8.ca31', 'dynamic', '1171', 'Port-channel41']
['001d.affe.7d33', 'dynamic', '1171', 'Port-channel21']

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

 TYPE3
-  ^\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record
+  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record

@ktbyers
Copy link
Owner

ktbyers commented Mar 7, 2019

Type2 and Type4 might also need to be edited as well.

@kevindasilva03
Copy link
Author

kevindasilva03 commented Mar 7, 2019

I updated the template, but when I ran the command as you did, it's not showing the update. Is it pulling from cache or buffer?

python textfsm.py .../ntc-templates/templates/cisco_ios_show_mac-address-table.template .../show_mac.txt

FSM Template:
Value DESTINATION_ADDRESS ([0-9a-fA-F]{4}.[0-9a-fA-F]{4}.[0-9a-fA-F]{4})
Value TYPE (\w+)
Value VLAN (\w+)
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

TYPE1
^${DESTINATION_ADDRESS}\s+${TYPE}\s+${VLAN}\s+${DESTINATION_PORT} -> Record

TYPE2
^[*|\s]\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT} -> Record

TYPE3
^\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record

TYPE4
^\s+${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+${DESTINATION_PORT} -> Record

FSM Table:
['DESTINATION_ADDRESS', 'TYPE', 'VLAN', 'DESTINATION_PORT']
['0008.e3ff.fca8', 'static', '950', 'Switch']


FROM THE TEMPLATE:

1 Value DESTINATION_ADDRESS ([0-9a-fA-F]{4}.[0-9a-fA-F]{4}.[0-9a-fA-F]{4})
2 Value TYPE (\w+)
3 Value VLAN (\w+)
4 Value DESTINATION_PORT (\S+)
5
6 Start
7 ^Destination\s+Address\s+Address\s+Type\s+VLAN\s+Destination\s+Port -> TYPE1
8 ^\s+vlan\s+mac address\s+type\s+learn\s+age\s+ports -> TYPE2
9 ^\s+vlan\s+mac address\s+type\s+protocols\s+port -> TYPE3
10 ^Vlan\s+Mac Address\s+Type\s+Ports -> TYPE4
11
12 TYPE1
13 ^${DESTINATION_ADDRESS}\s+${TYPE}\s+${VLAN}\s+${DESTINATION_PORT} -> Record
14
15 TYPE2
16 ^[*|\s]\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT} -> Record
17
18 TYPE3
19 ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT} -> Record
20
21 TYPE4
22 ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+${DESTINATION_PORT} -> Record

@kevindasilva03
Copy link
Author

kevindasilva03 commented Mar 7, 2019

Please disregard... I found my error... Thank for your help!!

Kevin

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