diff --git a/README.md b/README.md index 95b839a..439c7db 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Add the ones that differ on your system. | LOG_MEASUREMENT | nginx_access_logs | InfluxDB measurement name for nginx logs. Optional, defaults to the example. | | SEND_NGINX_LOGS | true | Set to `false` to disable nginx logs. Optional, defaults to `true`. | | GEOIP2INFLUX_LOG_LEVEL | info | Sets the log level in geoip2influx.log. Use `debug` for verbose logging Optional, defaults to info. | +| GEOIP2INFLUX_LOG_PATH | /config/log/geoip2influx/geoip2influx.log | Optional. Defaults to example. | | INFLUX_RETENTION | 7d | Sets the retention for the database. Optional, defaults to example.| | INFLUX_SHARD | 1d | Set the shard for the database. Optional, defaults to example. | | MAXMINDDB_LICENSE_KEY | xxxxxxx | Add your Maxmind licence key | diff --git a/geoip2influx.py b/geoip2influx.py index c732ee7..2613fa9 100644 --- a/geoip2influx.py +++ b/geoip2influx.py @@ -31,9 +31,10 @@ geo_measurement = env.get('GEO_MEASUREMENT', 'geoip2influx') log_measurement = env.get('LOG_MEASUREMENT', 'nginx_access_logs') send_nginx_logs = env.get('SEND_NGINX_LOGS','true') log_level = env.get('GEOIP2INFLUX_LOG_LEVEL', 'info').upper() +g2i_log_path = env.get('GEOIP2INFLUX_LOG_PATH','/config/log/geoip2influx/geoip2influx.log') # Logging -logging.basicConfig(level=log_level,format='%(asctime)s :: %(levelname)s :: %(message)s',datefmt='%d/%b/%Y %H:%M:%S',filename=path[0] + '/geoip2influx.log') +logging.basicConfig(level=log_level,format='%(asctime)s :: %(levelname)s :: %(message)s',datefmt='%d/%b/%Y %H:%M:%S',filename=g2i_log_path) def regex_tester(log_path, N): time_out = time() + 60 diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 7e13fa0..0ee3fc5 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -13,11 +13,16 @@ GEO_MEASUREMENT=${GEO_MEASUREMENT}\\n\ LOG_MEASUREMENT=${LOG_MEASUREMENT}\\n\ SEND_NGINX_LOGS=${SEND_NGINX_LOGS}\\n\ GEOIP2INFLUX_LOG_LEVEL=${GEOIP2INFLUX_LOG_LEVEL}\\n\ +GEOIP2INFLUX_LOG_PATH=${GEOIP2INFLUX_LOG_PATH}\\n\ MAXMINDDB_LICENSE_KEY=${MAXMINDDB_LICENSE_KEY}\\n" -mkdir -p /config/geoip2db +mkdir -p \ + /config/geoip2db \ + /config/log/geoip2influx cp -f /geoip2influx/geoip2influx.py /config/geoip2db - +# move old log if needed +if [ -f /config/geoip2db/geoip2influx.log ]; then + mv /config/geoip2db/geoip2influx.log /config/log/geoip2influx # create GeoIP2 folder symlink [[ -d /var/lib/libmaxminddb ]] && [[ ! -L /var/lib/libmaxminddb ]] && \ rm -rf /var/lib/libmaxminddb diff --git a/root/etc/logrotate.d/geoip2influx b/root/etc/logrotate.d/geoip2influx index 8d66dfe..ba181ee 100644 --- a/root/etc/logrotate.d/geoip2influx +++ b/root/etc/logrotate.d/geoip2influx @@ -1,4 +1,4 @@ -/config/geoip2db/geoip2influx.log { +/config/log/geoip2influx/geoip2influx.log { daily rotate 7 size 25M