Merge pull request #3 from MatStace/handle-rfc1918

little tweak to not throw an exception on RFC1918 IP address
This commit is contained in:
Alexey Nizhegolenko 2019-06-11 16:02:03 +03:00 committed by GitHub
commit 75b79f3fe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import geoip2.database
import Geohash
import configparser
from influxdb import InfluxDBClient
from IPy import IP as ipadd
def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSERPASS, MEASUREMENT, GEOIPDB, INODE): # NOQA
# Preparing variables and params
@ -52,7 +53,7 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
m = re_IPV6.match(LINE)
IP = m.group(1)
if IP:
if ipadd(IP).iptype() == 'PUBLIC' and IP:
INFO = GI.city(IP)
if INFO is not None:
HASH = Geohash.encode(INFO.location.latitude, INFO.location.longitude) # NOQA

View file

@ -2,3 +2,4 @@ configparser==3.5.0
influxdb==5.2.0
Geohash==1.0
geoip2==2.9.0
IPy==1.00