-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbPush.py
85 lines (70 loc) · 3.09 KB
/
dbPush.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
import mongodb_auth
import requests
from pprint import pprint
import thousandEyesAppHealth
#import dbnotifications
def runme():
"""This function is used to push data to the database
parameters: None
returns: None
"""
db = mongodb_auth.authenticatedb()
response = requests.get("http://127.0.0.1:5555/data")
data = response.json()["data"]
print("completed getting data from ControllerREST..")
#dbnotifications.runme(dataparam=data)
vManageHealth_data = data["vManageHealth"]
DnacHealth_data = data["DnacHealth"]
vManageNWPI_readTrace_sloDetails = data["vManageNWPI_readTrace"][0]
vManageNWPIAppHealth_data = data["vManageNWPI_readTrace"][1]
DnacAppHealth_data = data["DnacAppHealth"]
thousandEyesAppHealth_data = thousandEyesAppHealth.get_data()
AppHealth_data = vManageNWPIAppHealth_data
if(vManageNWPIAppHealth_data==[] and DnacAppHealth_data==[] and vManageNWPI_readTrace_sloDetails==[]):
AppHealth_data = [{"health":"green","name":"all","events":["positive"]}]
tmp = {}
result = int(vManageHealth_data[0]["networkHealth"]) * int(DnacHealth_data[0]["networkHealth"])
if(result == 0):
tmp["NetworkHealth"] = "critical"
elif(result == -1):
tmp["NetworkHealth"] = "moderate"
else:
tmp["NetworkHealth"] = "positive"
vManageAlarms_data = data["vManageAlarms"]
DnacAlarms_data = data["DnacAlarms"]
collection = db['NetworkHealth']
print("NetworkHealth : ",mongodb_auth.purge_collection(collection))
data = [tmp]
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
collection = db['DeviceHealth']
print("DeviceHealth : ",mongodb_auth.purge_collection(collection))
data = vManageHealth_data[1]
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
data = DnacHealth_data[1]
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
collection = db['ApplicationHealth']
print("ApplicationHealth : ", mongodb_auth.purge_collection(collection))
data = AppHealth_data
if(data!=[]):
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
data = vManageNWPI_readTrace_sloDetails
if(data!=[]):
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
data = DnacAppHealth_data
if(data!=[]):
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
data = thousandEyesAppHealth_data
if(data!=[]):
print(mongodb_auth.addData(data,collection))
if(vManageAlarms_data==[] and DnacAlarms_data==[]):
DnacAlarms_data = {"severity":"positive"}
collection = db['Alarms']
print("Alarms : ", mongodb_auth.purge_collection(collection))
data = DnacAlarms_data
if(data!=[]):
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
data = vManageAlarms_data
if(data!=[]):
print("Added",mongodb_auth.addData(data,collection),"documents to collection.")
if __name__ == "__main__":
runme()