From 6e6c01a34173f59f1bef802d7bbdf779f36d5ca0 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 2 Feb 2019 16:27:03 +0100 Subject: [PATCH] chg: [pdns analyzer] proper logging --- bin/pdns-ingestion.py | 24 +++++++++++++++++++----- etc/analyzer.conf.sample | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/pdns-ingestion.py b/bin/pdns-ingestion.py index 7a81c2d..13a60a2 100644 --- a/bin/pdns-ingestion.py +++ b/bin/pdns-ingestion.py @@ -4,16 +4,31 @@ import fileinput import json import configparser import time +import logging +import sys config = configparser.RawConfigParser() config.read('../etc/analyzer.conf') myuuid = config.get('global', 'my-uuid') myqueue = "analyzer:8:{}".format(myuuid) -print (myqueue) +mylogginglevel = config.get('global', 'logging-level') +logger = logging.getLogger('pdns ingestor') +ch = logging.StreamHandler() +if mylogginglevel == 'DEBUG': + logger.setLevel(logging.DEBUG) + ch.setLevel(logging.DEBUG) +elif mylogginglevel == 'INFO': + logger.setLevel(logging.INFO) + ch.setLevel(logging.INFO) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +ch.setFormatter(formatter) +logger.addHandler(ch) + +logger.info("Starting and using FIFO {} from D4 server".format(myqueue)) + d4_server = config.get('global', 'd4-server') r = redis.Redis(host="127.0.0.1",port=6400) - r_d4 = redis.Redis(host=d4_server.split(':')[0], port=d4_server.split(':')[1], db=2) @@ -63,7 +78,7 @@ while (True): continue l = d4_record_line.decode('utf-8') rdns = process_format_passivedns(line=l.strip()) - print (rdns) + logger.debug((rdns)) if rdns is False: # need to add logging when it fails continue @@ -92,7 +107,6 @@ while (True): r.hincrby('dist:type', rdns['type'], amount=1) if stats: r.incrby('stats:processed', amount=1) - print (last) - print (query) if not r: + logger.info('empty passive dns record') continue diff --git a/etc/analyzer.conf.sample b/etc/analyzer.conf.sample index 33dd337..fca4e62 100644 --- a/etc/analyzer.conf.sample +++ b/etc/analyzer.conf.sample @@ -1,3 +1,5 @@ [global] my-uuid = 6a2461ce-c29d-44fc-b4fa-947d68826639 d4-server = 127.0.0.1:6380 +# INFO|DEBUG +logging-level = INFO