diff options
Diffstat (limited to 'roles/install_respondd_poller')
-rw-r--r-- | roles/install_respondd_poller/files/respondd_poller.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/roles/install_respondd_poller/files/respondd_poller.py b/roles/install_respondd_poller/files/respondd_poller.py index 1eb98a1..b9a9a36 100644 --- a/roles/install_respondd_poller/files/respondd_poller.py +++ b/roles/install_respondd_poller/files/respondd_poller.py @@ -35,6 +35,7 @@ with open("/etc/respondd_poller.json", "r") as f: wg = WireGuard() sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) last_request = dict() +last_http_request = dict() last_response = dict() def get_wg_peers(): @@ -51,6 +52,9 @@ def inflate(data): return inflated.decode() def cleanup(): + global last_request + global last_http_request + global last_response while True: time.sleep(60) old = time.monotonic() - 360 @@ -62,6 +66,7 @@ def cleanup(): for ip in ips: del last_response[ip] del last_request[ip] + del last_http_request[ip] def recv(): global sock @@ -81,8 +86,10 @@ def send(ip): def get_http_nodeinfo(ip): global last_request - now = time.monotonic() + global last_http_request + global last_response try: + print("get_http_nodeinfo", ip) status = requests.get('http://[' + str(ip) + ']/cgi-bin/status') except: return @@ -104,12 +111,18 @@ def get_http_nodeinfo(ip): for address in data["network"]["addresses"]: if ipaddress.IPv6Network(address).subnet_of(prefix): node_ip = ipaddress.IPv6Address(address) + now = time.monotonic() if node_ip not in last_request: last_request[node_ip] = now last_response[node_ip] = now + if node_ip not in last_http_request or now - last_http_request[node_ip] > 300: + last_http_request[node_ip] = now + get_http_nodeinfo(node_ip) def scan_wg_peers(): global last_request + global last_http_request + global last_response while True: print("scanning wg peers") request_threads = [] @@ -118,6 +131,7 @@ def scan_wg_peers(): ip = ipaddress.IPv6Address(str(net.network_address) + "1") if ip not in last_request: last_request[ip] = now + last_http_request[ip] = now last_response[ip] = now request_thread = threading.Thread(target=get_http_nodeinfo, args=(ip,)) request_thread.start() @@ -139,8 +153,8 @@ scan_thread.start() last_wg_time = 0 while True: - now = time.monotonic() for ip in last_request: + now = time.monotonic() if now - last_request[ip] > 15: last_request[ip] = now send(ip) |