diff --git a/agent_based/checkpoint_asg_diag.py b/agent_based/checkpoint_asg_diag.py index 42fd3927d2f4657a1c38fe57f318a67aac814de5..328335e4fabdb837dda21e19c0cf9855b7573a10 100644 --- a/agent_based/checkpoint_asg_diag.py +++ b/agent_based/checkpoint_asg_diag.py @@ -34,45 +34,45 @@ # sample section # [ # [ -# [u'On 2020-10-23, At 01:00:02, Passed: 28/30 tests. Failed tests: 11,28'] +# ['On 2020-10-23, At 01:00:02, Passed: 28/30 tests. Failed tests: 11,28'] # ], # [ -# [u'1', u'System Health', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'2', u'Resources', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'3', u'Software Provision', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'4', u'Media Details', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'5', u'SSD Health', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'6', u'Firmware Verifier', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'7', u'Distribution Mode', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'8', u'DXL Balance', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'9', u'Policy', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'10', u'AMW Policy', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'11', u'SWB Updates', u'2020-10-23 01:00:02', u'Failed (!)', u''], -# [u'12', u'Installation', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'13', u'Security Group', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'14', u'Cores Distribution', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'15', u'Clock', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'16', u'Licenses', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'17', u'IPS Enhancement', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'18', u'Configuration Files', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'19', u'MAC Setting', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'20', u'ARP Consistency', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'21', u'Bond', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'22', u'IPv4 Route', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'23', u'IPv6 Route', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'24', u'Dynamic Routing', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'25', u'Local ARP', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'26', u'IGMP Consistency', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'27', u'PIM Neighbors', u'2020-10-23 01:00:02', u'Passed', u'Not configured'], -# [u'28', u'Core Dumps', u'2020-10-23 01:00:02', u'Failed (!)', u''], -# [u'29', u'Processes', u'2020-10-23 01:00:02', u'Passed', u''], -# [u'30', u'Performance hogs', u'2020-10-23 01:00:02', u'Passed', u''] +# ['1', 'System Health', '2020-10-23 01:00:02', 'Passed', ''], +# ['2', 'Resources', '2020-10-23 01:00:02', 'Passed', ''], +# ['3', 'Software Provision', '2020-10-23 01:00:02', 'Passed', ''], +# ['4', 'Media Details', '2020-10-23 01:00:02', 'Passed', ''], +# ['5', 'SSD Health', '2020-10-23 01:00:02', 'Passed', ''], +# ['6', 'Firmware Verifier', '2020-10-23 01:00:02', 'Passed', ''], +# ['7', 'Distribution Mode', '2020-10-23 01:00:02', 'Passed', ''], +# ['8', 'DXL Balance', '2020-10-23 01:00:02', 'Passed', ''], +# ['9', 'Policy', '2020-10-23 01:00:02', 'Passed', ''], +# ['10', 'AMW Policy', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['11', 'SWB Updates', '2020-10-23 01:00:02', 'Failed (!)', ''], +# ['12', 'Installation', '2020-10-23 01:00:02', 'Passed', ''], +# ['13', 'Security Group', '2020-10-23 01:00:02', 'Passed', ''], +# ['14', 'Cores Distribution', '2020-10-23 01:00:02', 'Passed', ''], +# ['15', 'Clock', '2020-10-23 01:00:02', 'Passed', ''], +# ['16', 'Licenses', '2020-10-23 01:00:02', 'Passed', ''], +# ['17', 'IPS Enhancement', '2020-10-23 01:00:02', 'Passed', ''], +# ['18', 'Configuration Files', '2020-10-23 01:00:02', 'Passed', ''], +# ['19', 'MAC Setting', '2020-10-23 01:00:02', 'Passed', ''], +# ['20', 'ARP Consistency', '2020-10-23 01:00:02', 'Passed', ''], +# ['21', 'Bond', '2020-10-23 01:00:02', 'Passed', ''], +# ['22', 'IPv4 Route', '2020-10-23 01:00:02', 'Passed', ''], +# ['23', 'IPv6 Route', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['24', 'Dynamic Routing', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['25', 'Local ARP', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['26', 'IGMP Consistency', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['27', 'PIM Neighbors', '2020-10-23 01:00:02', 'Passed', 'Not configured'], +# ['28', 'Core Dumps', '2020-10-23 01:00:02', 'Failed (!)', ''], +# ['29', 'Processes', '2020-10-23 01:00:02', 'Passed', ''], +# ['30', 'Performance hogs', '2020-10-23 01:00:02', 'Passed', ''] # ] # ] # - -from typing import Mapping, Dict, List, Tuple, NamedTuple +import time +from typing import List, NamedTuple from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, @@ -90,92 +90,102 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import ( startswith, all_of, any_of, + check_levels, ) -class CheckPointASGDiagSummary(NamedTuple): +class CheckpointAsgDiagSummary(NamedTuple): date: str time: str + days_ago: int passed: int maxtest: int failed: list -class CheckPointASGDiag(NamedTuple): - summary: CheckPointASGDiagSummary - tests: List +class CheckpointAsgDiagTest(NamedTuple): + index: str + name: str + lastrun: str + result: str + comment: str -def parse_checkpoint_asg_diag(string_table: List[StringTable]) -> CheckPointASGDiag: - asgSummary, asgTests = string_table +class CheckpointAsgDiag(NamedTuple): + summary: CheckpointAsgDiagSummary + tests: List[CheckpointAsgDiagTest] - # ToDo: change date to real date string, and add warn/crit if last run to old +def parse_checkpoint_asg_diag(string_table: List[StringTable]) -> CheckpointAsgDiag: + asgSummary, asgTests = string_table + + # sample asgSummary [['On 2020-10-23, At 01:00:02, Passed: 28/30 tests. Failed tests: 11,28']] if len(asgSummary) != 0: asgSummary = asgSummary[0][0] - return CheckPointASGDiag( - summary=CheckPointASGDiagSummary( + passed, max = asgSummary[28:].split('.')[0].split(' ')[1].split('/') + 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]), + days_ago=int((time.time() - time.mktime(time.strptime(asgSummary[3:13], '%Y-%m-%d'))) / 86400), + passed=int(passed), + maxtest=int(max), failed=list(map(int, asgSummary.split(':')[-1].strip(' ').split(','))) ), - tests=asgTests + tests=[CheckpointAsgDiagTest(*test) for test in asgTests] ) -def discovery_checkpoint_asg_diag(section: CheckPointASGDiag) -> DiscoveryResult: +def discovery_checkpoint_asg_diag(section: CheckpointAsgDiag) -> DiscoveryResult: yield Service(parameters={}) -def check_checkpoint_asg_diag(params, section: CheckPointASGDiag) -> CheckResult: - class CheckPointASGDiagTest(NamedTuple): - index: str - name: str - lastrun: str - result: str - comment: str - - 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 = [] - asg_diag_warning = [] - - if params: - asg_diag_ignore = params.get('asg_diag_ignore', []) - asg_diag_warning = params.get('asg_diag_warning', []) +def check_checkpoint_asg_diag(params, section: CheckpointAsgDiag) -> CheckResult: + state = 0 + asg_diag_ignore = params['asg_diag_ignore'] + asg_diag_warning = params['asg_diag_warning'] asg_diag_ignore.sort() + asg_diag_warning.sort() + + yield Result(state=State.OK, summary=f'Last run on: {section.summary.date} at: {section.summary.time}') + yield from check_levels( + value=section.summary.days_ago, + label='Days ago', + levels_upper=params['levels_upper_last_run'], + render_func=lambda v: str(v) + ) + summary = f'Tests Passed {section.summary.passed}/{section.summary.maxtest},' + if len(section.summary.failed) > 0: + summary += f' Failed: {",".join(map(str, section.summary.failed))}' if len(asg_diag_ignore) > 0: - summary += ', Ignored tests: %s' % ','.join(map(str, asg_diag_ignore)) + summary += f', Ignored: {",".join(map(str, asg_diag_ignore))}' for test in section.summary.failed: - if not test in asg_diag_ignore: + if test not in asg_diag_ignore: if test in asg_diag_warning: - if state == State.OK: - state = State.WARN + state = max(state, 1) else: - state = State.CRIT + state = 2 + + yield Result(state=State(state), summary=summary) - yield Result(state=state, summary=summary, details=details) + yield Result( + state=State.OK, + notice='\nTo verify this output use the "asg diag verify" command on the Check Point SMO CLI.\n' + ) + + for test in section.tests: + result = test.result + if result.lower().startswith('failed'): + if int(test.index) in asg_diag_ignore: + result = result.replace(' (!)', '') + elif int(test.index) not in asg_diag_warning: + result = result.replace(' (!)', ' (!!)') + notice = f'Index: {test.index}, Name: {test.name}, LastRun: {test.lastrun}, Restult: {result}' + if test.comment != '': + notice += f', Comment: {test.comment}' + yield Result(state=State.OK, notice=notice) register.snmp_section( @@ -213,6 +223,10 @@ register.check_plugin( service_name='ASG Diag', discovery_function=discovery_checkpoint_asg_diag, check_function=check_checkpoint_asg_diag, - check_default_parameters={}, + check_default_parameters={ + 'levels_upper_last_run': (3, 5), + 'asg_diag_ignore': [], + 'asg_diag_warning': [], + }, check_ruleset_name='checkpoint_asg_diag', ) diff --git a/checkpoint_asg_diag.mkp b/checkpoint_asg_diag.mkp index cbfad34e8bd7a552d20c4cf805a2a5440bef81e6..171cfa571e614c1ad2a223fd023adce8f2502954 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 6b01fc23b08e188c5b469e574c96a1b52005e889..407764388960dd68ab81aa013136241a8ec79351 100644 --- a/packages/checkpoint_asg_diag +++ b/packages/checkpoint_asg_diag @@ -1,16 +1,14 @@ {'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', 'description': 'Monitor Check Point Maestro SMO Test status (asg diag ' 'verify)\n' - '\n' - '- 2020-11-03: initial release for CMK 1.6.x\n' - '- 2021-03-01: rewrite for CMK 2.x\n', + '\n', 'download_url': 'http://thl-cmk.hopto.org/', 'files': {'agent_based': ['checkpoint_asg_diag.py'], 'web': ['plugins/wato/checkpoint_asg_diag.py']}, 'name': 'checkpoint_asg_diag', 'num_files': 2, 'title': 'Check Point Maestro SMO ASG Diag', - 'version': '20210301.v0.1', - 'version.min_required': '2.0.0b8', + 'version': '20210911.v0.2', + 'version.min_required': '2.0.0', 'version.packaged': '2021.07.14', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/wato/checkpoint_asg_diag.py b/web/plugins/wato/checkpoint_asg_diag.py index f2257df7002746d09fd29ebfe3cc5048f8d48818..70ec26707a038a3fcd3d0b6131744647b9511c7a 100644 --- a/web/plugins/wato/checkpoint_asg_diag.py +++ b/web/plugins/wato/checkpoint_asg_diag.py @@ -6,8 +6,8 @@ from cmk.gui.i18n import _ from cmk.gui.valuespec import ( Dictionary, Integer, - TextAscii, ListOfStrings, + Tuple, ) from cmk.gui.plugins.wato import ( @@ -19,24 +19,41 @@ from cmk.gui.plugins.wato import ( def _parameter_valuespec_checkpoint_asg_diag(): return Dictionary(elements=[ + ('levels_upper_last_run', + Tuple( + title=_('Maximum days no run "asg diag verify"'), + elements=[ + Integer( + title=_('Warning at'), + unit='days', + default_value=3, + minvalue=1, + ), + Integer( + title=_('Critical at'), + unit='days', + default_value=5, + minvalue=1, + ) + ], + )), ('asg_diag_ignore', ListOfStrings( - title=_('Index list of ASG Diag tests to ignore'), + title=_('Index list of ignored failde tests'), orientation='horizontal', allow_empty=False, valuespec=Integer(minvalue=1, maxvalue=99), - help=_('there will be no warning/critical if this tests are not "Passed"'), - ) - ), + help=_('This tests will be ignored if the are not "Passed". The monitoring state will stay OK'), + )), ('asg_diag_warning', ListOfStrings( - title=_('Set monitoring state to warining if ASG Diag state is "Failed" for the following tests'), + title=_('Indix list of WARNING only failed tests'), orientation='horizontal', allow_empty=False, valuespec=Integer(minvalue=1, maxvalue=99), - help=_('there will be only warning if this tests are not "Passed", else there will be a critical.'), - ) - ), + help=_('For this tests the monitoring state will be WARNING if the test result is not "Passed", ' + 'all other failed tests set the monitoring state to CRITICAL.'), + )), ]) @@ -44,8 +61,7 @@ rulespec_registry.register( CheckParameterRulespecWithItem( check_group_name='checkpoint_asg_diag', group=RulespecGroupCheckParametersNetworking, - item_spec=lambda: TextAscii(title=_('Check Point ASG Diag'), ), match_type='dict', parameter_valuespec=_parameter_valuespec_checkpoint_asg_diag, title=lambda: _('Check Point ASG Diag'), - )) \ No newline at end of file + ))