-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_encoder.py
60 lines (45 loc) · 1.89 KB
/
run_encoder.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
"""Command line wrapper around the log_tools.encoder.
`python run_encoder.py --help` for usage information.
"""
import argparse
import getpass
import lzma
import colte.db.reader
import colte.log_tools.encoder
PASS = None
FLOWLOG_OUT_FILE = "flowlog_archive"
DNS_OUT_FILE = "dns_archive"
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--compress", action="store_true",
help="Compress the output archive files.")
key_group = parser.add_mutually_exclusive_group(required=True)
key_group.add_argument("-f", "--keyfile",
help="The file holding the encoding key.")
key_group.add_argument("-k", "--key",
help="The key string to use when encoding data.")
args = parser.parse_args()
if not PASS or PASS is None:
db_password = getpass.getpass(prompt="DB Password:")
else:
db_password = PASS
reader = colte.db.reader.ColteReader(db_host="localhost",
db_user="colte_db",
db_name="colte_db",
db_password=db_password,
)
if args.keyfile is not None:
with open(args.keyfile, mode="rb") as f:
key = f.read()
else:
key = args.key.encode('utf8')
encoder = colte.log_tools.encoder.StreamingEncoder(reader, key)
if args.compress:
encoder.stream_flowlogs_to_file(FLOWLOG_OUT_FILE + ".xz",
compressor=lzma.LZMACompressor())
encoder.stream_dns_to_file(DNS_OUT_FILE + ".xz",
compressor=lzma.LZMACompressor())
else:
encoder.stream_flowlogs_to_file(FLOWLOG_OUT_FILE, compressor=None)
encoder.stream_dns_to_file(DNS_OUT_FILE, compressor=None)
reader.close()