From 82352110a46ad775447c7edd12f763a236b523b0 Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 25 Jan 2026 22:49:19 -0500 Subject: [PATCH] fix: incorrect decision pulling from CrowdSec locally --- auditor.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/auditor.py b/auditor.py index b756e66..9f3c353 100644 --- a/auditor.py +++ b/auditor.py @@ -20,12 +20,19 @@ class FirewallAuditor: cmd = ["/usr/bin/cscli", "decisions", "list", "-a", "-o", "json"] res = subprocess.run(cmd, capture_output=True, text=True, check=True) data = json.loads(res.stdout) or [] - - return { - d["value"]: d.get("duration") - for d in data - if isinstance(d, dict) and d.get("origin") != "CAPI" - } + + truth_map = {} + for item in data: + # cscli JSON can be a list of alerts, each containing a list of decisions + decisions = item.get('decisions', []) + for d in decisions: + val = d.get('value') + # Filter: must have a value, must not be CAPI + if val and d.get('origin') != 'CAPI': + truth_map[val] = d.get('duration') + + logging.info(f"LAPI Local Parser: Found {len(truth_map)} active bans.") + return truth_map except Exception as e: logging.error(f"Failed to get LAPI truth: {e}") return {}