Hello guys,
at work im in charge of several hundred of cisco switches. Because we are undergoing an infrastructure migration my boss wants me to check every single switch for unused ports and document it. You can imagine how i felt when i heard that. I was not amazed over the fact that i had to SSH into every single device, do following stuff:
- sh int | inc line protocol is|Last input -> check which interfaces are not connected and where last input/output never
- disable those interfaces
show int status | count disable -> count the amount of interfaces which in the end are disabled and document in a excel file.
I have little understanding of coding from school and after TSHOOT my next goal was to start with python, but with this assignment i will have to postpone my certification.
So i spent whole day trying to figure out how to code it and the nearest ive come is this:
- So in another pyfile (which i dont show you here) i SSH to a device, use the command: sh int | inc line protocol is|Last input and save the output in the file ASW2.cfg which we use here as reference.
- I dont know if thats the optimal way to do this. In my opinion id like the code to SSH into the device, send the command sh int |... (save the output as a list?), if interface is unused, disable it, if not go to next interface. Sounds easy, right?
device = ConnectHandler(device_type="cisco_ios_telnet", ip="192.168.170.129", port="32778", username="x", password="x") parse = CiscoConfParse('C:/Users/x/Desktop/ASW2.cfg') device.enable() def standardize_intfs(parse): for intf in parse.find_objects('Ethernet'): #Would like to pick an Object with "Ethernet" AND "not connected" in it? And i would like it to check if gigabit or #fastethernet port. last_input = intf.has_child_with ("Last input never") last_output = intf.has_child_with ("output never") if last_input and last_input: x = intf.text.split() print(x[0]) configcmds=["interface " + x[0], "shutdown"] device.send_config_set(configcmds) standardize_intfs(parse) count_disable = device.send_command("show int status | count disable") print (count_disable)
Ive almost made it work. It picks up Interfaces which are not connected but also those who are connected. Example:
Ethernet1/1 is up, line protocol is up (connected)
Last input never, output never, output hang never
Thank you!
No comments:
Post a Comment