From c3c4dddb629ac4da6e1af60b4e67922e0ce0463e Mon Sep 17 00:00:00 2001 From: badra001 Date: Tue, 10 Mar 2026 14:40:52 -0400 Subject: [PATCH] update report 2 --- .../assess_check_scheduling.py | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/local-app/python-tools/cross-organization/assess_check_scheduling.py b/local-app/python-tools/cross-organization/assess_check_scheduling.py index e1858f65..0d6d8883 100755 --- a/local-app/python-tools/cross-organization/assess_check_scheduling.py +++ b/local-app/python-tools/cross-organization/assess_check_scheduling.py @@ -3,7 +3,7 @@ from collections import Counter, defaultdict # --- VERSIONING --- -__version__ = "1.1.0" +__version__ = "1.2.0" def find_latest_file(pattern): """Locates the most recent check_scheduling JSON file.""" @@ -11,11 +11,11 @@ def find_latest_file(pattern): return max(files, key=os.path.getctime) if files else None def main(): - parser = argparse.ArgumentParser(description="PowerSchedule & FinOps Assessor - v1.1.0") + parser = argparse.ArgumentParser(description="PowerSchedule & FinOps Assessor - v1.2.0") parser.add_argument("--input", help="JSON audit file") args = parser.parse_args() - input_file = args.input or find_latest_file("audit_results.check_scheduling.*.json") + input_file = args.input or find_latest_file() if not input_file: print("Error: No scheduling audit file found."); sys.exit(1) @@ -23,15 +23,18 @@ def main(): data = json.load(f) # Tracking structures - # env -> schedule_value -> count env_matrix = defaultdict(Counter) env_totals = Counter() - # NEW: resource_type -> schedule_value -> count type_matrix = defaultdict(Counter) type_totals = Counter() total_resources = 0 + accounts_checked = len(data) + + # Specific sub-type counters for summary + asg_names = set() + eks_node_count = 0 for account in data: checks = account.get("data", {}) @@ -43,15 +46,19 @@ def main(): tags = val.get("tags", {}) res_type = val.get("type", "unknown") - # Normalize Environment key + # Sub-type tracking for summary + if res_type == "eks_node": + eks_node_count += 1 + if val.get("asg_name") and val.get("asg_name") != "N/A": + asg_names.add(f"{account.get('account_id')}:{val.get('asg_name')}") + + # Normalize Environment and Schedule env = tags.get('Environment') or tags.get('environment') or "Undefined" schedule = tags.get('PowerSchedule', "No Schedule") - # Aggregate by Environment env_matrix[env][schedule] += 1 env_totals[env] += 1 - # Aggregate by Resource Type (EC2 categories normalized to 'ec2') display_type = "ec2" if res_type in ["plain", "asg_member", "eks_node"] else res_type type_matrix[display_type][schedule] += 1 type_totals[display_type] += 1 @@ -65,10 +72,9 @@ def main(): print(f"\nREPORT 1: BREAKDOWN BY ENVIRONMENT") print("=" * 40) for env in sorted(env_matrix.keys()): - print(f"\nEnvironment: {env}") + print(f"\nEnvironment: {env} (Total: {env_totals[env]})") print(f" {'Schedule Value':<30} | {'Count':<10} | {'Percentage'}") print(f" {'-'*30} | {'-'*10} | {'-'*10}") - for sched, count in env_matrix[env].items(): pct = (count / env_totals[env]) * 100 print(f" {sched:<30} | {count:<10} | {pct:.1f}%") @@ -77,10 +83,10 @@ def main(): print(f"\n\nREPORT 2: BREAKDOWN BY RESOURCE TYPE") print("=" * 40) for r_type in sorted(type_matrix.keys()): - print(f"\nResource Type: {r_type.upper()}") + # ADDED: Total count for each resource type + print(f"\nResource Type: {r_type.upper()} (Total: {type_totals[r_type]})") print(f" {'Schedule Value':<30} | {'Count':<10} | {'Percentage'}") print(f" {'-'*30} | {'-'*10} | {'-'*10}") - for sched, count in type_matrix[r_type].items(): pct = (count / type_totals[r_type]) * 100 print(f" {sched:<30} | {count:<10} | {pct:.1f}%") @@ -88,9 +94,11 @@ def main(): # Organization Summary print("\n" + "=" * report_width) print(f"ORGANIZATION SUMMARY") + print(f" Accounts Checked: {accounts_checked}") print(f" Total Resources Scanned: {total_resources}") + print(f" Total ASGs Identified: {len(asg_names)}") + print(f" Total EKS Nodes Found: {eks_node_count}") print(f" Environments Found: {len(env_matrix)}") - print(f" Resource Types Found: {', '.join(sorted(type_matrix.keys())).upper()}") print("=" * report_width) if __name__ == "__main__":