From 26fc6fd5b94fb3f33e3731d43a0d4c5ea2569af9 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 14 Sep 2022 17:17:32 +0200 Subject: [PATCH] Island: Add save_event_to_event_repository subscriber --- .../cc/agent_event_subscribers/__init__.py | 1 + .../save_event_to_event_repository.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 monkey/monkey_island/cc/agent_event_subscribers/__init__.py create mode 100644 monkey/monkey_island/cc/agent_event_subscribers/save_event_to_event_repository.py diff --git a/monkey/monkey_island/cc/agent_event_subscribers/__init__.py b/monkey/monkey_island/cc/agent_event_subscribers/__init__.py new file mode 100644 index 000000000..f206087d7 --- /dev/null +++ b/monkey/monkey_island/cc/agent_event_subscribers/__init__.py @@ -0,0 +1 @@ +from .save_event_to_event_repository import save_event_to_event_repository diff --git a/monkey/monkey_island/cc/agent_event_subscribers/save_event_to_event_repository.py b/monkey/monkey_island/cc/agent_event_subscribers/save_event_to_event_repository.py new file mode 100644 index 000000000..0249369b3 --- /dev/null +++ b/monkey/monkey_island/cc/agent_event_subscribers/save_event_to_event_repository.py @@ -0,0 +1,17 @@ +import logging + +from common.events import AbstractAgentEvent +from monkey_island.cc.repository import IEventRepository, StorageError + +logger = logging.getLogger(__name__) + + +class save_event_to_event_repository: + def __init__(self, event_repository: IEventRepository): + self._event_repository = event_repository + + def __call__(self, event: AbstractAgentEvent): + try: + self._event_repository.save_event(event) + except StorageError as err: + logger.error(f"Error occured storing event {event}: {err}")