pepex7
pepex7

Reputation: 1

How to parse cisco switch output data with Netmiko

I am doing TDR cable-diagnostics on a Cisco switch and I need to know how to transfer that information to Excel (ordered).

from netmiko import ConnectHandler

#Credenciales
ip = "192.168.xx.xx"
username = "admin"
password = "pass"
pass_enable = "secret"
DEVICE_TYPE = 'cisco_ios'

conexion = ConnectHandler(ip=ip, username=username, password=password, secret=pass_enable, device_type=DEVICE_TYPE)

if not conexion.check_enable_mode():
    conexion.enable()

tdr = conexion.send_command('show cable-diagnostics tdr interface Gi1/0/1', use_textfsm=True)

print(tdr)

The output is this:

SW1#show cable-diagnostics tdr interface Gi1/0/1
TDR test last run on: December 26 11:40:35

Interface Speed Local pair Pair length        Remote pair Pair status
--------- ----- ---------- ------------------ ----------- --------------------
Gi1/0/1   1000M Pair A     55   +/- 10 meters Pair B      Normal              
                Pair B     55   +/- 10 meters Pair A      Normal              
                Pair C     55   +/- 10 meters Pair D      Normal              
                Pair D     55   +/- 10 meters Pair C      Normal 

I hope you can help me, thanks

I tried to sort output to text file but I can pass it to excel sorted.

Upvotes: 0

Views: 666

Answers (1)

Kaleb Fenley
Kaleb Fenley

Reputation: 226

This isn't a perfect solution, but it will get you pretty close.

  • Copy & Paste into Excel

Excel will paste all the data into a single column

EXCEL

  • Highlight the data you want to split into multiple columns. Select Data tab, and Text to Columns

enter image description here

  • Select 'Delimited' and click Next

enter image description here

  • Select 'Tab' 'Space' and 'Treat consecutive delimiters as one', click Finish

enter image description here

enter image description here

  • In your case to get things to line up perfectly you need to highlight a7:a9 and insert, shift cells right

enter image description here

enter image description here

enter image description here

Upvotes: 0

Related Questions