Adds server specific conditions
This commit is contained in:
@@ -2,12 +2,20 @@ import os
|
||||
import re
|
||||
import json
|
||||
|
||||
absPath = os.path.dirname(os.path.abspath(__file__))
|
||||
logPath = '/var/log/nginx/'
|
||||
logFiles = ['access.log', 'pajonk.kavalanche.net.access.log', 'stock.kavalanche.net.access.log', 'todolist.kavalanche.net.access.log']
|
||||
output = []
|
||||
|
||||
with open(absPath + os.sep + 'access.log', 'r') as f:
|
||||
logs = f.readlines()
|
||||
f.close()
|
||||
for logFile in logFiles:
|
||||
with open(logPath + logFile, 'r') as f:
|
||||
logs = f.readlines()
|
||||
f.close()
|
||||
|
||||
for log in logs:
|
||||
regex = re.match('(?P<remote_addr>\d+\.\d+\.\d+\.\d+)\s-\s(?P<remote_user>[^\s]+)\s\[(?P<time_local>[^\]]+)\]\s"(?P<request>[^"]+)"\s(?P<status>\d+)\s(?P<body_bytes_sent>\d+)\s"(?P<http_referer>[^"]+)"\s"(?P<http_user_agent>[^"]+)"', log)
|
||||
print(json.dumps(regex.groupdict()))
|
||||
logsInFile = []
|
||||
|
||||
for log in logs:
|
||||
regex = re.match('(?P<remote_addr>\d+\.\d+\.\d+\.\d+)\s-\s(?P<remote_user>[^\s]+)\s\[(?P<time_local>[^\]]+)\]\s"(?P<request>[^"]+)"\s(?P<status>\d+)\s(?P<body_bytes_sent>\d+)\s"(?P<http_referer>[^"]+)"\s"(?P<http_user_agent>[^"]+)"', log)
|
||||
logsInFile.append(regex.groupdict())
|
||||
output.append({logFile: logsInFile})
|
||||
|
||||
print(json.dumps(output))
|
||||
|
||||
Reference in New Issue
Block a user