Skip to content

Commit

Permalink
Merge pull request #66 from kuettai/main
Browse files Browse the repository at this point in the history
Improve debug messaging
  • Loading branch information
kuettai authored Mar 20, 2024
2 parents a346f5b + 54ac7eb commit 9eafdf2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def number_format(num, places=2):

# print(crossAccounts)

DEBUG = True if debugFlag in _C.CLI_TRUE_KEYWORD_ARRAY or debugFlag is True else False
DEBUG = False if debugFlag in _C.CLI_TRUE_KEYWORD_ARRAY or debugFlag is True else False
testmode = True if testmode in _C.CLI_TRUE_KEYWORD_ARRAY or testmode is True else False
crossAccounts = True if crossAccounts in _C.CLI_TRUE_KEYWORD_ARRAY or crossAccounts is True else False
_cli_options['crossAccounts'] = crossAccounts
Expand Down
9 changes: 8 additions & 1 deletion services/Evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ def run(self, serviceName):
rulePrefix = serviceName.__name__ + '::rules'
rules = Config.get(rulePrefix, [])

debugFlag = Config.get('DEBUG')

ecnt = cnt = 0
emsg = []
methods = [method for method in dir(self) if method.startswith('__') is False and method.startswith('_check') is True]
for method in methods:
if not rules or str.lower(method[6:]) in rules:
try:
# print('--- --- fn: ' + method)
if debugFlag:
print('--- --- fn: ' + method)

getattr(self, method)()
cnt += 1
except botocore.exceptions.ClientError as e:
Expand Down Expand Up @@ -53,6 +57,9 @@ def run(self, serviceName):
'exceptions': scanned['exceptions'] + ecnt
})

if debugFlag:
self.showInfo()

def showInfo(self):
print("Class: {}".format(self.classname))
print(self.getInfo())
Expand Down
9 changes: 9 additions & 0 deletions services/rds/drivers/RdsCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def _checkFreeStorage(self):

GBYTES = 1024 * 1024 * 1024
dp = results['Datapoints']
if len(dp) == 0:
return

freesize = round(dp[0]['Average'] / GBYTES, 4)

ratio = freesize / self.db['AllocatedStorage']
Expand Down Expand Up @@ -578,6 +581,9 @@ def _checkCPUUtilization(self):
Statistics=['Minimum', 'Maximum', 'Average']
)
monthDp = resp.get('Datapoints')
if len(monthDp) == 0:
return

monthAverage = monthDp[0]['Average']
monthMax = monthDp[0]['Maximum']

Expand Down Expand Up @@ -637,8 +643,11 @@ def _checkFreeMemory(self):
)

dp = resp.get('Datapoints')
if len(dp) == 0:
return

serverGB = self.instInfo['specification']['memoryInGiB']

freeMemoryMin = dp[0]['Minimum'] / rawToGBRatio
freeMemoryMax = dp[0]['Maximum'] / rawToGBRatio
freeMemoryAvg = dp[0]['Average'] / rawToGBRatio
Expand Down
3 changes: 2 additions & 1 deletion services/rds/drivers/RdsMssql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import math
import math, ast

from utils.Tools import _pr
from .RdsCommon import RdsCommon
Expand Down Expand Up @@ -78,6 +78,7 @@ def _checkParamMaxServerMemory(self):
if 'DBInstanceClassMemory' in maxMemorySettings:
maxMemorySettings = maxMemorySettings.replace("{", "")
maxMemorySettings = maxMemorySettings.replace("}", "")

maxMemorySettings = eval(maxMemorySettings, {"DBInstanceClassMemory": memInKBytes})

## Need to be review
Expand Down
10 changes: 5 additions & 5 deletions utils/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
from netaddr import IPAddress


def _pr(s):
def _pr(s, forcePrint = False):
DEBUG = Config.get('DEBUG')
if DEBUG == True:
if forcePrint or DEBUG == True:
print(s)

def _info(s):
_printStatus("info", s)

def _warn(s):
_printStatus("\033[1;41m__!! WARNING !!__\033[0m", s)
_printStatus("\033[1;41m__!! WARNING !!__\033[0m", s, forcePrint=True)

def _printStatus(status, s):
def _printStatus(status, s, forcePrint = False):
p = "["+status+"] "+ s
_pr(p)
_pr(p, forcePrint)

def checkIsPrivateIp(ipaddr):
ip = ipaddr.split('/')
Expand Down

0 comments on commit 9eafdf2

Please sign in to comment.