Fix for multiple connect_time values, #12

This commit is contained in:
gilbn 2022-03-13 21:35:19 +01:00
parent abaa555a7a
commit 9144e64be6

View file

@ -203,7 +203,7 @@ def logparse(
ip_type = ipadd(ip).iptype() ip_type = ipadd(ip).iptype()
if ip_type in monitored_ip_types and ip: if ip_type in monitored_ip_types and ip:
info = gi.city(ip) info = gi.city(ip)
if info is not None: if info:
geohash = encode(info.location.latitude, info.location.longitude) geohash = encode(info.location.latitude, info.location.longitude)
geohash_fields['count'] = 1 geohash_fields['count'] = 1
geohash_tags['geohash'] = geohash geohash_tags['geohash'] = geohash
@ -234,15 +234,15 @@ def logparse(
data = search(log, line) data = search(log, line)
if ip_type in monitored_ip_types and ip: if ip_type in monitored_ip_types and ip:
info = gi.city(ip) info = gi.city(ip)
if info is not None: if info:
datadict = data.groupdict() datadict = data.groupdict()
log_data_fields['count'] = 1 log_data_fields['count'] = 1
log_data_fields['bytes_sent'] = int(datadict['bytes_sent']) log_data_fields['bytes_sent'] = int(datadict['bytes_sent'])
log_data_fields['request_time'] = float(datadict['request_time']) log_data_fields['request_time'] = float(datadict['request_time'])
if datadict['connect_time'] == '-': try:
log_data_fields['connect_time'] = 0.0 log_data_fields['connect_time'] = float(datadict['connect_time']) if datadict['connect_time'] != '-' else 0.0
else: except ValueError:
log_data_fields['connect_time'] = float(datadict['connect_time']) log_data_fields['connect_time'] = str(datadict['connect_time'])
log_data_tags['ip'] = datadict['ipaddress'] log_data_tags['ip'] = datadict['ipaddress']
log_data_tags['datetime'] = datetime.strptime(datadict['dateandtime'], '%d/%b/%Y:%H:%M:%S %z') log_data_tags['datetime'] = datetime.strptime(datadict['dateandtime'], '%d/%b/%Y:%H:%M:%S %z')
log_data_tags['remote_user'] = datadict['remote_user'] log_data_tags['remote_user'] = datadict['remote_user']