change some things in install.sh again
This commit is contained in:
parent
cd83de6696
commit
d948998ac3
2 changed files with 8 additions and 90 deletions
14
install.sh
14
install.sh
|
@ -4,29 +4,31 @@
|
||||||
## Installetion script for GeoStat
|
## Installetion script for GeoStat
|
||||||
## Alexey Nizhegolenko 2018
|
## Alexey Nizhegolenko 2018
|
||||||
##
|
##
|
||||||
|
echo ""
|
||||||
echo "Creating virtual ENV and installing requirements..."
|
echo "Creating virtual ENV and installing requirements..."
|
||||||
virtualenv venv && source venv/bin/activate
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
virtualenv venv && source venv/bin/activate
|
||||||
|
|
||||||
pip install -r requirements.txt && deactivate
|
pip install -r requirements.txt && deactivate
|
||||||
sleep 1
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
echo "Please edit settings.ini file and set right parameters..."
|
echo "Please edit settings.ini file and set right parameters..."
|
||||||
|
sleep 1
|
||||||
cp settings.ini.back settings.ini
|
cp settings.ini.back settings.ini
|
||||||
|
|
||||||
"${VISUAL:-"${EDITOR:-vi}"}" "settings.ini"
|
"${VISUAL:-"${EDITOR:-vi}"}" "settings.ini"
|
||||||
|
|
||||||
|
echo ""
|
||||||
echo "Installing SystemD service..."
|
echo "Installing SystemD service..."
|
||||||
|
sleep 1
|
||||||
while read line
|
while read line
|
||||||
do
|
do
|
||||||
eval echo "$line"
|
eval echo "$line"
|
||||||
done < "./geostat.service.template" > /lib/systemd/system/geostat.service
|
done < "./geostat.service.template" > /lib/systemd/system/geostat.service
|
||||||
|
|
||||||
systemctl enable geostat.service
|
systemctl enable geostat.service
|
||||||
sleep 1
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
echo "All done, now you can start getting GEO data from your log"
|
echo "All done, now you can start getting GEO data from your log"
|
||||||
echo "run 'systemd start geostat.service' for this"
|
echo "run 'systemctl start geostat.service' for this"
|
||||||
echo "Good Luck !"
|
echo "Good Luck !"
|
||||||
|
|
84
parser.py
84
parser.py
|
@ -1,84 +0,0 @@
|
||||||
#! /usr/bin/env python
|
|
||||||
|
|
||||||
|
|
||||||
# Getting GEO information for Nginx access.log IP's.
|
|
||||||
# Alexey Nizhegolenko 2018
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
# import sys
|
|
||||||
import json
|
|
||||||
import pygeoip
|
|
||||||
# import subprocess
|
|
||||||
import Geohash
|
|
||||||
import configparser
|
|
||||||
from collections import Counter
|
|
||||||
# from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
def logparse(logpath):
|
|
||||||
GI = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.const.MEMORY_CACHE)
|
|
||||||
GETIP = r"^(?P<remote_host>[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3})"
|
|
||||||
IPS = Counter()
|
|
||||||
with open(logpath, "r") as file:
|
|
||||||
for line in file:
|
|
||||||
IP = re.search(GETIP, line).group(1)
|
|
||||||
if IP:
|
|
||||||
IPS[IP] += 1
|
|
||||||
OUTPUT = []
|
|
||||||
for KEYIP, VALUE in IPS.items():
|
|
||||||
OUTIPS = {}
|
|
||||||
INFO = GI.record_by_addr(KEYIP)
|
|
||||||
if INFO is not None:
|
|
||||||
HASH = Geohash.encode(INFO['latitude'], INFO['longitude'])
|
|
||||||
OUTIPS['ip'] = KEYIP
|
|
||||||
OUTIPS['geohash'] = HASH
|
|
||||||
OUTIPS['count'] = VALUE
|
|
||||||
OUTPUT.append(OUTIPS)
|
|
||||||
|
|
||||||
return OUTPUT
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
def logparse(logpath):
|
|
||||||
GI = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.const.MEMORY_CACHE)
|
|
||||||
GETIP = r"^(?P<remote_host>[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3})"
|
|
||||||
OUTPUT = []
|
|
||||||
IPS = {}
|
|
||||||
with open(logpath, "r") as file:
|
|
||||||
for line in file:
|
|
||||||
IP = re.search(GETIP, line)
|
|
||||||
if IP:
|
|
||||||
INFO = GI.record_by_addr(IP.group(1))
|
|
||||||
if INFO is not None:
|
|
||||||
HASH = Geohash.encode(INFO['latitude'], INFO['longitude'])
|
|
||||||
# IPS['key'] = INFO['country_code']
|
|
||||||
# IPS['name'] = INFO['country_name']
|
|
||||||
IPS['ip'] = IP.group(1)
|
|
||||||
IPS['geohash'] = HASH
|
|
||||||
# IPS['data'] = {'latitude': INFO['latitude'], 'longitude': INFO['longitude']} # NOQA
|
|
||||||
# IPS['latitude'] = INFO['latitude']
|
|
||||||
# IPS['longitude'] = INFO['longitude']
|
|
||||||
OUTPUT.append(IPS)
|
|
||||||
return OUTPUT
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Set LANG ENV
|
|
||||||
os.environ["LC_ALL"] = "C"
|
|
||||||
# Getting params from config
|
|
||||||
pwd = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read('%s/settings.ini' % pwd)
|
|
||||||
logpath = config.get('NGINX_LOG', 'logpath')
|
|
||||||
# Parse given log file
|
|
||||||
IPS_IN = logparse(logpath)
|
|
||||||
# Send result to fle
|
|
||||||
with open('/tmp/metrics.json', 'w') as outputfile:
|
|
||||||
json.dump(IPS_IN, outputfile, indent=4, sort_keys=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in a new issue