diff --git a/agent_based/checkpoint_asg_diag.py b/agent_based/checkpoint_asg_diag.py index b692678ee0a11480fdd8b07b8ec9cb2e4fc7b35c..42fd3927d2f4657a1c38fe57f318a67aac814de5 100644 --- a/agent_based/checkpoint_asg_diag.py +++ b/agent_based/checkpoint_asg_diag.py @@ -11,6 +11,7 @@ # # 2021-03-01: rewrite for CMK 2.x # 2021-03-03: fixed date/time in parse function +# 2021-09-10: fixed duplicate detail output # # sample snmpwalk for one passed asg test # .1.3.6.1.4.1.2620.1.48.31.1.1.1.21.0 = Wrong Type (should be OCTET STRING): Gauge32: 21 @@ -73,13 +74,13 @@ from typing import Mapping, Dict, List, Tuple, NamedTuple -from .agent_based_api.v1.type_defs import ( +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, StringTable, ) -from .agent_based_api.v1 import ( +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, equals, @@ -91,6 +92,7 @@ from .agent_based_api.v1 import ( any_of, ) + class CheckPointASGDiagSummary(NamedTuple): date: str time: str @@ -98,6 +100,7 @@ class CheckPointASGDiagSummary(NamedTuple): maxtest: int failed: list + class CheckPointASGDiag(NamedTuple): summary: CheckPointASGDiagSummary tests: List @@ -106,22 +109,20 @@ class CheckPointASGDiag(NamedTuple): def parse_checkpoint_asg_diag(string_table: List[StringTable]) -> CheckPointASGDiag: asgSummary, asgTests = string_table - if len(asgSummary) == 0: - return None - - asgSummary = asgSummary[0][0] - - parsed = CheckPointASGDiag - parsed.summary = CheckPointASGDiagSummary - # todo: change date to real date string, and add warn/crit if last run to old - parsed.summary.date = asgSummary[3:13] - parsed.summary.time = asgSummary[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 + # ToDo: change date to real date string, and add warn/crit if last run to old + + if len(asgSummary) != 0: + asgSummary = asgSummary[0][0] + return CheckPointASGDiag( + summary=CheckPointASGDiagSummary( + date=asgSummary[3:13], + time=asgSummary[18:26], + passed=int(asgSummary[28:].split(".")[0].split(' ')[1].split('/')[0]), + maxtest=int(asgSummary[28:].split(".")[0].split(' ')[1].split('/')[1]), + failed=list(map(int, asgSummary.split(':')[-1].strip(' ').split(','))) + ), + tests=asgTests + ) def discovery_checkpoint_asg_diag(section: CheckPointASGDiag) -> DiscoveryResult: @@ -166,15 +167,6 @@ def check_checkpoint_asg_diag(params, section: CheckPointASGDiag) -> CheckResult if len(asg_diag_ignore) > 0: summary += ', Ignored tests: %s' % ','.join(map(str, asg_diag_ignore)) - 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) - for test in section.summary.failed: if not test in asg_diag_ignore: if test in asg_diag_warning: @@ -223,4 +215,4 @@ register.check_plugin( check_function=check_checkpoint_asg_diag, check_default_parameters={}, check_ruleset_name='checkpoint_asg_diag', -) \ No newline at end of file +) diff --git a/checkpoint_asg_diag.mkp b/checkpoint_asg_diag.mkp index 9fb2c54b6a5a315b5f0fe685e42ffcc151b1df6f..cbfad34e8bd7a552d20c4cf805a2a5440bef81e6 100644 Binary files a/checkpoint_asg_diag.mkp and b/checkpoint_asg_diag.mkp differ diff --git a/packages/checkpoint_asg_diag b/packages/checkpoint_asg_diag index 4dd5471eaa16156878241995efd0c0291916c3cd..6b01fc23b08e188c5b469e574c96a1b52005e889 100644 --- a/packages/checkpoint_asg_diag +++ b/packages/checkpoint_asg_diag @@ -12,5 +12,5 @@ 'title': 'Check Point Maestro SMO ASG Diag', 'version': '20210301.v0.1', 'version.min_required': '2.0.0b8', - 'version.packaged': '2.0.0p1', + 'version.packaged': '2021.07.14', 'version.usable_until': None} \ No newline at end of file