fix: incorrect decision pulling from CrowdSec locally
This commit is contained in:
1 parent
d91cfc7e1f
commit
82352110a4
1 file changed
+13
-6
+13
-6
@@ -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 {}
|
||||
|
||||
Reference in new issue
Block a user