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()
Larz60+ write Nov-13-2020, 05:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Thank You
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Thank You