mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
log message split error + perf
fix: log message split errors perf: string affected at start doc: comments
This commit is contained in:
parent
519560b0c8
commit
4d6de7a397
1 changed files with 23 additions and 4 deletions
27
bin/Tags.py
27
bin/Tags.py
|
@ -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__':
|
||||
|
|
Loading…
Reference in a new issue