Skip to content

Commit

Permalink
Revert "Add ZMQ publisher."
Browse files Browse the repository at this point in the history
This reverts commit 18ce2f8.
  • Loading branch information
Rafiot committed Aug 4, 2014
1 parent 18ce2f8 commit c1bde7d
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions lib/modules/helper.py
Expand Up @@ -10,15 +10,6 @@
import importlib
import sys
from pubsublogger import publisher
try:
import zmq
has_zmq = True
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)
except:
has_zmq = False

separator = '|'
key_ip = 'ip'
Expand All @@ -32,19 +23,17 @@

temp_db = None


def __prepare():
global temp_db

config = ConfigParser.RawConfigParser()
config_file = "/etc/bgpranking/bgpranking.conf"
config.read(config_file)

temp_db = redis.Redis(port=int(config.get('redis', 'port_cache')),
db=int(config.get('redis', 'temp')))
temp_db = redis.Redis(port = int(config.get('redis','port_cache')),
db=int(config.get('redis','temp')))
sys.path.append(os.path.dirname(__file__))


def new_entry(ip, source, timestamp):
"""
insert a new entry in redis
Expand All @@ -56,9 +45,6 @@ def new_entry(ip, source, timestamp):
p.hmset(uid, {key_ip: ip, key_src: source, key_tstamp: timestamp})
p.sadd(key_uid_list, uid)
p.execute()
if has_zmq:
socket.send('"{}","{}","{}"'.format(source, timestamp, ip))


def __get_files(directory):
"""
Expand All @@ -72,20 +58,18 @@ def __get_files(directory):
files.append(f)
return files


def __default_parser(filename, listname, date):
"""
Search for IPs on each line of the files in that dir
"""
with open(filename, 'r') as f:
for line in f:
ip = re.findall('((?:\d{1,3}\.){3}\d{1,3})', line)
ip = re.findall('((?:\d{1,3}\.){3}\d{1,3})',line)
if len(ip) == 0:
continue
new_entry(ip[0], listname, date)
return date


def importer(raw_dir, listname):
publisher.channel = 'ParseRawFiles'
has_files = False
Expand All @@ -105,7 +89,8 @@ def importer(raw_dir, listname):
os.rename(filename, os.path.join(raw_dir, old_dir, date.isoformat()))
except:
new_file = os.path.join(raw_dir, old_dir,
'INVALID_' + str(date).replace(' ', '-'))
'INVALID_' + str(date).replace(' ','-'))
os.rename(filename, new_file)
publisher.error('Invalid file: ' + new_file)
return has_files

0 comments on commit c1bde7d

Please sign in to comment.