Added some changes with new GEOIP data file and fix some BUGs
This commit is contained in:
parent
04f43c4bc6
commit
26be286582
4 changed files with 19 additions and 13 deletions
|
@ -60,8 +60,9 @@ $ cp geostat.service /lib/systemd/system/
|
|||
```
|
||||
3) Download latest GeoLiteCity.dat from MaxMind
|
||||
```sh
|
||||
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
|
||||
$ gunzip GeoLiteCity.dat.gz
|
||||
$ wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
|
||||
$ tar -xvf GeoLite2-City.tar.gz
|
||||
$ cp ./GeoLite2-City_some-date/GeoLite2-City.mmdb ./
|
||||
```
|
||||
4) Then enable and start service
|
||||
```sh
|
||||
|
|
14
geoparser.py
14
geoparser.py
|
@ -25,7 +25,7 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
|
|||
username=INFLUXUSER, password=INFLUXUSERPASS, database=INFLUXDBDB) # NOQA
|
||||
|
||||
re_IPV4 = re.compile('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
|
||||
re_IPV6 = re.compile('(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))')
|
||||
re_IPV6 = re.compile('(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))') # NOQA
|
||||
|
||||
GI = geoip2.database.Reader(GEOIPDB)
|
||||
|
||||
|
@ -45,12 +45,12 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
|
|||
time.sleep(1)
|
||||
FILE.seek(WHERE)
|
||||
else:
|
||||
if re_IPV4.match(LINE):
|
||||
m = re_IPV4.match(LINE)
|
||||
IP = m.group(1)
|
||||
elif re_IPV6.match(LINE):
|
||||
m = re_IPV6.match(LINE)
|
||||
IP = m.group(1)
|
||||
if re_IPV4.match(LINE):
|
||||
m = re_IPV4.match(LINE)
|
||||
IP = m.group(1)
|
||||
elif re_IPV6.match(LINE):
|
||||
m = re_IPV6.match(LINE)
|
||||
IP = m.group(1)
|
||||
|
||||
if IP:
|
||||
INFO = GI.city(IP)
|
||||
|
|
|
@ -5,11 +5,16 @@
|
|||
## Alexey Nizhegolenko 2018
|
||||
##
|
||||
|
||||
WORKDIR=$(pwd)
|
||||
|
||||
echo ""
|
||||
echo "Downloading latest GeoLiteCity.dat from MaxMind"
|
||||
sleep 1
|
||||
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
|
||||
gunzip GeoLiteCity.dat.gz
|
||||
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
|
||||
mkdir tmpgeo
|
||||
tar -xvf GeoLite2-City.tar.gz -C ./tmpgeo && cd ./tmpgeo/*/.
|
||||
cp ./GeoLite2-City.mmdb $WORKDIR
|
||||
cd $WORKDIR
|
||||
|
||||
echo ""
|
||||
echo "Creating virtual ENV and installing requirements..."
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
logpath = /var/log/nginx/access.log
|
||||
|
||||
[GEOIP]
|
||||
geoipdb = /usr/local/share/GeoIP/GeoLite2-City.mmdb
|
||||
# For country use /usr/local/share/GeoIP/GeoLite2-Country.mmdb
|
||||
#Path for the GEOIP DB file
|
||||
geoipdb = ./GeoLite2-City.mmdb
|
||||
|
||||
[INFLUXDB]
|
||||
# Database URL
|
||||
|
|
Loading…
Reference in a new issue