1347
This commit is contained in:
@@ -125,6 +125,10 @@ NB_PROBLEM_LOCK = asyncio.Lock()
|
|||||||
# Structured event log output (JSON Lines)
|
# Structured event log output (JSON Lines)
|
||||||
EVENT_LOG_PATH = os.environ.get("EVENT_LOG_PATH", "/opt/containers/nats-registration-listener/logs/registration_events.jsonl")
|
EVENT_LOG_PATH = os.environ.get("EVENT_LOG_PATH", "/opt/containers/nats-registration-listener/logs/registration_events.jsonl")
|
||||||
|
|
||||||
|
EVENODD = (os.environ.get("EVENODD", "") or "").strip().lower()
|
||||||
|
if EVENODD not in ("", "even", "odd"):
|
||||||
|
raise SystemExit("ERROR: EVENODD must be unset, 'even', or 'odd'")
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# Arg parsing
|
# Arg parsing
|
||||||
@@ -296,6 +300,18 @@ def normalize_mac(mac: str) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def mac_belongs_to_this_shard(mac_norm: Optional[str]) -> bool:
|
||||||
|
if EVENODD == "":
|
||||||
|
return True
|
||||||
|
if not mac_norm:
|
||||||
|
return True
|
||||||
|
md5_hex = hashlib.md5(mac_norm.encode("utf-8")).hexdigest()
|
||||||
|
last_nibble = int(md5_hex[-1], 16)
|
||||||
|
if EVENODD == "even":
|
||||||
|
return (last_nibble % 2) == 0
|
||||||
|
return (last_nibble % 2) == 1
|
||||||
|
|
||||||
|
|
||||||
IGNORE_MACS = {m for m in (normalize_mac(x) for x in IGNORE_MACS_RAW) if m}
|
IGNORE_MACS = {m for m in (normalize_mac(x) for x in IGNORE_MACS_RAW) if m}
|
||||||
|
|
||||||
|
|
||||||
@@ -584,11 +600,11 @@ async def main():
|
|||||||
recent_payloads.pop(k, None)
|
recent_payloads.pop(k, None)
|
||||||
|
|
||||||
product = mac = fw = "-"
|
product = mac = fw = "-"
|
||||||
|
obj = None
|
||||||
try:
|
try:
|
||||||
text = payload.decode("utf-8", errors="replace")
|
text = payload.decode("utf-8", errors="replace")
|
||||||
obj = json.loads(text)
|
obj = json.loads(text)
|
||||||
product, mac, fw = extract_fields(obj)
|
product, mac, fw = extract_fields(obj)
|
||||||
event["reg_age_s"] = extract_registration_age_s(obj)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -597,7 +613,15 @@ async def main():
|
|||||||
event["fw"] = fw
|
event["fw"] = fw
|
||||||
|
|
||||||
mac_norm = normalize_mac(mac)
|
mac_norm = normalize_mac(mac)
|
||||||
|
if not mac_belongs_to_this_shard(mac_norm):
|
||||||
|
return
|
||||||
|
|
||||||
event["mac_norm"] = mac_norm
|
event["mac_norm"] = mac_norm
|
||||||
|
if obj is not None:
|
||||||
|
try:
|
||||||
|
event["reg_age_s"] = extract_registration_age_s(obj)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if mac_norm in IGNORE_MACS:
|
if mac_norm in IGNORE_MACS:
|
||||||
event["ignored"] = True
|
event["ignored"] = True
|
||||||
event["ignore_reason"] = "mac_ignore_list"
|
event["ignore_reason"] = "mac_ignore_list"
|
||||||
|
|||||||
Reference in New Issue
Block a user