diff --git a/agent_based/checkpoint_asg_diag.py b/agent_based/checkpoint_asg_diag.py index 0f64892cf675d79e9fad003b028b10f5b90b901a..545a00561818777cd44a8eedd2783a2a2de1a9e7 100644 --- a/agent_based/checkpoint_asg_diag.py +++ b/agent_based/checkpoint_asg_diag.py @@ -88,9 +88,15 @@ from .agent_based_api.v1 import ( any_of, ) +class CheckPointASGDiagSummary(NamedTuple): + date: str + time: str + passed: int + maxtest: int + failed: list class CheckPointASGDiag(NamedTuple): - summary: str + summary: CheckPointASGDiagSummary tests: List @@ -100,8 +106,16 @@ def parse_checkpoint_asg_diag(string_table: List[StringTable]) -> CheckPointASGD if len(asgSummary) == 0: return None + asgSummary = asgSummary[0][0] + parsed = CheckPointASGDiag - parsed.summary = asgSummary[0][0] + parsed.summary = CheckPointASGDiagSummary + # todo: change date to real date string, and add warn/crit if last run to old + parsed.summary.date = asgSummary[0][0][3:13] + parsed.summary.time = asgSummary[0][0][18:26] + parsed.summary.passed = int(asgSummary[28:].split(".")[0].split(' ')[1].split('/')[0]) + parsed.summary.maxtest = int(asgSummary[28:].split(".")[0].split(' ')[1].split('/')[1]) + parsed.summary.failed = list(map(int, asgSummary.split(':')[-1].strip(' ').split(','))) parsed.tests = asgTests return parsed @@ -119,8 +133,23 @@ def check_checkpoint_asg_diag(params, section: CheckPointASGDiag): result: str comment: str - summary = 'Last run ' + section.summary + summary = '' + summary += 'Last run on: %s at: %s' % (section.summary.date, section.summary.time) + summary += ' Passed %d/%d tests' % (section.summary.passed, section.summary.maxtest) + if len(section.summary.failed) > 0: + summary += ' Failed: %s' % ','.join(map(str, section.summary.failed)) + details = '\n\nTo verify this output use the "asg diag verify" command on the Check Point SMO cli,\n' + + for test in section.tests: + test = CheckPointASGDiagTest(*test) + if test.comment == '': + details += '\nIndex: %s, Name: %s, LastRun: %s, Restult: %s' % ( + test.index, test.name, test.lastrun, test.result) + else: + details += '\nIndex: %s, Name: %s, LastRun: %s, Restult: %s, Comment: %s' % ( + test.index, test.name, test.result, test.result, test.comment) + state = State.OK asg_diag_ignore = [] @@ -129,9 +158,10 @@ def check_checkpoint_asg_diag(params, section: CheckPointASGDiag): if params: asg_diag_ignore = params.get('asg_diag_ignore', []) asg_diag_warning = params.get('asg_diag_warning', []) + asg_diag_ignore.sort() if len(asg_diag_ignore) > 0: - summary += ', Ignored tests: %s' % str(asg_diag_ignore).strip('[').strip(']').replace(' ', '') + summary += ', Ignored tests: %s' % ','.join(map(str, asg_diag_ignore)) for test in section.tests: test = CheckPointASGDiagTest(*test) @@ -142,14 +172,13 @@ def check_checkpoint_asg_diag(params, section: CheckPointASGDiag): details += '\nIndex: %s, Name: %s, LastRun: %s, Restult: %s, Comment: %s' % ( test.index, test.name, test.result, test.result, test.comment) - asgTestIndex = int(test.index) - if not asgTestIndex in asg_diag_ignore: - if test.result.lower() == 'failed (!)': - if asgTestIndex in asg_diag_warning: - if state == State.OK: - state = State.WARN - else: - state = State.CRIT + for test in section.summary.failed: + if not test in asg_diag_ignore: + if test in asg_diag_warning: + if state == State.OK: + state = State.WARN + else: + state = State.CRIT yield Result(state=state, summary=summary, details=details) diff --git a/checkpoint_asg_diag.mkp b/checkpoint_asg_diag.mkp index 2d910cc08f018ff4fbb37abed82d3b8a4b3b0902..9c6f26220ba522ef5d15aad526044b16c7e3ff88 100644 Binary files a/checkpoint_asg_diag.mkp and b/checkpoint_asg_diag.mkp differ