-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
88 lines (67 loc) · 2.53 KB
/
main.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
#!/usr/bin/env python3
# -----------------------------------------------------------------------------------------
#
# Demonstrates how to get Cisco DNA Center device list and save them to an xlsx sheet and
# and device configs and save them to text files.
#
# (C) 2021 Osama Abbas, Cairo, Egypt
# Released under MIT License
#
# Filename: main.py
# Version: Python 3.9.4
# Authors: Osama Abbas ([email protected])
# Description: This program is designed to get Cisco DNA Center device list and
# save them to an xlsx sheet and device configs and save them to text files.
#
# -----------------------------------------------------------------------------------------
# Import Modules
import platform
import time
from datetime import timedelta
from colorama import init
from dotenv import dotenv_values
# Export modules
from export_device_config import export_device_config
from export_device_list import export_device_list
from export_network_health import export_network_health
# Get modules
from get_auth_token import get_auth_token
from get_device_config import get_device_config
from get_device_list import get_device_list
from get_network_health import get_network_health
# Notification module
from notify import notify
# use Colorama to make Termcolor work on Windows too
init(autoreset=True)
# ENV Variables in current project
ENV = {
**dotenv_values(".env.example"),
**dotenv_values(".env"),
}
def main():
# Start time
start_time = time.perf_counter()
print(f'Running for {ENV["DOMAIN"]}')
# Obtain the Cisco DNA Center Auth Token
token = get_auth_token(ENV=ENV)
# Obtain devices on Cisco DNA Center
device_list = get_device_list(token=token, ENV=ENV)
# Export devices to Excel sheet
export_device_list(device_list=device_list, ENV=ENV)
# Obtain device configs
device_configs = get_device_config(token=token, ENV=ENV)
# Export device configs to text files
export_device_config(device_configs=device_configs, ENV=ENV)
# Obtain network health
network_health = get_network_health(token=token, ENV=ENV)
# Export matplotlib bar chart of network health
export_network_health(network_health=network_health, ENV=ENV)
# Print Elasped time
end_time = time.perf_counter()
delta = str(timedelta(seconds=end_time - start_time)).split(".")[0]
print(f"\nFinishd in {delta}")
# Send notification for Windows users ONLY
if "Windows" in platform.system():
notify("Congratulations! Python script ran successfully")
if __name__ == "__main__":
main()