Skip to content

Commit

Permalink
fix counting of buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 2, 2026
1 parent 042bab2 commit 3668b25
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions local-app/python-tools/cross-organization/assess_check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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__":
Expand Down

0 comments on commit 3668b25

Please sign in to comment.