简体   繁体   中英

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.

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

在此处输入图像描述

  • Select 'Delimited' and click Next

在此处输入图像描述

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

在此处输入图像描述

在此处输入图像描述

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

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM