-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
run.py
35 lines (31 loc) · 1.02 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import os
import logging
import signal
from geoip2influx import LogParser, configure_logging
from dotenv import load_dotenv
load_dotenv()
def handle_sigterm(signum, frame):
logger = logging.getLogger("g2i")
logger.info("Received SIGTERM. Exiting GeoIP2Influx.")
try:
parser.client.influx.close()
except Exception:
logger.exception("Error closing InfluxDB client.")
logger.info("Parsed %d log line(s).", parser.parsed_lines)
exit(0)
if __name__ == "__main__":
try:
configure_logging(os.getenv("GEOIP2INFLUX_LOG_LEVEL", "debug"))
signal.signal(signal.SIGTERM, handle_sigterm)
logger = logging.getLogger("g2i")
logger.info("Starting GeoIP2Influx.")
parser = LogParser()
parser.run()
except KeyboardInterrupt:
logger.info("Exiting GeoIP2Influx.")
logger.info("Parsed %d log line(s).", parser.parsed_lines)
exit(0)
except Exception:
logger.exception("Error running parser.")
exit(1)