forked from p15670423/monkey
Agent: Rework relay.utils.find_server a bit
This commit is contained in:
parent
e539495545
commit
60f9aa6a4e
|
@ -13,23 +13,19 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def find_server(servers: Iterable[str]) -> Optional[str]:
|
def find_server(servers: Iterable[str]) -> Optional[str]:
|
||||||
server_found = None
|
|
||||||
|
|
||||||
logger.debug(f"Trying to wake up with servers: {', '.join(servers)}")
|
logger.debug(f"Trying to wake up with servers: {', '.join(servers)}")
|
||||||
|
|
||||||
for server in servers:
|
for server in servers:
|
||||||
|
logger.debug(f"Trying to connect to server: {server}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
debug_message = f"Trying to connect to server: {server}"
|
|
||||||
logger.debug(debug_message)
|
|
||||||
requests.get( # noqa: DUO123
|
requests.get( # noqa: DUO123
|
||||||
f"https://{server}/api?action=is-up",
|
f"https://{server}/api?action=is-up",
|
||||||
verify=False,
|
verify=False,
|
||||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
server_found = server
|
return server
|
||||||
|
|
||||||
break
|
|
||||||
except requests.exceptions.ConnectionError as err:
|
except requests.exceptions.ConnectionError as err:
|
||||||
logger.error(f"Unable to connect to server/relay {server}: {err}")
|
logger.error(f"Unable to connect to server/relay {server}: {err}")
|
||||||
except TimeoutError as err:
|
except TimeoutError as err:
|
||||||
|
@ -39,7 +35,7 @@ def find_server(servers: Iterable[str]) -> Optional[str]:
|
||||||
f"Exception encountered when trying to connect to server/relay {server}: {err}"
|
f"Exception encountered when trying to connect to server/relay {server}: {err}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return server_found
|
return None
|
||||||
|
|
||||||
|
|
||||||
def send_relay_control_message(servers: Iterable[str]):
|
def send_relay_control_message(servers: Iterable[str]):
|
||||||
|
|
Loading…
Reference in New Issue