ail-framework/bin/modules/Hosts.py

70 lines
1.7 KiB
Python
Raw Normal View History

2022-05-30 07:15:50 +00:00
#!/usr/bin/env python3
# -*-coding:UTF-8 -*
"""
The Hosts Module
======================
This module is consuming the Redis-list created by the Global module.
It is looking for Hosts
"""
##################################
# Import External packages
##################################
import os
import re
import sys
sys.path.append(os.environ['AIL_BIN'])
##################################
# Import Project packages
##################################
from modules.abstract_module import AbstractModule
from lib.ConfigLoader import ConfigLoader
from lib.objects.Items import Item
2022-05-30 07:15:50 +00:00
class Hosts(AbstractModule):
"""
Hosts module for AIL framework
"""
def __init__(self):
super(Hosts, self).__init__()
config_loader = ConfigLoader()
self.r_cache = config_loader.get_redis_conn("Redis_Cache")
# regex timeout
self.regex_timeout = 30
# Waiting time in seconds between to message processed
2022-05-30 07:15:50 +00:00
self.pending_seconds = 1
self.host_regex = r'\b([a-zA-Z\d-]{,63}(?:\.[a-zA-Z\d-]{,63})+)\b'
re.compile(self.host_regex)
2023-05-12 13:29:53 +00:00
self.logger.info(f"Module: {self.module_name} Launched")
2022-05-30 07:15:50 +00:00
def compute(self, message):
item = self.get_obj()
2022-05-30 07:15:50 +00:00
# mimetype = item_basic.get_item_mimetype(item.get_id())
# if mimetype.split('/')[0] == "text":
content = item.get_content()
hosts = self.regex_findall(self.host_regex, item.get_id(), content)
if hosts:
print(f'{len(hosts)} host {item.get_id()}')
for host in hosts:
# print(host)
self.add_message_to_queue(message=str(host), queue='Host')
2022-05-30 07:15:50 +00:00
if __name__ == '__main__':
module = Hosts()
module.run()