From 3668b25146c693d862562feac3e193e95696973b Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 2 Jan 2026 11:22:11 -0500 Subject: [PATCH] fix counting of buckets --- .../cross-organization/assess_check_config.py | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/local-app/python-tools/cross-organization/assess_check_config.py b/local-app/python-tools/cross-organization/assess_check_config.py index dc98a0d6..967f799c 100755 --- a/local-app/python-tools/cross-organization/assess_check_config.py +++ b/local-app/python-tools/cross-organization/assess_check_config.py @@ -8,10 +8,9 @@ import glob # --- VERSIONING --- -__version__ = "1.0.7" +__version__ = "1.0.8" def find_latest_file(pattern): - """Searches for the most recent file matching the pattern.""" files = glob.glob(pattern) return max(files, key=os.path.getctime) if files else None @@ -39,10 +38,15 @@ def main(): print(f"{'Account ID':<15} | {'OU Path':<30} | {'Global Status':<12} | {'S3 Compliance'}") print("-" * 140) + # UPDATED STATS: Tracking CONFIG COUNTS separately from UNIQUE BUCKETS stats = { "objects": 0, "size_bytes": 0, - "central_buckets": set(), "non_central_buckets": set(), - "total_recorders": 0, "accounts": len(data) + "total_recorders": 0, + "config_count_central": 0, # Number of regional configs using central buckets + "config_count_non_central": 0, # Number of regional configs using non-central buckets + "unique_central_buckets": set(), + "unique_non_central_buckets": set(), + "accounts": len(data) } for account in data: @@ -63,24 +67,31 @@ def main(): stats["size_bytes"] += reg_data.get("bucket_size_bytes", 0) if bucket != "N/A": - if re.search(args.central_bucket_regex, bucket): - stats["central_buckets"].add(bucket) + # FIXED: Using search for pattern matching anywhere in the name + if re.search(args.central_bucket_regex, bucket, re.IGNORECASE): + stats["config_count_central"] += 1 # Increment config instance count + stats["unique_central_buckets"].add(bucket) # Track unique bucket else: + stats["config_count_non_central"] += 1 # Increment config instance count + stats["unique_non_central_buckets"].add(bucket) # Track unique bucket s3_issues.append(bucket) - stats["non_central_buckets"].add(bucket) s3_status = "NON_COMPLIANT" if s3_issues else "COMPLIANT" print(f"{acc_id:<15} | {ou_path[:30]:<30} | {summary:<12} | {s3_status}") - # SUMMARY SECTION + # SUMMARY SECTION: Displaying both instance counts and unique bucket counts size_gb = stats["size_bytes"] / (1024**3) print("-" * 140) print(f"ORGANIZATION FOOTPRINT SUMMARY (CONFIG) | Org ID: {org_id}") - print(f" Active Recorders: {stats['total_recorders']}") - print(f" Total S3 Objects: {stats['objects']:,}") - print(f" Total S3 Storage: {size_gb:.2f} GB") - print(f" Central Buckets: {len(stats['central_buckets'])}") - print(f" Non-Central Buckets: {len(stats['non_central_buckets'])}") + print(f" Active Recorders Found: {stats['total_recorders']}") + print(f" Total S3 Objects: {stats['objects']:,}") + print(f" Total S3 Storage: {size_gb:.2f} GB") + print(f" --- Configuration Instance Counts ---") + print(f" Configs using Central: {stats['config_count_central']}") + print(f" Configs using Non-Central:{stats['config_count_non_central']}") + print(f" --- Unique Resource Counts ---") + print(f" Unique Central Buckets: {len(stats['unique_central_buckets'])}") + print(f" Unique Non-Central: {len(stats['unique_non_central_buckets'])}") print("-" * 140) if __name__ == "__main__":