diff --git a/monkey/infection_monkey/telemetry/base_telem.py b/monkey/infection_monkey/telemetry/base_telem.py index 0fcf4b203..4a37a9eb9 100644 --- a/monkey/infection_monkey/telemetry/base_telem.py +++ b/monkey/infection_monkey/telemetry/base_telem.py @@ -3,6 +3,7 @@ import json import logging from infection_monkey.control import ControlClient +from infection_monkey.telemetry.i_telem import ITelem logger = logging.getLogger(__name__) LOGGED_DATA_LENGTH = 300 # How many characters of telemetry data will be logged @@ -24,14 +25,11 @@ __author__ = "itay.mizeretz" # logging and sending them. -class BaseTelem(object, metaclass=abc.ABCMeta): +class BaseTelem(ITelem, metaclass=abc.ABCMeta): """ Abstract base class for telemetry. """ - def __init__(self): - pass - def send(self, log_data=True): """ Sends telemetry to island @@ -41,13 +39,6 @@ class BaseTelem(object, metaclass=abc.ABCMeta): self._log_telem_sending(serialized_data, log_data) ControlClient.send_telemetry(self.telem_category, serialized_data) - @abc.abstractmethod - def get_data(self) -> dict: - """ - :return: Data of telemetry (should be dict) - """ - pass - @property def json_encoder(self): return json.JSONEncoder @@ -57,14 +48,6 @@ class BaseTelem(object, metaclass=abc.ABCMeta): if log_data: logger.debug(f"Telemetry contents: {BaseTelem._truncate_data(serialized_data)}") - @property - @abc.abstractmethod - def telem_category(self): - """ - :return: Telemetry type - """ - pass - @staticmethod def _truncate_data(data: str): if len(data) <= LOGGED_DATA_LENGTH: diff --git a/monkey/infection_monkey/telemetry/i_telem.py b/monkey/infection_monkey/telemetry/i_telem.py new file mode 100644 index 000000000..faaa0a65e --- /dev/null +++ b/monkey/infection_monkey/telemetry/i_telem.py @@ -0,0 +1,29 @@ +import abc + + +class ITelem(metaclass=abc.ABCMeta): + @abc.abstractmethod + def send(self, log_data=True): + """ + Sends telemetry to island + """ + + @abc.abstractmethod + def get_data(self) -> dict: + """ + :return: Data of telemetry (should be dict) + """ + pass + + @property + @abc.abstractmethod + def json_encoder(self): + pass + + @property + @abc.abstractmethod + def telem_category(self): + """ + :return: Telemetry type + """ + pass