From 20cd977ded085a1235e353e2d515f512be2c4ddd Mon Sep 17 00:00:00 2001 From: "rick.mollard" <rick.mollard@nebraska.edu> Date: Fri, 15 Jul 2022 11:07:36 -0500 Subject: [PATCH] added output file --- highTransitions.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/highTransitions.py b/highTransitions.py index aa984cc..480017a 100644 --- a/highTransitions.py +++ b/highTransitions.py @@ -32,13 +32,16 @@ Ausername = input() print("Enter Password:") Apassword = getpass.getpass() creds = {"username": {Ausername}, "password": {Apassword}} +file1 = open("highTransitions.txt", "w") for selectIP in file: ip_add = selectIP hostname = socket.getfqdn(ip_add) print(f"Login from: {hostname} {ip_add}") + file1.writelines(f"Login from: {hostname} {ip_add}\n") session = requests.session() + # create sessions object def get_logs(self): try: @@ -72,17 +75,16 @@ for selectIP in file: get_lldp = session.get(f"https://{self}/rest/v10.04/system/interfaces/{Switch}%2F1%2F{SwitchPort}/lldp_neighbors?attributes=neighbor_info&depth=4&selector=status&filter=") lldpModel = f"{get_lldp.json()}" split_lldpModel = lldpModel.split(", ") - count=3 while count < len(split_lldpModel): # This handles errors when no lldp info is found. - #final_lldp = split_lldpModel[3] lsplit_lldp = lldpModel.split("'chassis_description': '",1)[1] final_lldp = lsplit_lldp.split("', ",1)[0] count += 1 - #print(final_lldp) print(f"Port: {Switch}/1/{SwitchPort} {str_LinkTransitions} --- {final_lldp}") + file1.write(f"Port: {Switch}/1/{SwitchPort} {str_LinkTransitions}\n") final_lldp = "No LLDP Info" # Default value if no lldp info is retreived + SwitchPort += 1 Switch += 1 SwitchPort = 1 @@ -97,7 +99,8 @@ for selectIP in file: LinkTransitions = re.findall(r'\d+',f"{get_log.json()}") str_LinkTransitions = str(LinkTransitions[0]) if transitions <= int(str_LinkTransitions): - print(f"Port: {Switch}/1/{SwitchPort} {str_LinkTransitions}") + print(f"Port: {Switch}/1/{SwitchPort} {str_LinkTransitions} --- {final_lldp}") + file1.write(f"Port: {Switch}/1/{SwitchPort} {str_LinkTransitions}\n") SwitchPort += 1 Switch += 1 SwitchPort = 1 @@ -107,10 +110,12 @@ for selectIP in file: logout = session.post(f"https://{self}/rest/v1/logout") print(f"Logout from: {hostname} {ip_add}") + file1.write(f"Logout from: {hostname} {ip_add}\n") except requests.exceptions.RequestException as e: print("Switch is not responding-----> " + ip_add) print("Switch is not responding-----> " + ip_add) - print("Switch is not responding-----> " + ip_add) + print("Switch is not responding-----> " + ip_add) + file1.write("Switch is not responding-----> " + ip_add + "\n") -- GitLab