aboutsummaryrefslogtreecommitdiff
path: root/license_protected_downloads
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-03-21 13:20:12 -0500
committerAndy Doan <andy.doan+gerrit@linaro.org>2016-03-22 13:58:04 +0000
commit3cd2548a03666c32dc1d58dd9462407193fd85f0 (patch)
tree4d8750d06ef653b8e266094220e7d2148b8fc094 /license_protected_downloads
parent4eafaa41b148ade4d2510a1d27f8c5dd6619086f (diff)
add logging for request ip misses
The logic for determining the actual request IP continues to be unusually complicated. We've started getting "bad" IPs over the last few days from builds.96boards.org. Somehow we are getting an ip of "rt504" inserted into the DB which then causes errors when we try to get the GEO IP information. This tries to validate we are storing a "real" IP, and if we hit something we don't expect we log it, so we can try and get an idea why its happening. Change-Id: I0bb36062b434c18651138b0121a415bc0bd98ead Reviewed-on: https://review.linaro.org/11004 Reviewed-by: Andy Doan <andy.doan+gerrit@linaro.org>
Diffstat (limited to 'license_protected_downloads')
-rw-r--r--license_protected_downloads/models.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/license_protected_downloads/models.py b/license_protected_downloads/models.py
index b933b31..2df5009 100644
--- a/license_protected_downloads/models.py
+++ b/license_protected_downloads/models.py
@@ -3,6 +3,7 @@ import datetime
import logging
import uuid
import csv
+import socket
from django.conf import settings
from django.db import models
@@ -36,7 +37,13 @@ def get_ip(request):
if ip:
ip = ip.split(',')[0]
if ip != 'unknown':
- return ip.split(',')[0]
+ ip = ip.split(',')[0]
+ try:
+ socket.inet_aton(ip)
+ return ip
+ except socket.error:
+ # weird field, lets log to try and understand
+ logging.warning('Odd "IP" field: %s = %s', field, ip)
logging.warn('Unable to find request ip: %r', request.META)
return 'unknown'