From 81d392e7ff5f2ac920819194de32e4cfbe75ddd7 Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Sat, 25 Nov 2023 19:54:19 +0000 Subject: [PATCH] Improve worker IDs --- .tfstate | 2 +- listener/lambda_function.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.tfstate b/.tfstate index 4a7c931..b600f2a 160000 --- a/.tfstate +++ b/.tfstate @@ -1 +1 @@ -Subproject commit 4a7c931eb51d2c594ea5bf13df06358cb8d486e5 +Subproject commit b600f2a8d70d680d745642364483cbdbc5a7b04d diff --git a/listener/lambda_function.py b/listener/lambda_function.py index b69410f..024c61f 100644 --- a/listener/lambda_function.py +++ b/listener/lambda_function.py @@ -2,6 +2,7 @@ import logging import os import re +import socket from abc import ABC, abstractmethod from base64 import b64encode @@ -226,14 +227,14 @@ def worker_id(self): result = self.source_ip if ip_address(result) not in self.config.home_network: - return result + return gethostbyaddr(result) for word in self.miner_status["cpu.brand"].split(): name = self.config.home_hostnames_by_cpu.get(word) if name is not None: - return name + return f"{name}.nx" - return result + return gethostbyaddr(result) LIST_SUFFIXES = { "hashrate.total": ("10s", "1m", "15m"), @@ -312,6 +313,13 @@ def is_in_container_hostname(s): return re.match(r"^[0-9a-f]{12}$", s) is not None +def gethostbyaddr(ip_address): + try: + return socket.gethostbyaddr(ip_address)[0] + except Exception: + return ip_address + + def as_dict(obj): """JSON serialization helper. """