From 1462e832b0a21b1248dd28060b6068c9fb021455 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 12 Sep 2022 18:54:53 +0530 Subject: [PATCH] Agent: Add subscriber to push all events to the Island --- .../infection_monkey/push_events_to_island.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 monkey/infection_monkey/push_events_to_island.py diff --git a/monkey/infection_monkey/push_events_to_island.py b/monkey/infection_monkey/push_events_to_island.py new file mode 100644 index 000000000..6eae55ae7 --- /dev/null +++ b/monkey/infection_monkey/push_events_to_island.py @@ -0,0 +1,28 @@ +import logging + +import requests + +# TODO: shouldn't leak implementation information; can we do this some other way? +from pubsub import pub + +from common.common_consts.timeouts import MEDIUM_REQUEST_TIMEOUT +from common.events import AbstractAgentEvent + +logger = logging.getLogger(__name__) + + +class push_all_events_to_island: + def __init__(self, server_address: str): + self._server_address = server_address + + def __call__(self, event: AbstractAgentEvent, topic=pub.AUTO_TOPIC): + requests.post( # noqa: DUO123 + "https://%s/api/events" % (self._server_address,), + data=self._serialize_event(event, topic.getName()), + headers={"content-type": "application/json"}, + verify=False, + timeout=MEDIUM_REQUEST_TIMEOUT, + ) + + def _serialize_event(self, event: AbstractAgentEvent, topic_name: str): + pass