diff --git a/monkey/infection_monkey/master/control_channel.py b/monkey/infection_monkey/master/control_channel.py index 9e8046baf..12bf3a52f 100644 --- a/monkey/infection_monkey/master/control_channel.py +++ b/monkey/infection_monkey/master/control_channel.py @@ -19,37 +19,51 @@ class ControlChannel(IControlChannel): self._control_channel_server = server def should_agent_stop(self) -> bool: - if not self._control_channel_server: - return - try: response = requests.get( # noqa: DUO123 f"{self._control_channel_server}/api/monkey_control/{self._agent_id}", verify=False, + proxies=ControlClient.proxies, timeout=SHORT_REQUEST_TIMEOUT, ) response = json.loads(response.content.decode()) return response["stop_agent"] except Exception as e: + # TODO: Evaluate how this exception is handled; don't just log and ignore it. logger.error(f"An error occurred while trying to connect to server. {e}") + return True + def get_config(self) -> dict: - ControlClient.load_control_config() - return WormConfiguration.as_dict() + try: + response = requests.get( # noqa: DUO123 + "https://%s/api/monkey/%s" % (WormConfiguration.current_server, self._agent_id), + verify=False, + proxies=ControlClient.proxies, + timeout=SHORT_REQUEST_TIMEOUT, + ) + + return json.loads(response.content.decode()) + except Exception as exc: + # TODO: Evaluate how this exception is handled; don't just log and ignore it. + logger.warning( + "Error connecting to control server %s: %s", WormConfiguration.current_server, exc + ) + + return {} def get_credentials_for_propagation(self) -> dict: - if not self._control_channel_server: - return - try: response = requests.get( # noqa: DUO123 f"{self._control_channel_server}/api/propagationCredentials", verify=False, + proxies=ControlClient.proxies, timeout=SHORT_REQUEST_TIMEOUT, ) response = json.loads(response.content.decode())["propagation_credentials"] return response except Exception as e: + # TODO: Evaluate how this exception is handled; don't just log and ignore it. logger.error(f"An error occurred while trying to connect to server. {e}")