2018-05-16 14:39:01 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The Tags Module
|
|
|
|
================================
|
|
|
|
|
2021-05-27 17:28:20 +02:00
|
|
|
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
|
|
|
|
##################################
|
2021-06-02 16:04:52 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2021-04-28 15:24:33 +02:00
|
|
|
|
2021-06-02 16:04:52 +02:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
2021-04-28 15:24:33 +02:00
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2021-06-02 16:04:52 +02:00
|
|
|
from modules.abstract_module import AbstractModule
|
2021-05-27 17:28:20 +02:00
|
|
|
from packages.Item import Item
|
2020-01-06 17:07:52 +01:00
|
|
|
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
|
2021-04-30 14:14:46 +02:00
|
|
|
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):
|
2021-05-27 17:28:20 +02:00
|
|
|
# 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])
|
2021-04-30 14:14:46 +02:00
|
|
|
|
|
|
|
# Create a new tag
|
2021-05-27 17:28:20 +02:00
|
|
|
Tag.add_tag('item', tag, item.get_id())
|
2021-10-29 18:48:12 +02:00
|
|
|
print(f'{item.get_id()}: Tagged {tag}')
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-30 14:14:46 +02:00
|
|
|
# Forward message to channel
|
2021-05-27 17:28:20 +02:00
|
|
|
self.send_message_to_queue(message, 'MISP_The_Hive_feeder')
|
2021-10-29 18:48:12 +02:00
|
|
|
|
|
|
|
message = f'{item.get_type()};{item.get_subtype(r_str=True)};{item.get_id()}'
|
2022-05-18 15:46:27 +02:00
|
|
|
self.send_message_to_queue(message, 'SyncModule')
|
2021-10-29 18:48:12 +02:00
|
|
|
|
2021-04-30 14:14:46 +02:00
|
|
|
else:
|
|
|
|
# Malformed message
|
2021-05-27 17:28:20 +02:00
|
|
|
raise Exception(f'too many values to unpack (expected 2) given {len(mess_split)} with message {message}')
|
2019-10-17 16:39:43 +02:00
|
|
|
|
2020-06-19 13:36:03 +02:00
|
|
|
|
2021-04-28 15:24:33 +02:00
|
|
|
if __name__ == '__main__':
|
2021-05-27 17:28:20 +02:00
|
|
|
|
2021-04-28 15:24:33 +02:00
|
|
|
module = Tags()
|
|
|
|
module.run()
|