2016-02-04 15:22:51 +01:00
|
|
|
#!/usr/bin/env python
|
2014-08-06 11:43:40 +02:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The ZMQ_PubSub_Lines Module
|
|
|
|
============================
|
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
This module is consuming the Redis-list created by the ZMQ_PubSub_Line_Q
|
|
|
|
Module.
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
It perform a sorting on the line's length and publish/forward them to
|
|
|
|
differents channels:
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
*Channel 1 if max length(line) < max
|
|
|
|
*Channel 2 if max length(line) > max
|
|
|
|
|
|
|
|
The collected informations about the processed pastes
|
|
|
|
(number of lines and maximum length line) are stored in Redis.
|
|
|
|
|
|
|
|
..note:: Module ZMQ_Something_Q and ZMQ_Something are closely bound, always put
|
|
|
|
the same Subscriber name in both of them.
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
------------
|
|
|
|
|
|
|
|
*Need running Redis instances. (LevelDB & Redis)
|
|
|
|
*Need the ZMQ_PubSub_Line_Q Module running to be able to work properly.
|
|
|
|
|
|
|
|
"""
|
2014-08-14 17:55:18 +02:00
|
|
|
import argparse
|
|
|
|
import time
|
|
|
|
from packages import Paste
|
2014-08-06 11:43:40 +02:00
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
from Helper import Process
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
if __name__ == '__main__':
|
2014-08-22 17:35:40 +02:00
|
|
|
publisher.port = 6380
|
2014-08-29 19:37:56 +02:00
|
|
|
publisher.channel = 'Script'
|
2014-08-14 17:55:18 +02:00
|
|
|
|
2014-08-29 19:37:56 +02:00
|
|
|
config_section = 'Lines'
|
|
|
|
p = Process(config_section)
|
2014-08-20 15:14:57 +02:00
|
|
|
|
2014-08-06 11:43:40 +02:00
|
|
|
# SCRIPT PARSER #
|
|
|
|
parser = argparse.ArgumentParser(
|
2014-08-29 19:37:56 +02:00
|
|
|
description='This script is a part of the Analysis Information \
|
|
|
|
Leak framework.')
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-20 15:14:57 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'-max', type=int, default=500,
|
|
|
|
help='The limit between "short lines" and "long lines"',
|
|
|
|
action='store')
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# FUNCTIONS #
|
2014-08-20 15:14:57 +02:00
|
|
|
tmp_string = "Lines script Subscribed to channel {} and Start to publish \
|
2014-08-29 19:37:56 +02:00
|
|
|
on channel Longlines, Shortlines"
|
|
|
|
publisher.info(tmp_string)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
2014-08-29 19:37:56 +02:00
|
|
|
message = p.get_from_set()
|
|
|
|
print message
|
2014-08-14 17:55:18 +02:00
|
|
|
if message is not None:
|
2014-08-29 19:37:56 +02:00
|
|
|
PST = Paste.Paste(message)
|
2014-08-06 11:43:40 +02:00
|
|
|
else:
|
|
|
|
publisher.debug("Tokeniser is idling 10s")
|
|
|
|
time.sleep(10)
|
|
|
|
continue
|
|
|
|
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME do it in the paste class
|
2014-08-06 11:43:40 +02:00
|
|
|
lines_infos = PST.get_lines_info()
|
2014-08-21 12:22:07 +02:00
|
|
|
PST.save_attribute_redis("p_nb_lines", lines_infos[0])
|
|
|
|
PST.save_attribute_redis("p_max_length_line", lines_infos[1])
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-21 14:39:17 +02:00
|
|
|
# FIXME Not used.
|
2014-08-21 12:22:07 +02:00
|
|
|
PST.store.sadd("Pastes_Objects", PST.p_path)
|
2014-08-29 19:37:56 +02:00
|
|
|
if lines_infos[1] < args.max:
|
|
|
|
p.populate_set_out(PST.p_path, 'LinesShort')
|
2014-08-06 11:43:40 +02:00
|
|
|
else:
|
2014-08-29 19:37:56 +02:00
|
|
|
p.populate_set_out(PST.p_path, 'LinesLong')
|
2014-08-06 11:43:40 +02:00
|
|
|
except IOError:
|
|
|
|
print "CRC Checksum Error on : ", PST.p_path
|