This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServerActions.py
50 lines (45 loc) · 1.66 KB
/
ServerActions.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
import datetime
import pytz
from MongoC.EvtManagerClass import LogTemplate
from MongoC.ClientReport import ClientReport as ClientR
from MongoC.CategoryClass import Category
timezone = pytz.timezone('Asia/Jerusalem')
def pushToMongo(evtmgr) -> bool:
loghand = LogTemplate() # LogHandler in the Class
loghand.logid = evtmgr.id
loghand.client_time = datetime.datetime.fromtimestamp(evtmgr.time.seconds + evtmgr.time.nanos, timezone) #TODO: check if the convert is right
loghand.insert_time = datetime.datetime.now()
loghand.type = evtmgr.type
loghand.src = evtmgr.src
loghand.cat = evtmgr.cat
loghand.hostname = evtmgr.hostname
loghand.username = evtmgr.username
loghand.os = evtmgr.os
loghand.ip_add = evtmgr.ip_add
loghand.mac_add = evtmgr.mac_add
if (evtmgr.dataList != None):
loghand.dataList = list(evtmgr.dataList)
try:
loghand.save()
return True
except Exception as error_massage:
print('Push_to_mongo failure:\n %s' % error_massage) # Debug only
return False
def PushClientReports(ClientReport)->bool:
clientReport = ClientR()
clientReport.header = ClientReport.head
clientReport.desc = ClientReport.details
clientReport.hostname = ClientReport.hostname
clientReport.time = datetime.datetime.now()
try:
clientReport.save()
return True
except Exception as error_massage:
print('Push_to_mongo failure:\n %s' % error_massage) # Debug only
return False
def get_categories():
cat_class = Category.objects.first()
cat_list = []
for category in cat_class.category_select:
cat_list.append(category)
return cat_list