log message split error + perf

fix: log message split errors
perf: string affected at start
doc: comments
pull/569/head
osagit 2021-04-30 14:14:46 +02:00 committed by GitHub
parent 519560b0c8
commit 4d6de7a397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 4 deletions

View File

@ -29,6 +29,17 @@ class Tags(AbstractModule):
Tags module for AIL framework
"""
# Channel name to forward message
out_channel_name = 'MISP_The_Hive_feeder'
# Split char in incomming message
msg_sep = ';'
# Tag object type
# TODO could be an enum in Tag class
tag_type = 'item'
def __init__(self):
super(Tags, self).__init__()
@ -36,16 +47,24 @@ class Tags(AbstractModule):
self.pending_seconds = 10
# Send module state to logs
self.redis_logger.info(f"Module {self.module_name} initialized")
self.redis_logger.info(f'Module {self.module_name} initialized')
def compute(self, message):
self.redis_logger.debug(message)
tag, item_id = message.split(';')
Tag.add_tag("item", tag, item_id)
if len(message.split(Tags.msg_sep)) == 2:
# Extract item ID and tag from message
tag, item_id = message.split(Tags.msg_sep)
self.process.populate_set_out(message, 'MISP_The_Hive_feeder')
# Create a new tag
Tag.add_tag(Tags.tag_type, tag, item_id)
# Forward message to channel
self.process.populate_set_out(message, Tags.out_channel_name)
else:
# Malformed message
raise Exception(f'too many values to unpack (expected 2) given {len(message.split(Tags.msg_sep))} with message {message}')
if __name__ == '__main__':