Added some changes with new GEOIP data file and fix some BUGs

This commit is contained in:
Alexey 2019-02-12 11:17:15 +02:00
parent 04f43c4bc6
commit 26be286582
4 changed files with 19 additions and 13 deletions

View file

@ -60,8 +60,9 @@ $ cp geostat.service /lib/systemd/system/
``` ```
3) Download latest GeoLiteCity.dat from MaxMind 3) Download latest GeoLiteCity.dat from MaxMind
```sh ```sh
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz $ wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
$ gunzip GeoLiteCity.dat.gz $ tar -xvf GeoLite2-City.tar.gz
$ cp ./GeoLite2-City_some-date/GeoLite2-City.mmdb ./
``` ```
4) Then enable and start service 4) Then enable and start service
```sh ```sh

View file

@ -25,7 +25,7 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
username=INFLUXUSER, password=INFLUXUSERPASS, database=INFLUXDBDB) # NOQA username=INFLUXUSER, password=INFLUXUSERPASS, database=INFLUXDBDB) # NOQA
re_IPV4 = re.compile('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') 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) GI = geoip2.database.Reader(GEOIPDB)
@ -45,12 +45,12 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
time.sleep(1) time.sleep(1)
FILE.seek(WHERE) FILE.seek(WHERE)
else: else:
if re_IPV4.match(LINE): if re_IPV4.match(LINE):
m = re_IPV4.match(LINE) m = re_IPV4.match(LINE)
IP = m.group(1) IP = m.group(1)
elif re_IPV6.match(LINE): elif re_IPV6.match(LINE):
m = re_IPV6.match(LINE) m = re_IPV6.match(LINE)
IP = m.group(1) IP = m.group(1)
if IP: if IP:
INFO = GI.city(IP) INFO = GI.city(IP)

View file

@ -5,11 +5,16 @@
## Alexey Nizhegolenko 2018 ## Alexey Nizhegolenko 2018
## ##
WORKDIR=$(pwd)
echo "" echo ""
echo "Downloading latest GeoLiteCity.dat from MaxMind" echo "Downloading latest GeoLiteCity.dat from MaxMind"
sleep 1 sleep 1
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
gunzip GeoLiteCity.dat.gz mkdir tmpgeo
tar -xvf GeoLite2-City.tar.gz -C ./tmpgeo && cd ./tmpgeo/*/.
cp ./GeoLite2-City.mmdb $WORKDIR
cd $WORKDIR
echo "" echo ""
echo "Creating virtual ENV and installing requirements..." echo "Creating virtual ENV and installing requirements..."

View file

@ -3,8 +3,8 @@
logpath = /var/log/nginx/access.log logpath = /var/log/nginx/access.log
[GEOIP] [GEOIP]
geoipdb = /usr/local/share/GeoIP/GeoLite2-City.mmdb #Path for the GEOIP DB file
# For country use /usr/local/share/GeoIP/GeoLite2-Country.mmdb geoipdb = ./GeoLite2-City.mmdb
[INFLUXDB] [INFLUXDB]
# Database URL # Database URL