diff --git a/Screener.py b/Screener.py index 55966f3..b53f42f 100644 --- a/Screener.py +++ b/Screener.py @@ -97,8 +97,9 @@ def scanByService(service, regions, filters): except botocore.exceptions.ClientError as e: contexts[service[0]][region] = {} eCode = e.response['Error']['Code'] - print(eCode) - print(_cli_options['crossAccounts']) + eMsg = e.response['Error']['Message'] + print("Screener.py error: {}, {}".format(eCode, eMsg)) + print("Screener.py isCrossAccounts: {}".format(_cli_options['crossAccounts'])) if eCode == 'InvalidClientTokenId' and _cli_options['crossAccounts'] == True: _warn('Impacted Region: [{}], Services: {}... Cross Account limitation, encounted errors: {}'.format(reg, service[0], e)) diff --git a/services/rds/Rds.py b/services/rds/Rds.py index 4741a89..232d3ee 100644 --- a/services/rds/Rds.py +++ b/services/rds/Rds.py @@ -37,6 +37,7 @@ def __init__(self, region): self.setChartsType(self.CHARTSTYPE) self.secrets = [] + self.hasCEPermission = True engineDriver = { 'mariadb': 'Mariadb', @@ -124,14 +125,24 @@ def getCEResults(self, groupBy, filter): ## Fix for 30 days data endDate = datetime.now().date() startDate = endDate - timedelta(days=30) + response = {} + + if self.hasCEPermission == True: + try: + response = self.ceClient.get_cost_and_usage( + TimePeriod={"Start": str(startDate), "End": str(endDate)}, + Granularity="MONTHLY", + Metrics=["UnblendedCost"], + GroupBy=[{"Type": "DIMENSION", "Key": groupBy}], + Filter=filter, + ) + except botocore.exceptions.ClientError as e: + self.hasCEPermission = False + eCode = e.response['Error']['Code'] + eMsg = e.response['Error']['Message'] + print("Rds.py error: {}, {}".format(eCode, eMsg)) + print("[Skipped] RDS Cost Breakdown Charts") - response = self.ceClient.get_cost_and_usage( - TimePeriod={"Start": str(startDate), "End": str(endDate)}, - Granularity="MONTHLY", - Metrics=["UnblendedCost"], - GroupBy=[{"Type": "DIMENSION", "Key": groupBy}], - Filter=filter, - ) return response @@ -144,6 +155,8 @@ def getRDSCost(self, dimension, unuse_group=[]): ] } response = self.getCEResults(dimension, filter) + if response == {}: + return results for item in response.get('ResultsByTime'): for group in item.get("Groups"): diff --git a/services/rds/drivers/RdsSecurityGroup.py b/services/rds/drivers/RdsSecurityGroup.py index f7237ac..2e4f8fa 100644 --- a/services/rds/drivers/RdsSecurityGroup.py +++ b/services/rds/drivers/RdsSecurityGroup.py @@ -34,6 +34,7 @@ def _checkSGHasPublicRules(self): infoMsg = [] hasNonPrivateIp = False + for sg in settings: if not 'IpPermissions' in sg: continue