-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwineventlog.py
46 lines (36 loc) · 1.38 KB
/
wineventlog.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
import json
import os
import evtx
from statistics import median_low
from datetime import date
# TODO: comment your crap, christian
def initialize(from_date: date):
print("Parsing .evtx logs...")
EVTX_LOCATION = os.fspath(r"\\DCVM-WEB\c$\Windows\System32\winevt\Logs\Application.evtx")
parser = evtx.PyEvtxParser(EVTX_LOCATION)
records = parser.records_json()
# Decode the event log from json strings to a dict, with complete disregard to the inefficiency of doing it this way
record_list = []
for record in records:
try:
date_string = record['timestamp'].split(' ')[0]
event_date = date.fromisoformat(date_string)
if event_date >= from_date:
record_json = json.loads(record['data'])
if record_json['Event']['System']['Level'] <= 3:
record_list.append(record_json['Event']['EventData']['Data']['#text'][0])
except:
pass
record_dict = {}
for item in record_list:
if record_dict.__contains__(item):
record_dict[item] += 1
else:
record_dict[item] = 1
median = median_low(record_dict.values()) + 1
high_errors = []
for item in record_dict.items():
if item[1] >= median:
high_errors.append(item)
high_errors.sort(key=lambda x: x[1], reverse=True)
return high_errors, median