12
12
13
13
'''
14
14
from ruxit .api .base_plugin import RemoteBasePlugin
15
+ from datetime import datetime , timedelta
15
16
from math import floor
17
+ from time import sleep
16
18
import requests
17
19
import logging
18
- import time
19
- import os
20
+ import pytz
20
21
21
22
logger = logging .getLogger (__name__ )
22
23
@@ -49,13 +50,9 @@ def initialize(self, **kwargs):
49
50
}
50
51
51
52
self .pollingInterval = int (config ['pollingInterval' ]) * 60 * 1000
52
- self .start_time = floor (time .time ()* 1000 ) - self .pollingInterval
53
-
54
-
55
- os .environ ['TZ' ] = config ['timezone' ]
56
- time .tzset ()
57
- logging .info (f" Timezone: { config ['timezone' ]} and ENV: { os .environ ['TZ' ]} and tzname { time .tzname } " )
58
53
54
+ self .timezone = pytz .timezone (config ['timezone' ])
55
+ self .start_time = floor (datetime .now ().timestamp ()* 1000 ) - self .pollingInterval
59
56
self .verify_ssl = config ['verify_ssl' ]
60
57
if not self .verify_ssl :
61
58
requests .packages .urllib3 .disable_warnings ()
@@ -73,7 +70,7 @@ def make_api_request(self, http_method, endpoint, json=None):
73
70
response = requests .request (http_method , f"{ self .url } { endpoint } " , json = json , headers = self .headers , verify = self .verify_ssl )
74
71
if response .status_code == 429 :
75
72
logging .info ("AUDIT - RATE LIMITED! SLEEPING..." )
76
- time . sleep (response .headers ['X-RateLimit-Reset' ]/ 1000000 )
73
+ sleep (response .headers ['X-RateLimit-Reset' ]/ 1000000 )
77
74
else :
78
75
break
79
76
return response .json ()
@@ -114,7 +111,7 @@ def post_annotations(self, eventType, user, category, timestamp, entityId, patch
114
111
"eventType" : eventType ,
115
112
"User" : user ,
116
113
"Category" : category ,
117
- "Timestamp" : time . strftime ("%a, %d %b %Y %H:%M:%S %z" , time . localtime ( timestamp / 1000 ) ),
114
+ "Timestamp" : datetime . now ( tz = self . timezone ). strftime ("%a, %d %b %Y %H:%M:%S %z" ),
118
115
"entityId" : entityId ,
119
116
"Change" : patch
120
117
},
@@ -183,7 +180,7 @@ def query(self, **kwargs):
183
180
'''
184
181
Routine call from the ActiveGate
185
182
'''
186
- self .end_time = floor (time . time ()* 1000 )
183
+ self .end_time = floor (datetime . now (). timestamp ()* 1000 )
187
184
if self .end_time - self .start_time >= self .pollingInterval :
188
185
audit_logs = self .get_audit_logs ()
189
186
self .process_audit_payload (audit_logs )
0 commit comments