add support for multiple log-files
This commit is contained in:
parent
92518aed55
commit
b4456d9080
66
tsstats.py
66
tsstats.py
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import glob
|
||||||
import json
|
import json
|
||||||
import configparser
|
import configparser
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
@ -135,37 +136,40 @@ def check_client(clid, nick):
|
||||||
clients[clid] = {}
|
clients[clid] = {}
|
||||||
clients[clid]['nick'] = nick
|
clients[clid]['nick'] = nick
|
||||||
|
|
||||||
|
log_files = [file_name for file_name in glob.glob(log_path)]
|
||||||
with open(log_path, 'r') as f:
|
log_lines = []
|
||||||
today = datetime.utcnow()
|
for log_file in log_files:
|
||||||
for line in f:
|
for line in open(log_file, 'r'):
|
||||||
parts = line.split('|')
|
log_lines.append(line)
|
||||||
logdatetime = datetime.strptime(parts[0], '%Y-%m-%d %H:%M:%S.%f')
|
today = datetime.utcnow()
|
||||||
sid = int(parts[3].strip())
|
for line in log_lines:
|
||||||
data = '|'.join(parts[4:]).strip()
|
parts = line.split('|')
|
||||||
if data.startswith('client'):
|
logdatetime = datetime.strptime(parts[0], '%Y-%m-%d %H:%M:%S.%f')
|
||||||
r = cldata.findall(data)[0]
|
sid = int(parts[3].strip())
|
||||||
nick = r[0]
|
data = '|'.join(parts[4:]).strip()
|
||||||
clid = r[1]
|
if data.startswith('client'):
|
||||||
if clid in id_map:
|
r = cldata.findall(data)[0]
|
||||||
clid = id_map[clid]
|
nick = r[0]
|
||||||
if data.startswith('client connected'):
|
clid = r[1]
|
||||||
add_connect(clid, nick, logdatetime)
|
if clid in id_map:
|
||||||
elif data.startswith('client disconnected'):
|
clid = id_map[clid]
|
||||||
add_disconnect(clid, nick, logdatetime)
|
if data.startswith('client connected'):
|
||||||
if 'bantime' in data:
|
add_connect(clid, nick, logdatetime)
|
||||||
add_pban(clid, nick)
|
elif data.startswith('client disconnected'):
|
||||||
elif 'invokerid' in data:
|
add_disconnect(clid, nick, logdatetime)
|
||||||
add_pkick(clid, nick)
|
if 'bantime' in data:
|
||||||
r = cldata_invoker.findall(data)[0]
|
add_pban(clid, nick)
|
||||||
nick = r[0]
|
elif 'invokerid' in data:
|
||||||
cluid = r[1]
|
add_pkick(clid, nick)
|
||||||
add_kick(cluid, nick)
|
r = cldata_invoker.findall(data)[0]
|
||||||
elif data.startswith('ban added') and 'cluid' in data:
|
nick = r[0]
|
||||||
r = cldata_ban.findall(data)[0]
|
cluid = r[1]
|
||||||
nick = r[0]
|
add_kick(cluid, nick)
|
||||||
clid = r[1]
|
elif data.startswith('ban added') and 'cluid' in data:
|
||||||
add_ban(clid, nick)
|
r = cldata_ban.findall(data)[0]
|
||||||
|
nick = r[0]
|
||||||
|
clid = r[1]
|
||||||
|
add_ban(clid, nick)
|
||||||
|
|
||||||
for clid in clients:
|
for clid in clients:
|
||||||
if 'connected' not in clients[clid]:
|
if 'connected' not in clients[clid]:
|
||||||
|
|
Loading…
Reference in New Issue