def check_gateways(): # Todo only check against Freefarm getways info_log = [] for expname, expurl in EXPLORERS.items(): gws_endpoint = f"{expurl}/gateways" try: res = j.tools.http.get(gws_endpoint) json_list = res.json() for gw in json_list: gw_id = gw["id"] gw_node_id = gw["node_id"] farm_id = gw["farm_id"] if farm_id not in [0, 1, 71]: continue #skip none freefarm gateway ten_mins_ago = now().timestamp - (60 * 10) amonth_ago = now().timestamp - (60 * 60 * 24 * 30) if gw["updated"] < ten_mins_ago and gw["updated"] > amonth_ago: if gw_id != 19 and gw_node_id != "23z8M5DVdbWwmBWaR3mmsDrzUf76iqeYhSWeSXXDR5nE": info_log.append( f"{expname}:: {expurl} :: gateway {gw_id} on {gw_node_id} is down 💣" ) # else: # info_log.append(f"{expname}:: {expurl} :: gateway {gw_id} on {gw_node_id} is up ✅") except Exception as e: info_log.append(str(e)) return info_log
def wait_connection_test(ipaddr: str, port: int, timeout=5): """Will wait until port listens on the specified address Args: ipaddr (str): ip address port (int): port number timeout_total (int, optional): how long to wait for the connection. Defaults to 5. Returns: bool: True if the test succeeds, False otherwise """ port = int(port) end = now().timestamp + timeout while True: if now().timestamp > end: return False if tcp_connection_test(ipaddr, port, timeout=2): return True
def filter_is_up(self, node: Node): """filter function that filters out nodes that have not received update for more then 10 minutes""" ago = now().timestamp - (60 * 10) return node.updated.timestamp() > ago
def filter_is_up(self, gw): """ filter out gateways that have not received update for more then 10 minutes """ ago = now().timestamp - (60 * 10) return gw.updated > ago