-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotate-calcium
42 lines (35 loc) · 1.13 KB
/
annotate-calcium
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
#!/usr/bin/env python3
from glob import glob
from datetime import datetime
def load_logs():
logs = dict()
for filename in glob("/var/log/httpd/ssl_mgb_log*"):
for line in open(filename, "r").read().splitlines():
dt, _, ip, mgb, query = line.split(" ", 4)
if query == "-":
continue
dt = dt[1:]
dtobj = datetime.strptime(dt, "%d/%b/%Y:%H:%M:%S")
logs[(dtobj, ip)] = (mgb, query)
return logs
def annotate_calcium(logs):
for line in (
open("/var/www/cgi-bin/CalciumDir40/data/CalciumAuditLog", "rb")
.read()
.decode("ascii")
.split("\n")
):
try:
d, t, ip, action = line.split(" ", 3)
dtobj = datetime.strptime(" ".join((d, t)), "%Y/%m/%d %H:%M:%S")
except ValueError:
continue
try:
match = logs[(dtobj, ip)]
except KeyError:
match = ("?", "?")
print(f"{match[0]} {line} # {match[1]}")
# Press the green button in the gutter to run the script.
if __name__ == "__main__":
logs = load_logs()
annotate_calcium(logs)