-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertStateHandler.py
More file actions
36 lines (28 loc) · 926 Bytes
/
AlertStateHandler.py
File metadata and controls
36 lines (28 loc) · 926 Bytes
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
#!/usr/bin/python3
#
# AlertStateHandler.py - keeps track of CVEs where an alert was already sent out
#
import LogHandler
import json
class AlertStateHandler:
def __init__(self, statefile, loghandler: LogHandler):
self.statefile = statefile
self.lh = loghandler
def AddAlert(self, cveid):
try:
with open(self.statefile, 'r') as fh:
state = json.load(fh)
except Exception:
state = []
if cveid not in state:
state.append(cveid)
with open(self.statefile, 'w') as fh:
json.dump(state, fh)
def HasAlert(self, cveid):
state = []
try:
with open(self.statefile, 'r') as fh:
state = json.load(fh)
except Exception as e:
self.lh.Write("Failed to open state database: " + str(e) + ". Assuming empty state.", 1)
return cveid in state