AIL-framework/bin/modules/Tags.py

65 lines
1.6 KiB
Python
Raw Normal View History

2018-05-16 14:39:01 +02:00
#!/usr/bin/env python3
# -*-coding:UTF-8 -*
"""
The Tags Module
================================
This module add tags to an item.
2018-05-16 14:39:01 +02:00
"""
2021-04-28 15:24:33 +02:00
##################################
# Import External packages
##################################
import os
import sys
2021-04-28 15:24:33 +02:00
sys.path.append(os.environ['AIL_BIN'])
2021-04-28 15:24:33 +02:00
##################################
# Import Project packages
##################################
from modules.abstract_module import AbstractModule
from packages.Item import Item
from packages import Tag
2019-02-18 14:33:34 +01:00
2018-05-16 14:39:01 +02:00
2021-04-28 15:24:33 +02:00
class Tags(AbstractModule):
"""
Tags module for AIL framework
"""
def __init__(self):
super(Tags, self).__init__()
2018-05-16 14:39:01 +02:00
2021-04-28 15:24:33 +02:00
# Waiting time in secondes between to message proccessed
self.pending_seconds = 10
2018-05-16 14:39:01 +02:00
2021-04-28 15:24:33 +02:00
# Send module state to logs
self.redis_logger.info(f'Module {self.module_name} initialized')
2018-05-16 14:39:01 +02:00
2021-04-28 15:24:33 +02:00
def compute(self, message):
# Extract item ID and tag from message
mess_split = message.split(';')
if len(mess_split) == 2:
tag = mess_split[0]
item = Item(mess_split[1])
item_id = item.get_id()
# Create a new tag
Tag.add_tag('item', tag, item.get_id())
print(f'{item_id}: Tagged {tag}')
2018-05-16 14:39:01 +02:00
# Forward message to channel
self.send_message_to_queue(message, 'MISP_The_Hive_feeder')
else:
# Malformed message
raise Exception(f'too many values to unpack (expected 2) given {len(mess_split)} with message {message}')
2021-04-28 15:24:33 +02:00
if __name__ == '__main__':
2021-04-28 15:24:33 +02:00
module = Tags()
module.run()