From 782be7794bd8452765507fe254c8cdef28b7a3df Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 21 Mar 2021 10:12:27 +0100 Subject: [PATCH] More robust logic to deal with broken lines in HTTP logs --- platypush/backend/log/http.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platypush/backend/log/http.py b/platypush/backend/log/http.py index bcb64863..dc9a5fe0 100644 --- a/platypush/backend/log/http.py +++ b/platypush/backend/log/http.py @@ -100,18 +100,27 @@ class LogEventHandler(EventHandler): logger.warning('Could not parse log line from {}: {}'.format(file, line)) return + url = None + method = 'GET' + http_version = '1.0' + try: + url = m.group(5).split(' ')[1] + method = m.group(5).split(' ')[0] http_version = m.group(5).split(' ')[2].split('/')[1] except: - http_version = '1.0' + pass + + if not url: + return info = { 'address': m.group(1), 'user_identifier': m.group(2), 'user_id': m.group(3), 'time': datetime.datetime.strptime(m.group(4), '%d/%b/%Y:%H:%M:%S %z'), - 'method': m.group(5).split(' ')[0], - 'url': m.group(5).split(' ')[1], + 'method': method, + 'url': url, 'http_version': http_version, 'status': int(m.group(6)), 'size': int(m.group(7)),