diff --git a/alb-s3-sqs-es/alb_s3/geoip/GeoLite2-City_20210518/GeoLite2-City.mmdb b/alb-s3-sqs-es/alb_s3/geoip/GeoLite2-City_20210518/GeoLite2-City.mmdb index a50bfa1..69df2ab 100644 Binary files a/alb-s3-sqs-es/alb_s3/geoip/GeoLite2-City_20210518/GeoLite2-City.mmdb and b/alb-s3-sqs-es/alb_s3/geoip/GeoLite2-City_20210518/GeoLite2-City.mmdb differ diff --git a/alb-s3-sqs-es/alb_s3/ingester/message.py b/alb-s3-sqs-es/alb_s3/ingester/message.py index 5ceea73..3a65295 100644 --- a/alb-s3-sqs-es/alb_s3/ingester/message.py +++ b/alb-s3-sqs-es/alb_s3/ingester/message.py @@ -72,11 +72,22 @@ def __init__(self, log_msg): if "user_agent" in self.message: user_agent = parse(self.message["user_agent"]) user_agent_details = {} - user_agent_details["browser"] = user_agent.get_browser() - user_agent_details["os"] = user_agent.get_os() - user_agent_details["device"] = user_agent.get_device() + user_agent_details["browser"] = user_agent.browser.family + user_agent_details["browser_version"] = user_agent.browser.version_string + user_agent_details["os"] = user_agent.os.family + user_agent_details["os_version"] = user_agent.os.version_string + user_agent_details["device_family"] = user_agent.device.family + user_agent_details["device_brand"] = user_agent.device.brand + user_agent_details["device_model"] = user_agent.device.model + user_agent_details["is_pc"] = user_agent.is_pc user_agent_details["is_bot"] = user_agent.is_bot + user_agent_details["is_mobile"] = user_agent.is_mobile + user_agent_details["is_tablet"] = user_agent.is_tablet + user_agent_details["user_agent"] = user_agent.ua_string + self.message["user_agent_details"] = user_agent_details + #pop the old key + del self.message['user_agent'] # GeoIP Lookup if self.message["client_ip"] is not None: @@ -108,11 +119,12 @@ def __init__(self, log_msg): ] = geo_ip_response.subdivisions.most_specific.name if geo_ip_response.location is not None: - location = { - "lon": geo_ip_response.location.longitude, - "lat": geo_ip_response.location.latitude, - } - geoip_details["location"] = location + if geo_ip_response.location.longitude is not None: + location = { + "lon": geo_ip_response.location.longitude, + "lat": geo_ip_response.location.latitude, + } + geoip_details["location"] = location self.message["client_geoip"] = geoip_details # Expand Request details diff --git a/alb-s3-sqs-es/tests/test_message.py b/alb-s3-sqs-es/tests/test_message.py index fc8e890..db739ba 100644 --- a/alb-s3-sqs-es/tests/test_message.py +++ b/alb-s3-sqs-es/tests/test_message.py @@ -17,8 +17,15 @@ def test_app_loadbalancer_log_https_useragent(loadbalancer_https_entry): msg = loadbalancer_https_entry.payload() assert msg['type'] == 'https' - assert msg['user_agent'].startswith('Mozilla/5.0 (Macintosh;') - assert msg['user_agent_details']['browser'] == 'Firefox 88.0' - assert msg['user_agent_details']['os'] == 'Mac OS X 10.15' - assert msg['user_agent_details']['device'] == 'PC' + assert msg['user_agent_details']['user_agent'].startswith('Mozilla/5.0 (Macintosh;') + assert msg['user_agent_details']['browser'] == 'Firefox' + assert msg['user_agent_details']['browser_version'] == '88.0' + assert msg['user_agent_details']['os'] == 'Mac OS X' + assert msg['user_agent_details']['os_version'] == '10.15' + assert msg['user_agent_details']['device_family'] == 'Mac' + assert msg['user_agent_details']['device_brand'] == 'Apple' + assert msg['user_agent_details']['device_model'] == 'Mac' + assert msg['user_agent_details']['is_pc'] is True assert msg['user_agent_details']['is_bot'] is False + assert msg['user_agent_details']['is_tablet'] is False + assert msg['user_agent_details']['is_mobile'] is False