Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Mar 10, 2026
1 parent c3c4ddd commit 604b014
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
from collections import Counter, defaultdict

# --- VERSIONING ---
__version__ = "1.2.0"
__version__ = "1.2.1"

def find_latest_file(pattern):
"""Locates the most recent check_scheduling JSON file."""
files = glob.glob("audit_results.check_scheduling.*.json")
"""Locates the most recent file matching the given pattern."""
files = glob.glob(pattern)
return max(files, key=os.path.getctime) if files else None

def main():
parser = argparse.ArgumentParser(description="PowerSchedule & FinOps Assessor - v1.2.0")
parser = argparse.ArgumentParser(description="PowerSchedule & FinOps Assessor - v1.2.1")
parser.add_argument("--input", help="JSON audit file")
args = parser.parse_args()

input_file = args.input or find_latest_file()
# FIX: Pass the specific pattern to find_latest_file
input_file = args.input or find_latest_file("audit_results.check_scheduling.*.json")

if not input_file:
print("Error: No scheduling audit file found."); sys.exit(1)

Expand All @@ -25,14 +27,11 @@ def main():
# Tracking structures
env_matrix = defaultdict(Counter)
env_totals = Counter()

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

Expand All @@ -46,13 +45,11 @@ def main():
tags = val.get("tags", {})
res_type = val.get("type", "unknown")

# 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")

Expand All @@ -68,7 +65,6 @@ def main():
print(f"POWERSCHEDULE COMPLIANCE ASSESSMENT | Input: {os.path.basename(input_file)}")
print("-" * report_width)

# REPORT 1: Breakdown by Environment
print(f"\nREPORT 1: BREAKDOWN BY ENVIRONMENT")
print("=" * 40)
for env in sorted(env_matrix.keys()):
Expand All @@ -79,19 +75,16 @@ def main():
pct = (count / env_totals[env]) * 100
print(f" {sched:<30} | {count:<10} | {pct:.1f}%")

# REPORT 2: Breakdown by Resource Type
print(f"\n\nREPORT 2: BREAKDOWN BY RESOURCE TYPE")
print("=" * 40)
for r_type in sorted(type_matrix.keys()):
# 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}%")

# Organization Summary
print("\n" + "=" * report_width)
print(f"ORGANIZATION SUMMARY")
print(f" Accounts Checked: {accounts_checked}")
Expand Down

0 comments on commit 604b014

Please sign in to comment.