Skip to content
Snippets Groups Projects
Commit 20cd977d authored by rick.mollard's avatar rick.mollard
Browse files

added output file

parent c3a8f4f6
No related branches found
No related tags found
No related merge requests found
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment