forked from awslabs/amazon-redshift-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit_logs_parsing.py
106 lines (91 loc) · 3.23 KB
/
audit_logs_parsing.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
"""
auditlogs_parsing.py
This module parses various auditlogs
"""
logger = None
class Log:
def __init__(self):
self.record_time = ""
self.start_time = ""
self.end_time = ""
self.username = ""
self.database_name = ""
self.pid = ""
self.xid = ""
self.text = ""
def get_filename(self):
base_name = (
self.database_name
+ "-"
+ self.username
+ "-"
+ self.pid
+ "-"
+ self.xid
+ " ("
+ self.record_time.isoformat()
+ ")"
)
return base_name
def __str__(self):
return (
"Record time: %s, Start time: %s, End time: %s, Username: %s, Database: %s, PID: %s, XID: %s, Query: %s"
% (
self.record_time,
self.start_time,
self.end_time,
self.username,
self.database_name,
self.pid,
self.xid,
self.text,
)
)
def __eq__(self, other):
return (
isinstance(other, self.__class__)
and self.record_time == other.record_time
and self.start_time == other.start_time
and self.end_time == other.end_time
and self.username == other.username
and self.database_name == other.database_name
and self.pid == other.pid
and self.xid == other.xid
and self.text == other.text
)
def __hash__(self):
return hash((str(self.pid), str(self.xid), self.text.strip("\n")))
class ConnectionLog:
def __init__(self, session_initiation_time, end_time, database_name, username, pid):
self.session_initiation_time = session_initiation_time
self.disconnection_time = end_time
self.application_name = ""
self.database_name = database_name
self.username = username
self.pid = pid
self.time_interval_between_transactions = True
self.time_interval_between_queries = "transaction"
def __eq__(self, other):
return (
isinstance(other, self.__class__)
and self.session_initiation_time == other.session_initiation_time
and self.disconnection_time == other.disconnection_time
and self.application_name == other.application_name
and self.database_name == other.database_name
and self.username == other.username
and self.pid == other.pid
and self.time_interval_between_transactions
== other.time_interval_between_transactions
and self.time_interval_between_queries
== other.time_interval_between_queries
)
def __hash__(self):
return hash((self.database_name, self.username, self.pid))
def get_pk(self):
return hash(
(self.session_initiation_time, self.database_name, self.username, self.pid)
)
class Logger:
def __init__(self, logger_in):
global logger
logger = logger_in