diff --git a/FindLinkTransitions.py b/FindLinkTransitions.py new file mode 100644 index 0000000000000000000000000000000000000000..060e981fb00e0eb4084b8f7a56650ecff87ca5b1 --- /dev/null +++ b/FindLinkTransitions.py @@ -0,0 +1,62 @@ +from urllib3 import exceptions # Prevent SSL Self-Signed Certificate Error +import requests # Creation Of New Object +import urllib3 +import re +from netmiko import (ConnectHandler,NetmikoTimeoutException) # SSH Connection +import socket # DNS Lookup +import time # For Waiting +import CampusSelector + + +def main(ArubaUsername, ArubaPassword): + # Preparatory Work for SSH Connection + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Disable Certificate Warning + interfaces = {} # Initialize the interface variable + current_interface = "" # Initialize Current Interface to make sure it isn't null + port_configuration = ['vlan access 1', 'enable', 'enable'] + exception = ['trunk allowed 2000', 'trunk allowed 1999'] + int_changes = [] + + # Get the Campus or Switch IP Address + campus = CampusSelector.Campus_Selector() + ip = campus[1] + campus_selection = campus[2] + campus_file = campus[0] + transitions = "2000" + Switch = 1 + SwitchPort = 1 + + if campus_selection != "6": + with open(campus_file) as file: + while line := file.readline().rstrip(): + ip = line + hostname = socket.getfqdn(ip) + print('Current Switch:', hostname, ":", ip) + + missing = [] + # Create Session Object + session = requests.session() + + # Create SSH Connection + try: + ssh = ConnectHandler( + device_type="aruba_procurve", + host=ip, + username=ArubaUsername, + password=ArubaPassword, + ) + print(username) + + login = session.post(f"https://{ip}/rest/v1/login", data=(username,password), verify=False) + get_log = session.get(f"https://{ip}/rest/v10.04/system/interfaces/{Switch}%2F1%2F{SwitchPort}?attributes=link_resets&depth=2&selector=statistics") + print(get_logs) + logout = session.post(f"https://{ip}/rest/v1/logout") + print(f"Logout Code from Switch:{logout.status_code}") + + finally: + print("Logging Out From Switch", hostname, ip) + ssh.disconnect() + time.sleep(1) + + + \ No newline at end of file