Compare commits
16 Commits
1d5e59810f
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 139e675794 | |||
| 8c59d94aff | |||
| 04ab48c314 | |||
| b1f6de5c65 | |||
| 773a74c27c | |||
| 98d3e57737 | |||
| c41ae67ee8 | |||
| 81964183e8 | |||
| 7289430fc3 | |||
| 651e4dc1bc | |||
| 7e624e48f8 | |||
| a60b8c7012 | |||
| 5f29ea2e1d | |||
| 7540952328 | |||
| 26908890be | |||
| 1571f70ddd |
31
docker-compose-old.yml
Normal file
31
docker-compose-old.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
services:
|
||||
nats-registration-listener:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: nats-registration-listener:latest
|
||||
|
||||
# Share host network so 'localhost:4222' talks to NATS on the host (if that's your setup)
|
||||
network_mode: host
|
||||
|
||||
working_dir: /opt/containers/nats-registration-listener/app
|
||||
# entrypoint: ["/usr/bin/tini", "--", "/bin/bash", "-lc", "/usr/local/bin/nats-registration-entrypoint"]
|
||||
entrypoint: ["/usr/bin/tini","--","/bin/bash","-lc","/usr/local/bin/nats-registration-entrypoint"]
|
||||
# command: ["/opt/containers/nats-registration-listener/app/bin/nats-registration-listener.sh"]
|
||||
|
||||
restart: unless-stopped
|
||||
tty: true
|
||||
stdin_open: true
|
||||
|
||||
# One .env to rule them all
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
volumes:
|
||||
- ./data:/opt/containers/nats-registration-listener/data:rw
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "/usr/local/bin/nats-registration-healthcheck"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
@@ -1,29 +1,48 @@
|
||||
services:
|
||||
nats-registration-listener:
|
||||
nats-registration-listener-even:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: nats-registration-listener:latest
|
||||
|
||||
# Share host network so 'localhost:4222' talks to NATS on the host (if that's your setup)
|
||||
network_mode: host
|
||||
|
||||
working_dir: /opt/containers/nats-registration-listener/app
|
||||
# entrypoint: ["/usr/bin/tini", "--", "/bin/bash", "-lc", "/usr/local/bin/nats-registration-entrypoint"]
|
||||
entrypoint: ["/usr/bin/tini","--","/bin/bash","-lc","/usr/local/bin/nats-registration-entrypoint"]
|
||||
# command: ["/opt/containers/nats-registration-listener/app/bin/nats-registration-listener.sh"]
|
||||
|
||||
restart: unless-stopped
|
||||
tty: true
|
||||
stdin_open: true
|
||||
|
||||
# One .env to rule them all
|
||||
environment:
|
||||
EVENT_LOG_PATH: "/opt/containers/nats-registration-listener/logs/registration_events_even.jsonl"
|
||||
EVENODD: "even"
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
volumes:
|
||||
- ./data:/opt/containers/nats-registration-listener/data:rw
|
||||
|
||||
- ./logs:/opt/containers/nats-registration-listener/logs:rw
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "/usr/local/bin/nats-registration-healthcheck"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
nats-registration-listener-odd:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: nats-registration-listener:latest
|
||||
network_mode: host
|
||||
working_dir: /opt/containers/nats-registration-listener/app
|
||||
entrypoint: ["/usr/bin/tini","--","/bin/bash","-lc","/usr/local/bin/nats-registration-entrypoint"]
|
||||
restart: unless-stopped
|
||||
tty: true
|
||||
stdin_open: true
|
||||
environment:
|
||||
EVENT_LOG_PATH: "/opt/containers/nats-registration-listener/logs/registration_events_odd.jsonl"
|
||||
EVENODD: "odd"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./data:/opt/containers/nats-registration-listener/data:rw
|
||||
- ./logs:/opt/containers/nats-registration-listener/logs:rw
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "/usr/local/bin/nats-registration-healthcheck"]
|
||||
interval: 30s
|
||||
|
||||
@@ -61,7 +61,7 @@ RMQ_TIMEOUT = 5.0
|
||||
|
||||
# ---- Human-editable delay (milliseconds). Set to 0 to disable delay.
|
||||
# Example: 600000 = 10 minutes
|
||||
RMQ_DELAY_MS = 15000
|
||||
RMQ_DELAY_MS = 300000
|
||||
|
||||
# Posture analyzer gate: skip re-running sot-updater-scheduler if recently run (seconds)
|
||||
posture_analyzer = "sot-updater-scheduler"
|
||||
@@ -79,29 +79,14 @@ PRODUCT_TAG_SLUG = {
|
||||
# MACs to ignore completely when seen in registrations
|
||||
IGNORE_MACS_RAW = [
|
||||
"AA:BB:CC:DD:EE:FF",
|
||||
"D0:6C:37:01:26:02",
|
||||
"D0:6C:37:01:25:B2",
|
||||
"D0:6C:37:01:25:EA",
|
||||
"D0:6C:37:01:25:F2",
|
||||
"D0:6C:37:01:26:02",
|
||||
"D0:6C:37:01:26:1E",
|
||||
"D0:6C:37:01:26:3A",
|
||||
"D0:6C:37:01:26:D2",
|
||||
"D0:6C:37:01:26:D6",
|
||||
"D0:6C:37:01:26:E2",
|
||||
"D0:6C:37:01:0C:C0",
|
||||
"D0:6C:37:00:91:88",
|
||||
"C4:93:00:4E:96:0C",
|
||||
"D0:6C:37:01:0C:78",
|
||||
"C4:93:00:51:9A:12",
|
||||
"D0:6C:37:00:BD:B0",
|
||||
"C4:93:00:4E:97:B0",
|
||||
#"D0:6C:37:00:A9:68",
|
||||
"D0:6C:37:00:B0:1C",
|
||||
"C4:93:00:4E:96:F0",
|
||||
"D0:6C:37:00:B6:1C",
|
||||
"D0:6C:37:00:EA:40",
|
||||
"D0:6C:37:01:06:BC",
|
||||
"D0:6C:37:01:4A:25",
|
||||
"C4:93:00:4E:9E:C0", # 84823
|
||||
"C4:93:00:4E:97:B0", # 6667
|
||||
"D0:6C:37:01:26:D2", #NOT known for webapps
|
||||
"D0:6C:37:01:0C:C0", #NOT known for webapps
|
||||
"D0:6C:37:01:0C:7C", #NOT known for webapps
|
||||
"d0:6c:37:00:b0:1c", # 101200 flaps a lot
|
||||
"d0:6c:37:01:06:bc", #ikeja93929
|
||||
]
|
||||
|
||||
# Global counter for any NetBox-related problems
|
||||
@@ -111,6 +96,10 @@ NB_PROBLEM_LOCK = asyncio.Lock()
|
||||
# Structured event log output (JSON Lines)
|
||||
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
|
||||
@@ -282,6 +271,18 @@ def normalize_mac(mac: str) -> Optional[str]:
|
||||
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}
|
||||
|
||||
|
||||
@@ -570,11 +571,11 @@ async def main():
|
||||
recent_payloads.pop(k, None)
|
||||
|
||||
product = mac = fw = "-"
|
||||
obj = None
|
||||
try:
|
||||
text = payload.decode("utf-8", errors="replace")
|
||||
obj = json.loads(text)
|
||||
product, mac, fw = extract_fields(obj)
|
||||
event["reg_age_s"] = extract_registration_age_s(obj)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -583,7 +584,15 @@ async def main():
|
||||
event["fw"] = fw
|
||||
|
||||
mac_norm = normalize_mac(mac)
|
||||
if not mac_belongs_to_this_shard(mac_norm):
|
||||
return
|
||||
|
||||
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:
|
||||
event["ignored"] = True
|
||||
event["ignore_reason"] = "mac_ignore_list"
|
||||
|
||||
Reference in New Issue
Block a user