-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_ucs_ntp_config.py
executable file
·79 lines (59 loc) · 2.45 KB
/
audit_ucs_ntp_config.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
#!/usr/bin/env python
from ucsmsdk.ucshandle import UcsHandle
import getpass
from tabulate import tabulate
from datetime import datetime
import os
import ipaddress
import platform
ucs_ip = input('ucs system (or all): ')
ucs_username= input("username: ")
user_passwd = getpass.getpass("passowrd: ")
table_output=input("provide table output format (pipe, jira, simple): ")
ucs_list = []
if ucs_ip.lower() == 'all':
from ucs_list import ucs_list
ucs_list = ucs_list
else:
ucs_list.append(ucs_ip)
def get_ucs_ntp_settings(ucs_list, ucs_username, user_passwd):
timestamps_all=[]
for ucs in ucs_list:
handle = UcsHandle(ip=ucs, username=ucs_username, password=user_passwd)
handle.login()
mo_dn = handle.query_dn("sys")
ucs_current_time=mo_dn.current_time
utc_current_time=datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f1')
utc_current_time = utc_current_time[:-4]
t1 = datetime.strptime(ucs_current_time, "%Y-%m-%dT%H:%M:%S.%f")
t2 = datetime.strptime(utc_current_time, "%Y-%m-%dT%H:%M:%S.%f")
diff = t1 - t2
ntp_dn = handle.query_classid("commNtpProvider")
mgmt_ip_a = handle.query_dn("sys/switch-A")
fi_ip = mgmt_ip_a.oob_if_ip
netmask = mgmt_ip_a.oob_if_mask
if len(ntp_dn) > 0:
ntp_servers = [ n.name for n in ntp_dn ]
network=ipaddress.ip_network('{}/{}'.format(fi_ip,netmask),strict=False)
correct_ntp=ipaddress.ip_address(ntp_servers[0]) in ipaddress.ip_network(network)
else:
ntp_servers = ['no ntp']
# create temp list to add to a list of lists
timestamp_per_site = []
timestamp_per_site.extend([handle.ip,
utc_current_time,
ucs_current_time,
abs(diff.total_seconds()),
ntp_servers[0],
correct_ntp])
timestamps_all.append(timestamp_per_site)
print("=> logged out of {}".format(handle.ip))
handle.logout()
if platform.system() != ('Windows'):
os.system('clear')
else:
os.system( 'cls' )
headers=['site', 'utc timestamp', 'ucs timestamp', 'offset', 'ntp server', 'correct']
print(tabulate(timestamps_all, headers=headers, tablefmt=table_output))
if __name__ == "__main__":
get_ucs_ntp_settings(ucs_list, ucs_username, user_passwd)