forked from grapl-security/grapl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-raw-logs.py
executable file
·50 lines (37 loc) · 1.1 KB
/
gen-raw-logs.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
#!/usr/bin/env python
try:
from typing import Any, Dict, Union, Optional
except:
pass
import time
import string
import boto3
import random
import zstd
import sys
def rand_str(l):
# type: (int) -> str
return ''.join(random.choice(string.ascii_uppercase + string.digits)
for _ in range(l))
def main(prefix):
s3 = boto3.client('s3')
with open('./eventlog.xml', 'rb') as b:
body = b.readlines()
body = [line for line in body]
def chunker(seq, size):
return [seq[pos:pos + size] for pos in range(0, len(seq), size)]
for chunks in chunker(body, 50):
c_body = zstd.compress(b"\n".join(chunks), 4)
epoch = int(time.time())
s3.put_object(
Body=c_body,
Bucket="{}-sysmon-log-bucket".format(prefix),
Key=str(epoch - (epoch % (24 * 60 * 60))) + "/sysmon/" +
str(epoch) + rand_str(3)
)
print(time.ctime())
if __name__ == '__main__':
if len(sys.argv) != 2:
raise Exception("Provide bucket prefix as first argument")
else:
main(sys.argv[1])