Oct-13-2020, 02:07 AM
Good evening everyone
I am attempting to extract the output from multiple cisco switches about 60 of them and put the data into an excel spreadsheet with multiple sheets. I have the code working for a single switch and the output going to excel. I was wondering if anyone would be able to assist or help point me to some full examples of something similar. I am very new to programming so sorry if my code looks bad but I am trying to learn. Any help would be much appreciated.
I am attempting to extract the output from multiple cisco switches about 60 of them and put the data into an excel spreadsheet with multiple sheets. I have the code working for a single switch and the output going to excel. I was wondering if anyone would be able to assist or help point me to some full examples of something similar. I am very new to programming so sorry if my code looks bad but I am trying to learn. Any help would be much appreciated.
from netmiko import ConnectHandler from datetime import datetime import os import json import pandas as pd import argparse SW1 = { 'device_type': 'cisco_ios', 'host': '192.168.1.2', 'username':'cisco', 'password': 'cisco', } SW2 = { 'device_type': 'cisco_ios', 'host': '192.168.1.3', 'username':'cisco', 'password': 'cisco', } def main(): os.environ["NET_TEXTFSM"] = "./ntc-templates/templates" # list of all devices all_devices = [SW1, SW2] # commands for a_device in all_devices: net_connect = ConnectHandler(**a_device) lldp_neighbor = net_connect.send_command("show lldp neighbor", use_textfsm=True) print(lldp_neighbor) print(len(lldp_neighbor)) for line in lldp_neighbor: print(json.dumps(line, indent=6)) lldp_data = {'NEIGHBOR': [entry['neighbor'] for entry in lldp_neighbor], 'LOCAL_INTERFACE': [entry['local_interface'] for entry in lldp_neighbor], 'CAPABILITIES': [entry['capabilities'] for entry in lldp_neighbor], 'NEIGHBOR_INTERFACE': [entry['neighbor_interface'] for entry in lldp_neighbor], } df = pd.DataFrame(lldp_data, columns=list(lldp_data.keys())) print(df.head()) df.to_excel('LLDP_Neighbor.xlsx') # Standard call to the main() function. if __name__ == '__main__': parser = argparse.ArgumentParser(description="Script Description", epilog="Usage: ' python ccom' ") arguments = parser.parse_args() main()