From 9144e64be6a60afd67d91ca2ce782a63462db24b Mon Sep 17 00:00:00 2001 From: gilbn Date: Sun, 13 Mar 2022 21:35:19 +0100 Subject: [PATCH] Fix for multiple connect_time values, #12 --- geoip2influx.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/geoip2influx.py b/geoip2influx.py index 9cb02a3..f151355 100644 --- a/geoip2influx.py +++ b/geoip2influx.py @@ -203,7 +203,7 @@ def logparse( ip_type = ipadd(ip).iptype() if ip_type in monitored_ip_types and ip: info = gi.city(ip) - if info is not None: + if info: geohash = encode(info.location.latitude, info.location.longitude) geohash_fields['count'] = 1 geohash_tags['geohash'] = geohash @@ -234,15 +234,15 @@ def logparse( data = search(log, line) if ip_type in monitored_ip_types and ip: info = gi.city(ip) - if info is not None: + if info: datadict = data.groupdict() log_data_fields['count'] = 1 log_data_fields['bytes_sent'] = int(datadict['bytes_sent']) log_data_fields['request_time'] = float(datadict['request_time']) - if datadict['connect_time'] == '-': - log_data_fields['connect_time'] = 0.0 - else: - log_data_fields['connect_time'] = float(datadict['connect_time']) + try: + log_data_fields['connect_time'] = float(datadict['connect_time']) if datadict['connect_time'] != '-' else 0.0 + except ValueError: + log_data_fields['connect_time'] = str(datadict['connect_time']) log_data_tags['ip'] = datadict['ipaddress'] log_data_tags['datetime'] = datetime.strptime(datadict['dateandtime'], '%d/%b/%Y:%H:%M:%S %z') log_data_tags['remote_user'] = datadict['remote_user']