Skip to content

Commit 6c0c4ed

Browse files
authored
Fix traceback in monthly policies jenkins job (#968)
* Fix traceback in monthly policies jenkins job * Debug code changes * Revert Debug code changes
1 parent 91f71aa commit 6c0c4ed

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

cloud_governance/policy/aws/monthly_report.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,32 @@ def get_monthly_report_data(self):
6969
logger.info('es_host is missing')
7070
return []
7171

72+
@staticmethod
73+
def _normalize_account_key(account_name: str) -> str:
74+
"""Normalize account name from ES to match prepare_data keys (e.g. PERFSCALE -> PERF-SCALE)."""
75+
if not account_name:
76+
return account_name
77+
key = account_name.upper().strip()
78+
if key == 'PERFSCALE':
79+
return 'PERF-SCALE'
80+
if key == 'PERF-DEPT':
81+
return 'PERF-DEPT'
82+
return key
83+
7284
def send_monthly_report(self):
7385
"""
7486
This method send monthly report to the user
7587
@return:
7688
"""
7789
monthly_data = self.get_monthly_report_data()
78-
prepare_data = {"Perf-Dept".upper(): [], "Perf-Scale".upper(): []}
90+
prepare_data = {"PERF-DEPT": [], "PERF-SCALE": []}
7991
for data in monthly_data:
80-
account_name = data['Account']
92+
account_name = (data.get('Account') or '').strip()
8193
if account_name:
82-
prepare_data[account_name].append({
94+
key = self._normalize_account_key(account_name)
95+
if key not in prepare_data:
96+
prepare_data[key] = []
97+
prepare_data[key].append({
8398
"Policy": data['Policy'],
8499
"Alerts": len(data['MessageType'])
85100
})

0 commit comments

Comments
 (0)