-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNAC-TEST-SCRIPT-ver2-P3.8-SA.py
112 lines (96 loc) · 3.72 KB
/
DNAC-TEST-SCRIPT-ver2-P3.8-SA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!C:\Python38\python.exe -u
#!/usr/bin/env python
#written by Keith Baldwin
import getpass
import sys
import time
import paramiko
from datetime import datetime
# Set Username and Password and DNA Center node
username = "maglev"
password = ""
DNAC = ""
today = datetime.now()
date_time = today.strftime("%m/%d/%Y, %H:%M:%S")
ERRORFLAG = ["0","0","0"]
CLOUDURLS = ["www.ciscoconnectdna.com","cdn.ciscoconnectdna.com","registry.ciscoconnectdna.com","registry-cdn.ciscoconnectdna.com","software.cisco.com","cloudsso.cisco.com","cloudsso1.cisco.com","cloudsso2.cisco.com","apiconsole.cisco.com","api.cisco.com","apx.cisco.com","sso.cisco.com","apmx-prod1-vip.cisco.com","apmx-prod2-vip.cisco.com","tools.cisco.com","www.mapbox.com","tiles.mapbox.com"]
# Open files with list of SERVICES and RESULTS file
print("DNA CENTER CLOUD CONNECTIVITY TESTS\n")
DNAC = input("Enter IP Address of DNA Center: ")
password = input("Enter password for MAGLEV account: ")
print("\n\nPlease Standby - preparing the report...\n")
# Open files with list of SERVICES and RESULTS file
f2 = open ("RESULTS-DNAC-CLOUD-SERVICES.txt", "a")
f2.write("\n\n")
f2.write("DNA CENTER CONNECTIVITY TESTS TO NODE: " + (DNAC) + " @ " + (date_time) + "\n\n")
# Connect to DNA Center to run connectivity tests
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=(DNAC),port=2222,username=username,password=password)
remote_connection = ssh_client.invoke_shell()
remote_connection.send("\n")
connection_output = remote_connection.recv(65535)
time.sleep(1)
# Time Service Tests to ensure correct time
f2.write("Time Service Tests:\n")
remote_connection.send("timedatectl status \n\n")
time.sleep(3)
output = remote_connection.recv(65535)
if b"NTP synchronized: yes" in output:
f2.write("NTP Synchronized - success...\n")
else:
f2.write("NTP Synchronized - failure...\n")
ERRORFLAG[0] = "1"
remote_connection.send("date \n\n")
time.sleep(3)
f2.write("\n\n")
# NSLookup Tests to ensure services are resolved
f2.write("NS Lookup Tests:\n")
URL = ""
for URL in CLOUDURLS:
output = ""
remote_connection.send("nslookup " + (URL) +"\n")
time.sleep(3)
output = remote_connection.recv(65535)
if b"can't find" in output:
f2.write("test to " + (URL) + " failure...\n")
ERRORFLAG[1] = "1"
else:
f2.write("test to " + (URL) + " success...\n")
f2.write("\n\n")
URL = ""
# Connection Tests to ensure services are fully reachable
f2.write("Connection URL Tests:\n")
for URL in CLOUDURLS:
output = ""
remote_connection.send("telnet " + (URL) +" 443\n")
time.sleep(3)
remote_connection.send("^] \n")
remote_connection.send("close \n")
time.sleep(3)
output = remote_connection.recv(65535)
if b"Connected to" in output:
f2.write("test to " + (URL) + " success...\n")
else:
f2.write("test to " + (URL) + " failure...\n")
ERRORFLAG[2] = "1"
f2.write("\n\n")
# Connection Summary
f2.write("Connection URL Tests:\n")
print("\n\nConnection URL Tests:\n")
if ERRORFLAG[0] == "1" :
f2.write("NTP Synchronization issue - check Firewall settings and NTP Server IP\n")
print("NTP Synchronization issue - check Firewall settings and NTP Server IP\n")
if ERRORFLAG[1] == "1" :
f2.write("DNS Resolution issue - check DNS IP's, DNS Filtering, and Firewall Settings\n")
print("DNS Resolution issue - check DNS IP's, DNS Filtering, and Firewall Settings\n")
if ERRORFLAG[2] == "1" :
f2.write("URL Connection issue - Filtering and Proxy Settings, and Firewall Settings\n")
print("URL Connection issue - Filtering and Proxy Settings, and Firewall Settings\n")
if b'1' not in ERRORFLAG :
f2.write("Cloud Connectivity Fully Operational\n")
print("Cloud Connectivity Fully Operational\n")
f2.close()
# Close Connection
time.sleep(5)
ssh_client.close