forked from Aspirin1897/VersaTEL_G1_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB.py
158 lines (113 loc) · 3.78 KB
/
DB.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# coding:utf-8
import datetime
from mongoengine import Document, connect
from mongoengine.fields import *
import GetConfig as gc
import HAAP as haap
import SANSW as sw
import Sundry as s
# <<<read config >>>
cfgDB = gc.DBConfig()
strDBName = cfgDB.name()
strDBHost = cfgDB.host()
intDBPort = cfgDB.port()
# <<<read config >>>
# connet to the datebase
connect(strDBName, host=strDBHost, port=intDBPort)
def haap_insert(time, origin, info):
"""
@note: monitoHAAP数据插入
"""
HAAP().insert(time, origin, info)
def haap_last_record():
"""
@note: HAAP最后一次所有的数据
"""
return HAAP().query_last_record()
# SANSW
def switch_insert(time, origin, sum_total, dicPEFormated):
"""
@note: SANSW数据插入
"""
SANSW().insert(time, origin, sum_total, dicPEFormated)
def switch_last_info():
"""
@note: SANSW最后一次所有的数据
"""
return SANSW().query_last_records()
# Warning
def insert_warning(time, ip,device, level, warn_message, confirm):
"""
@note: warning数据插入
"""
Warning().insert(time , ip, device,level,
warn_message, confirm)
def update_warning():
"""
@note: 更新warning数据库
"""
Warning().update_Warning()
def get_unconfirm_warning():
"""
@note: warning网页部分展示
"""
lstAllUCW = []
for warning in Warning().get_all_unconfirm_warning():
lstAllUCW.append([warning.time, warning.ip, warning.device,
warning.level, warning.warn_message])
if lstAllUCW:
return lstAllUCW
class collHAAP(Document):
time = DateTimeField(default=datetime.datetime.now())
origin = DictField()
info = DictField()
class collSANSW(Document):
# ptes = port error show info formatted
time = DateTimeField(default=datetime.datetime.now())
origin = DictField()
ptes = DictField()
sum_total = DictField()
class collWarning(Document):
time = StringField()
level = IntField()
device = StringField()
ip = StringField()
warn_message = StringField()
confirm = IntField()
class HAAP(object):
def insert(self, time , origin, info):
t = collHAAP(time=time , origin=origin, info=info)
t.save()
def query_range(self, time_start, time_end):
collHAAP.objects(date__gte=time_start,
date__lt=time_end).order_by('-date')
def query_last_record(self):
return collHAAP.objects().order_by('-time').first()
class SANSW(object):
def insert(self, time, origin, sum_total, ptes):
t = collSANSW(time=time, origin=origin, sum_total=sum_total, ptes=ptes,)
t.save()
def query_range(self, time_start, time_end):
collSANSW.objects(date__gte=time_start,
date__lt=time_end).order_by('-date')
def query_last_records(self):
return collSANSW.objects().order_by('-time').first()
class Warning(object):
def insert(self, time_now, lstip, device, lstdj, lstSTS, confirm):
t = collWarning(time=time_now, ip=lstip, device=device,level=lstdj,
warn_message=lstSTS, confirm=confirm)
t.save()
def query_range(self, time_start, time_end):
collWarning.objects(date__gte=time_start,
date__lt=time_end).order_by('-date')
def query_last_records(self):
return collWarning.objects().order_by('-time').first()
def update(self, intN):
return collWarning.objects().order_by('-time').first()
def get_all_unconfirm_warning(self):
warning_status = collWarning.objects(confirm=0)
return warning_status
def update_Warning(self):
return collWarning.objects(confirm=0).update(confirm=1)
if __name__ == '__main__':
pass