From 93585270dfcca56c81130dc8b8e836839246f29a Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Sun, 2 Jul 2023 09:40:51 +0000 Subject: [PATCH 1/7] Check running jobs against duration limit --- agent_based/veeam_o365jobs.py | 7 ++- agents/windows/plugins/veeam_o365_status.ps1 | 6 ++- .../agent_based/test_veeam_o356jobs.py | 43 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py index b584f9a..6bf313a 100644 --- a/agent_based/veeam_o365jobs.py +++ b/agent_based/veeam_o365jobs.py @@ -64,7 +64,12 @@ def check_veeam_o365jobs(item, params, section): job_objects, job_transferred = line[7:9] if job_state in ['Running']: - yield Result(state=State.OK, summary='Running since %s (current state is: %s)' % (job_creation_time, job_state)) + yield from check_levels( + float(job_duration), + levels_upper=params.get('duration', None), + label='Running since', + render_func=render.timespan, + ) return state = params.get('states').get(job_state, 3) diff --git a/agents/windows/plugins/veeam_o365_status.ps1 b/agents/windows/plugins/veeam_o365_status.ps1 index 0d52df6..0b70f53 100644 --- a/agents/windows/plugins/veeam_o365_status.ps1 +++ b/agents/windows/plugins/veeam_o365_status.ps1 @@ -38,7 +38,11 @@ foreach ($o365Job in $o365Jobs) $o365JobEndTime = $o365JobLastSession.EndTime | get-date -Format "dd.MM.yyyy HH\:mm\:ss" -ErrorAction SilentlyContinue - $o365JobDuration = $($o365JobLastSession.EndTime - $o365JobLastSession.CreationTime).TotalSeconds -as [int] + if ($o365JobLastState -eq 'Running') { + $o365JobDuration = $((Get-Date) - $o365JobLastSession.CreationTime).TotalSeconds -as [int] + } else { + $o365JobDuration = $($o365JobLastSession.EndTime - $o365JobLastSession.CreationTime).TotalSeconds -as [int] + } $processed = $o365JobLastSession.Statistics.ProcessedObjects -as [int] diff --git a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py index 83bff7d..e6bf347 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py @@ -130,6 +130,49 @@ def test_discovery_veeam_o365jobs(params, section, result): Metric('duration', 128.7511818), ] ), + ( + 'cmk.onmicrosoft.com Outlook Online', + { + 'jobId': '12345678-9abc-def0-1234-56789abcdef0', + }, + [ + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] + ], + [ + Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (500, 600)}, + [ + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] + ], + [ + Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 600)}, + [ + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] + ], + [ + Result(state=State.WARN, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/10 minutes 0 seconds)'), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 300)}, + [ + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] + ], + [ + Result(state=State.CRIT, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/5 minutes 0 seconds)'), + ] + ), ]) def test_check_veeam_o365jobs(item, params, section, result): fullparams = veeam_o365jobs.VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS.copy() From 47d509ce9d4d8f9361c85ca418ac180719bdfd2e Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Sun, 2 Jul 2023 10:00:24 +0000 Subject: [PATCH 2/7] Simplify testing --- agent_based/veeam_o365jobs.py | 6 +- .../agent_based/test_veeam_o356jobs.py | 83 +++++-------------- 2 files changed, 25 insertions(+), 64 deletions(-) diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py index 6bf313a..9f97bf3 100644 --- a/agent_based/veeam_o365jobs.py +++ b/agent_based/veeam_o365jobs.py @@ -54,7 +54,7 @@ def discovery_veeam_o365jobs(params, section): def check_veeam_o365jobs(item, params, section): for line in section: - if line[0] != params['jobId']: + if line[0] != params.get('jobId', None): continue job_org, job_name, job_state, \ @@ -75,14 +75,14 @@ def check_veeam_o365jobs(item, params, section): state = params.get('states').get(job_state, 3) yield Result(state=State(state), summary='Status: %s' % job_state) - if int(job_objects): + if job_objects.isdecimal(): yield from check_levels( int(job_objects), metric_name='items', label='Transferred Items', ) - if float(job_transferred): + if job_transferred.isdecimal(): yield from check_levels( float(job_transferred), metric_name='transferred', diff --git a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py index e6bf347..50309c1 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py @@ -26,40 +26,36 @@ ) from cmk.base.plugins.agent_based import veeam_o365jobs +EXAMPLE_STRING_TABLE = [ + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '', ''], + ['23456789-abcd-ef01-2345-6789abcdef01', 'cmk.onmicrosoft.com', 'Outlook Online3', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'], +] @pytest.mark.parametrize('params, section, result', [ ({}, [], []), ( - {}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], + {}, EXAMPLE_STRING_TABLE, [ Service(item='Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), - Service(item='Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}) + Service(item='Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), + Service(item='Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), ] ), ( - {'item_appearance': 'short'}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], + {'item_appearance': 'short'}, EXAMPLE_STRING_TABLE, [ Service(item='cmk Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), - Service(item='cmk Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}) + Service(item='cmk Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), + Service(item='cmk Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), ] ), ( - {'item_appearance': 'full'}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], + {'item_appearance': 'full'}, EXAMPLE_STRING_TABLE, [ Service(item='cmk.onmicrosoft.com Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), - Service(item='cmk.onmicrosoft.com Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}) + Service(item='cmk.onmicrosoft.com Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), + Service(item='cmk.onmicrosoft.com Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), ] ), ]) @@ -67,14 +63,10 @@ def test_discovery_veeam_o365jobs(params, section, result): assert list(veeam_o365jobs.discovery_veeam_o365jobs(params, section)) == result -@pytest.mark.parametrize('item, params, section, result', [ - ('', {}, [], []), +@pytest.mark.parametrize('item, params, result', [ + ('', {}, []), ( 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef'}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], [ Result(state=State.OK, summary='Status: Success'), Result(state=State.OK, summary='Transferred Items: 191.00'), @@ -87,10 +79,6 @@ def test_discovery_veeam_o365jobs(params, section, result): ), ( 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0'}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], [ Result(state=State.CRIT, summary='Status: Failed'), Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), @@ -99,10 +87,6 @@ def test_discovery_veeam_o365jobs(params, section, result): ), ( 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 300)}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], [ Result(state=State.CRIT, summary='Status: Failed'), Result(state=State.WARN, summary='Backup duration: 2 minutes 9 seconds (warn/crit at 2 minutes 0 seconds/5 minutes 0 seconds)'), @@ -120,10 +104,6 @@ def test_discovery_veeam_o365jobs(params, section, result): 'Failed': 0, } }, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'] - ], [ Result(state=State.OK, summary='Status: Failed'), Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), @@ -131,50 +111,31 @@ def test_discovery_veeam_o365jobs(params, section, result): ] ), ( - 'cmk.onmicrosoft.com Outlook Online', - { - 'jobId': '12345678-9abc-def0-1234-56789abcdef0', - }, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] - ], + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01',}, [ Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), ] ), ( - 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (500, 600)}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] - ], + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (500, 600)}, [ Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), ] ), ( - 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 600)}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] - ], + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (120, 600)}, [ Result(state=State.WARN, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/10 minutes 0 seconds)'), ] ), ( - 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 300)}, - [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'] - ], + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (120, 300)}, [ Result(state=State.CRIT, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/5 minutes 0 seconds)'), ] ), ]) -def test_check_veeam_o365jobs(item, params, section, result): +def test_check_veeam_o365jobs(item, params, result): fullparams = veeam_o365jobs.VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS.copy() fullparams.update(params) - assert list(veeam_o365jobs.check_veeam_o365jobs(item, fullparams, section)) == result + assert list(veeam_o365jobs.check_veeam_o365jobs(item, fullparams, EXAMPLE_STRING_TABLE)) == result From 16d256cf563e4826df600953895e6cca4f2a6367 Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Sun, 2 Jul 2023 10:37:11 +0000 Subject: [PATCH 3/7] Test jobs for last success --- agent_based/veeam_o365jobs.py | 22 ++++- agents/windows/plugins/veeam_o365_status.ps1 | 9 +- .../agent_based/test_veeam_o356jobs.py | 61 +++++++++++++- .../wato/check_parameters_veeam_o365jobs.py | 82 +++++++++---------- 4 files changed, 126 insertions(+), 48 deletions(-) diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py index 9f97bf3..b0a16d7 100644 --- a/agent_based/veeam_o365jobs.py +++ b/agent_based/veeam_o365jobs.py @@ -61,7 +61,7 @@ def check_veeam_o365jobs(item, params, section): job_creation_time, job_end_time, job_duration = line[1:7] job_objects = job_transferred = 0 if len(line) >= 9: - job_objects, job_transferred = line[7:9] + job_objects, job_transferred, job_last_success = line[7:10] if job_state in ['Running']: yield from check_levels( @@ -70,6 +70,16 @@ def check_veeam_o365jobs(item, params, section): label='Running since', render_func=render.timespan, ) + + if job_last_success.isdecimal(): + yield from check_levels( + value=int(job_last_success), + metric_name='age', + levels_upper=params.get('maxage', None), + render_func=render.timespan, + label='Last Success', + notice_only=True, + ) return state = params.get('states').get(job_state, 3) @@ -98,6 +108,16 @@ def check_veeam_o365jobs(item, params, section): render_func=render.timespan, ) + if job_last_success.isdecimal(): + yield from check_levels( + value=int(job_last_success), + metric_name='age', + levels_upper=params.get('maxage', None), + render_func=render.timespan, + label='Last Success', + notice_only=True, + ) + register.check_plugin( name = 'veeam_o365jobs', diff --git a/agents/windows/plugins/veeam_o365_status.ps1 b/agents/windows/plugins/veeam_o365_status.ps1 index 0b70f53..8eedaa8 100644 --- a/agents/windows/plugins/veeam_o365_status.ps1 +++ b/agents/windows/plugins/veeam_o365_status.ps1 @@ -31,6 +31,7 @@ foreach ($o365Job in $o365Jobs) $o365JobLastState = $o365Job.LastStatus $o365JobLastSession = Get-VBOJobSession -Job $o365Job -Last + $o365JobSuccessSession = Get-VBOJobSession -Job $o365Job -Last -Status Success if ($o365JobLastSession -ne $null) { @@ -61,7 +62,13 @@ foreach ($o365Job in $o365Jobs) } - Write-Host -Separator `t $jobID $jobOrganisation $jobName $o365JobLastState $o365JobCreationTime $o365JobEndTime $o365JobDuration $processed $transferred + if ($o365JobSuccessSession -ne $null) { + $lastSuccessAge = $((Get-Date) - $o365JobSuccessSession.EndTime).TotalSeconds -as [int] + } else { + $lastSuccessAge = $null + } + + Write-Host -Separator `t $jobID $jobOrganisation $jobName $o365JobLastState $o365JobCreationTime $o365JobEndTime $o365JobDuration $processed $transferred $lastSuccessAge } $o365Licenses = Get-VBOLicense diff --git a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py index 50309c1..7486159 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py @@ -27,11 +27,12 @@ from cmk.base.plugins.agent_based import veeam_o365jobs EXAMPLE_STRING_TABLE = [ - ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], - ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '', ''], - ['23456789-abcd-ef01-2345-6789abcdef01', 'cmk.onmicrosoft.com', 'Outlook Online3', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058'], + ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142', '3641'], + ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '', '', '90041'], + ['23456789-abcd-ef01-2345-6789abcdef01', 'cmk.onmicrosoft.com', 'Outlook Online3', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058', '90041'], ] + @pytest.mark.parametrize('params, section, result', [ ({}, [], []), ( @@ -75,6 +76,8 @@ def test_discovery_veeam_o365jobs(params, section, result): Metric('transferred', 142.0), Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), Metric('duration', 128.7511818), + Result(state=State.OK, notice='Last Success: 1 hour 0 minutes'), + Metric('age', 3641.0), ] ), ( @@ -83,6 +86,8 @@ def test_discovery_veeam_o365jobs(params, section, result): Result(state=State.CRIT, summary='Status: Failed'), Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), Metric('duration', 128.7511818), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( @@ -91,6 +96,8 @@ def test_discovery_veeam_o365jobs(params, section, result): Result(state=State.CRIT, summary='Status: Failed'), Result(state=State.WARN, summary='Backup duration: 2 minutes 9 seconds (warn/crit at 2 minutes 0 seconds/5 minutes 0 seconds)'), Metric('duration', 128.7511818, levels=(120.0, 300.0)), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( @@ -108,30 +115,76 @@ def test_discovery_veeam_o365jobs(params, section, result): Result(state=State.OK, summary='Status: Failed'), Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), Metric('duration', 128.7511818), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( - 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01',}, + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}, [ Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (500, 600)}, [ Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (120, 600)}, [ Result(state=State.WARN, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/10 minutes 0 seconds)'), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), ] ), ( 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'duration': (120, 300)}, [ Result(state=State.CRIT, summary='Running since: 5 minutes 14 seconds (warn/crit at 2 minutes 0 seconds/5 minutes 0 seconds)'), + Result(state=State.OK, notice='Last Success: 1 day 1 hour'), + Metric('age', 90041.0), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'maxage': (1800, 504000)}, + [ + Result(state=State.OK, summary='Status: Success'), + Result(state=State.OK, summary='Transferred Items: 191.00'), + Metric('items', 191.0), + Result(state=State.OK, summary='Transferred Data: 142 B'), + Metric('transferred', 142.0), + Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), + Metric('duration', 128.7511818), + Result(state=State.WARN, notice='Last Success: 1 hour 0 minutes (warn/crit at 30 minutes 0 seconds/5 days 20 hours)'), + Metric('age', 3641.0, levels=(1800.0, 504000.0)), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'maxage': (1800, 3600)}, + [ + Result(state=State.OK, summary='Status: Success'), + Result(state=State.OK, summary='Transferred Items: 191.00'), + Metric('items', 191.0), + Result(state=State.OK, summary='Transferred Data: 142 B'), + Metric('transferred', 142.0), + Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), + Metric('duration', 128.7511818), + Result(state=State.CRIT, notice='Last Success: 1 hour 0 minutes (warn/crit at 30 minutes 0 seconds/1 hour 0 minutes)'), + Metric('age', 3641.0, levels=(1800.0, 3600.0)), + ] + ), + ( + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'maxage': (86400, 504000)}, + [ + Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), + Result(state=State.WARN, summary='Last Success: 1 day 1 hour (warn/crit at 1 day 0 hours/5 days 20 hours)'), + Metric('age', 90041.0, levels=(86400.0, 504000.0)), ] ), ]) diff --git a/web/plugins/wato/check_parameters_veeam_o365jobs.py b/web/plugins/wato/check_parameters_veeam_o365jobs.py index 91f5ff7..db74461 100644 --- a/web/plugins/wato/check_parameters_veeam_o365jobs.py +++ b/web/plugins/wato/check_parameters_veeam_o365jobs.py @@ -78,48 +78,46 @@ def _parameter_valuespec_veeam_o365jobs(): return Dictionary( title=_('Veem for Office 365 Jobs'), elements=[ - ('duration', - Tuple( - title=_('Duration'), - elements=[ - Age(title=_('Warning at'),), - Age(title=_('Critical at'),), - ], - help=_('Thresholds for duration of the job.'), - )), - ('states', - Dictionary( - title=_('State mapping'), - elements=[ - ('Success', - MonitoringState( - title=_('Success'), - default_value=0, - )), - ('Warning', - MonitoringState( - title=_('Warning'), - default_value=1, - )), - ('Stopped', - MonitoringState( - title=_('Stopped'), - default_value=1, - )), - ('Failed', - MonitoringState( - title=_('Failed'), - default_value=2, - )), - ], - help=_('Remap the job stat to different monitoring states.'), - required_keys=[ - 'Success', - 'Warning', - 'Stopped', - 'Failed', - ], - )), + ( + 'duration', + Tuple( + title=_('Duration'), + elements=[ + Age(title=_('Warning at'),), + Age(title=_('Critical at'),), + ], + help=_('Thresholds for duration of the job.'), + ) + ), + ( + 'states', + Dictionary( + title=_('State mapping'), + elements=[ + ('Success', MonitoringState(title=_('Success'), default_value=0)), + ('Warning', MonitoringState(title=_('Warning'), default_value=1)), + ('Stopped', MonitoringState(title=_('Stopped'), default_value=1)), + ('Failed', MonitoringState(title=_('Failed'), default_value=2)), + ], + help=_('Remap the job stat to different monitoring states.'), + required_keys=[ + 'Success', + 'Warning', + 'Stopped', + 'Failed', + ], + ) + ), + ( + 'maxage', + Tuple( + title=_('Maximal time since last run'), + elements=[ + Age(title=_('Warning if older than')), + Age(title=_('Critical if older than')), + ], + ) + ), ], help=_('This rule configures thresholds Veeam for Office 365 jobs.'), ) From 797a0724eedbf458b6b12e635f7c8e7720fefbbe Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Sun, 2 Jul 2023 12:30:04 +0000 Subject: [PATCH 4/7] Improve parsing to cope with old agent plugins --- agent_based/veeam_o365jobs.py | 131 +++++++++++------- .../agent_based/test_veeam_o356jobs.py | 48 ++++++- 2 files changed, 125 insertions(+), 54 deletions(-) diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py index b0a16d7..6e68870 100644 --- a/agent_based/veeam_o365jobs.py +++ b/agent_based/veeam_o365jobs.py @@ -21,6 +21,8 @@ # 01234567-89ab-cdef-0123-456789abcdef cmk.onmicrosoft.com Outlook Online Success 29.05.2020 16:45:46 29.05.2020 16:47:55 128.7511818 191 142 # 12345678-9abc-def0-1234-56789abcdef0 cmk.onmicrosoft.com Outlook Online2 Failed 29.05.2020 16:45:46 29.05.2020 16:47:55 128.7511818 +from dataclasses import dataclass +from typing import Optional from .agent_based_api.v1 import ( Service, Result, @@ -29,6 +31,7 @@ render, register, ) +from .agent_based_api.v1.type_defs import StringTable VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS = { 'states': { @@ -40,83 +43,113 @@ } +@dataclass +class VeeamO365Job: + org: str + name: str + state: str + duration: float + objects: Optional[int] = None + transferred: Optional[int] = None + success_age: Optional[int] = None + + @property + def name_short(self): + return f"{self.org.replace('.onmicrosoft.com', '')} {self.name}" + + @property + def name_full(self): + return f"{self.org} {self.name}" + + +def parse_veeam_o365jobs(string_table: StringTable) -> dict[str, VeeamO365Job]: + parsed = {} + + for item in string_table: + try: + job = VeeamO365Job( + org=item[1], + name=item[2], + state=item[3], + duration=float(item[6]), + ) + if len(item) >= 9: + job.objects = int(item[7]) if item[7].isnumeric() else None + job.transferred = int(item[8]) if item[8].isnumeric() else None + if len(item) >= 10: + job.success_age = int(item[9]) if item[9].isnumeric() else None + parsed[item[0]] = job + except Exception: + pass + return parsed + + +register.agent_section( + name='veeam_o365jobs', + parse_function=parse_veeam_o365jobs, +) + + def discovery_veeam_o365jobs(params, section): appearance = params.get('item_appearance', 'name') - for line in section: - name = line[2] + for id, job in section.items(): + name = job.name if appearance == 'short': - name = '%s %s' % (line[1].replace('.onmicrosoft.com', ''), line[2]) + name = job.name_short elif appearance == 'full': - name = '%s %s' % (line[1], line[2]) - yield Service(item=name, parameters={'jobId': line[0]}) + name = job.name_full + yield Service(item=name, parameters={'jobId': id}) def check_veeam_o365jobs(item, params, section): - for line in section: - if line[0] != params.get('jobId', None): - continue + if params.get('jobId', None) not in section: + return + job = section.get(params.get('jobId', None)) - job_org, job_name, job_state, \ - job_creation_time, job_end_time, job_duration = line[1:7] - job_objects = job_transferred = 0 - if len(line) >= 9: - job_objects, job_transferred, job_last_success = line[7:10] - - if job_state in ['Running']: - yield from check_levels( - float(job_duration), - levels_upper=params.get('duration', None), - label='Running since', - render_func=render.timespan, - ) + if job.state == 'Running': + yield from check_levels( + float(job.duration), + levels_upper=params.get('duration', None), + label='Running since', + render_func=render.timespan, + ) + else: + state = params.get('states').get(job.state, 3) + yield Result(state=State(state), summary='Status: %s' % job.state) - if job_last_success.isdecimal(): - yield from check_levels( - value=int(job_last_success), - metric_name='age', - levels_upper=params.get('maxage', None), - render_func=render.timespan, - label='Last Success', - notice_only=True, - ) - return - - state = params.get('states').get(job_state, 3) - yield Result(state=State(state), summary='Status: %s' % job_state) - - if job_objects.isdecimal(): + if job.objects is not None: yield from check_levels( - int(job_objects), + int(job.objects), metric_name='items', label='Transferred Items', ) - if job_transferred.isdecimal(): + if job.transferred is not None: yield from check_levels( - float(job_transferred), + float(job.transferred), metric_name='transferred', label='Transferred Data', render_func=render.bytes, ) yield from check_levels( - float(job_duration), + float(job.duration), metric_name='duration', levels_upper=params.get('duration', None), label='Backup duration', render_func=render.timespan, ) - if job_last_success.isdecimal(): - yield from check_levels( - value=int(job_last_success), - metric_name='age', - levels_upper=params.get('maxage', None), - render_func=render.timespan, - label='Last Success', - notice_only=True, - ) + if job.success_age is not None: + yield from check_levels( + value=int(job.success_age), + metric_name='age', + levels_upper=params.get('maxage', None), + render_func=render.timespan, + label='Last Success', + notice_only=True, + ) register.check_plugin( diff --git a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py index 7486159..e0f0f14 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py @@ -27,33 +27,59 @@ from cmk.base.plugins.agent_based import veeam_o365jobs EXAMPLE_STRING_TABLE = [ + ['01234567-89ab-cdef-0123-456789abcold', 'cmk.onmicrosoft.com', 'Outlook Old Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142'], + ['12345678-9abc-def0-1234-56789abcdold', 'cmk.onmicrosoft.com', 'Outlook Old Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818'], ['01234567-89ab-cdef-0123-456789abcdef', 'cmk.onmicrosoft.com', 'Outlook Online', 'Success', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '191', '142', '3641'], ['12345678-9abc-def0-1234-56789abcdef0', 'cmk.onmicrosoft.com', 'Outlook Online2', 'Failed', '29.05.2020 16:45:46', '29.05.2020 16:47:55', '128.7511818', '', '', '90041'], ['23456789-abcd-ef01-2345-6789abcdef01', 'cmk.onmicrosoft.com', 'Outlook Online3', 'Running', '29.05.2020 16:45:46', '31.12.9999 23:59:59', '314', '0', '28058', '90041'], ] +EXAMPLE_SECTION = { + '01234567-89ab-cdef-0123-456789abcold': veeam_o365jobs.VeeamO365Job(org='cmk.onmicrosoft.com', name='Outlook Old Online', state='Success', duration=128.7511818, objects=191, transferred=142), + '12345678-9abc-def0-1234-56789abcdold': veeam_o365jobs.VeeamO365Job(org='cmk.onmicrosoft.com', name='Outlook Old Online2', state='Failed', duration=128.7511818), + '01234567-89ab-cdef-0123-456789abcdef': veeam_o365jobs.VeeamO365Job(org='cmk.onmicrosoft.com', name='Outlook Online', state='Success', duration=128.7511818, objects=191, transferred=142, success_age=3641), + '12345678-9abc-def0-1234-56789abcdef0': veeam_o365jobs.VeeamO365Job(org='cmk.onmicrosoft.com', name='Outlook Online2', state='Failed', duration=128.7511818, objects=None, transferred=None, success_age=90041), + '23456789-abcd-ef01-2345-6789abcdef01': veeam_o365jobs.VeeamO365Job(org='cmk.onmicrosoft.com', name='Outlook Online3', state='Running', duration=314, objects=0, transferred=28058, success_age=90041), +} + + +@pytest.mark.parametrize('string_table, result', [ + ([], {}), + ( + EXAMPLE_STRING_TABLE, + EXAMPLE_SECTION + ), +]) +def test_parse_win_scheduled_task(string_table, result): + assert veeam_o365jobs.parse_veeam_o365jobs(string_table) == result @pytest.mark.parametrize('params, section, result', [ - ({}, [], []), + ({}, {}, []), ( - {}, EXAMPLE_STRING_TABLE, + {}, EXAMPLE_SECTION, [ + Service(item='Outlook Old Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcold'}), + Service(item='Outlook Old Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdold'}), Service(item='Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), Service(item='Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), Service(item='Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), ] ), ( - {'item_appearance': 'short'}, EXAMPLE_STRING_TABLE, + {'item_appearance': 'short'}, EXAMPLE_SECTION, [ + Service(item='cmk Outlook Old Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcold'}), + Service(item='cmk Outlook Old Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdold'}), Service(item='cmk Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), Service(item='cmk Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), Service(item='cmk Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), ] ), ( - {'item_appearance': 'full'}, EXAMPLE_STRING_TABLE, + {'item_appearance': 'full'}, EXAMPLE_SECTION, [ + Service(item='cmk.onmicrosoft.com Outlook Old Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcold'}), + Service(item='cmk.onmicrosoft.com Outlook Old Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdold'}), Service(item='cmk.onmicrosoft.com Outlook Online', parameters={'jobId': '01234567-89ab-cdef-0123-456789abcdef'}), Service(item='cmk.onmicrosoft.com Outlook Online2', parameters={'jobId': '12345678-9abc-def0-1234-56789abcdef0'}), Service(item='cmk.onmicrosoft.com Outlook Online3', parameters={'jobId': '23456789-abcd-ef01-2345-6789abcdef01'}), @@ -80,6 +106,18 @@ def test_discovery_veeam_o365jobs(params, section, result): Metric('age', 3641.0), ] ), + ( + 'cmk.onmicrosoft.com Outlook Old Online', {'jobId': '01234567-89ab-cdef-0123-456789abcold'}, + [ + Result(state=State.OK, summary='Status: Success'), + Result(state=State.OK, summary='Transferred Items: 191.00'), + Metric('items', 191.0), + Result(state=State.OK, summary='Transferred Data: 142 B'), + Metric('transferred', 142.0), + Result(state=State.OK, summary='Backup duration: 2 minutes 9 seconds'), + Metric('duration', 128.7511818), + ] + ), ( 'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0'}, [ @@ -191,4 +229,4 @@ def test_discovery_veeam_o365jobs(params, section, result): def test_check_veeam_o365jobs(item, params, result): fullparams = veeam_o365jobs.VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS.copy() fullparams.update(params) - assert list(veeam_o365jobs.check_veeam_o365jobs(item, fullparams, EXAMPLE_STRING_TABLE)) == result + assert list(veeam_o365jobs.check_veeam_o365jobs(item, fullparams, EXAMPLE_SECTION)) == result From da9208c76c0a93ee1bd5b1bcd8ddd207c546872e Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Sun, 2 Jul 2023 12:31:49 +0000 Subject: [PATCH 5/7] Prepare for Version 2.6.1 --- package | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package b/package index b1bcb7c..a1ca21f 100644 --- a/package +++ b/package @@ -20,7 +20,7 @@ ]}, 'name': 'veeam_o365', 'title': u'Veeam for Office 365 Checks', - 'version': '2.6.0', + 'version': '2.6.1', 'version.min_required': '2.2.0', 'version.packaged': '2.2.0', 'version.usable_until': '2.3.0' From d6756155c9c95b93d7f2f0897990240064e33752 Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Mon, 3 Jul 2023 05:35:24 +0000 Subject: [PATCH 6/7] Rename maxage to success_maxage --- agent_based/veeam_o365jobs.py | 2 +- .../cmk/base/plugins/agent_based/test_veeam_o356jobs.py | 6 +++--- web/plugins/wato/check_parameters_veeam_o365jobs.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py index 6e68870..0228045 100644 --- a/agent_based/veeam_o365jobs.py +++ b/agent_based/veeam_o365jobs.py @@ -145,7 +145,7 @@ def check_veeam_o365jobs(item, params, section): yield from check_levels( value=int(job.success_age), metric_name='age', - levels_upper=params.get('maxage', None), + levels_upper=params.get('success_maxage', None), render_func=render.timespan, label='Last Success', notice_only=True, diff --git a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py index e0f0f14..fc7f1d4 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_veeam_o356jobs.py @@ -190,7 +190,7 @@ def test_discovery_veeam_o365jobs(params, section, result): ] ), ( - 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'maxage': (1800, 504000)}, + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'success_maxage': (1800, 504000)}, [ Result(state=State.OK, summary='Status: Success'), Result(state=State.OK, summary='Transferred Items: 191.00'), @@ -204,7 +204,7 @@ def test_discovery_veeam_o365jobs(params, section, result): ] ), ( - 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'maxage': (1800, 3600)}, + 'cmk.onmicrosoft.com Outlook Online', {'jobId': '01234567-89ab-cdef-0123-456789abcdef', 'success_maxage': (1800, 3600)}, [ Result(state=State.OK, summary='Status: Success'), Result(state=State.OK, summary='Transferred Items: 191.00'), @@ -218,7 +218,7 @@ def test_discovery_veeam_o365jobs(params, section, result): ] ), ( - 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'maxage': (86400, 504000)}, + 'cmk.onmicrosoft.com Outlook Online3', {'jobId': '23456789-abcd-ef01-2345-6789abcdef01', 'success_maxage': (86400, 504000)}, [ Result(state=State.OK, summary='Running since: 5 minutes 14 seconds'), Result(state=State.WARN, summary='Last Success: 1 day 1 hour (warn/crit at 1 day 0 hours/5 days 20 hours)'), diff --git a/web/plugins/wato/check_parameters_veeam_o365jobs.py b/web/plugins/wato/check_parameters_veeam_o365jobs.py index db74461..35dd381 100644 --- a/web/plugins/wato/check_parameters_veeam_o365jobs.py +++ b/web/plugins/wato/check_parameters_veeam_o365jobs.py @@ -26,7 +26,7 @@ TextAscii, Tuple, ) -from cmk.gui.plugins.wato import ( +from cmk.gui.plugins.wato.utils import ( CheckParameterRulespecWithItem, RulespecGroupCheckParametersApplications, RulespecGroupCheckParametersDiscovery, @@ -109,9 +109,9 @@ def _parameter_valuespec_veeam_o365jobs(): ) ), ( - 'maxage', + 'success_maxage', Tuple( - title=_('Maximal time since last run'), + title=_('Maximal time since last successfull run'), elements=[ Age(title=_('Warning if older than')), Age(title=_('Critical if older than')), From ed342bddc52152a29552778cbbba437a96d156b5 Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Mon, 3 Jul 2023 05:37:08 +0000 Subject: [PATCH 7/7] Migrate from legacy plugins --- .devcontainer/symlink.sh | 5 +++++ .../plugins/metrics => metrics}/veeam_o365jobs.py | 15 ++++++++++++++- .../metrics => metrics}/veeam_o365licenses.py | 2 +- package | 15 ++++++++------- .../agent_bakery/veeam_o365.py | 2 +- .../check_parameters/veeam_o365jobs.py | 0 .../check_parameters/veeam_o365licenses.py | 2 +- 7 files changed, 30 insertions(+), 11 deletions(-) rename {web/plugins/metrics => metrics}/veeam_o365jobs.py (86%) rename {web/plugins/metrics => metrics}/veeam_o365licenses.py (97%) rename web/plugins/wato/agent_bakery_veeam_o365.py => wato/agent_bakery/veeam_o365.py (97%) rename web/plugins/wato/check_parameters_veeam_o365jobs.py => wato/check_parameters/veeam_o365jobs.py (100%) rename web/plugins/wato/check_parameters_veeam_o365licenses.py => wato/check_parameters/veeam_o365licenses.py (98%) diff --git a/.devcontainer/symlink.sh b/.devcontainer/symlink.sh index a9b5e65..18d6cf6 100755 --- a/.devcontainer/symlink.sh +++ b/.devcontainer/symlink.sh @@ -8,6 +8,11 @@ done; rm -rfv $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based ln -sv $WORKSPACE/agent_based $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based +for DIR in 'wato' 'metrics'; do + rm -rfv $OMD_ROOT/local/lib/python3/cmk/gui/plugins/$DIR + ln -sv $WORKSPACE/$DIR $OMD_ROOT/local/lib/python3/cmk/gui/plugins/$DIR +done; + mkdir -p $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins ln -sv $WORKSPACE/bakery $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins/bakery diff --git a/web/plugins/metrics/veeam_o365jobs.py b/metrics/veeam_o365jobs.py similarity index 86% rename from web/plugins/metrics/veeam_o365jobs.py rename to metrics/veeam_o365jobs.py index a928eb9..3365403 100644 --- a/web/plugins/metrics/veeam_o365jobs.py +++ b/metrics/veeam_o365jobs.py @@ -19,7 +19,7 @@ from cmk.gui.i18n import _ -from cmk.gui.plugins.metrics import ( +from cmk.gui.plugins.metrics.utils import ( check_metrics, metric_info, graph_info, @@ -32,6 +32,7 @@ 'transferred': {'name': 'veeam_o365jobs_transferred'}, 'duration': {'name': 'veeam_o365jobs_duration'}, 'items': {'name': 'veeam_o365jobs_items'}, + 'age': {'name': 'veeam_o365jobs_age'}, } @@ -53,6 +54,12 @@ 'color': '#00b336', } +metric_info['veeam_o365jobs_age'] = { + 'title': _('Time since last successfull run'), + 'unit': 's', + 'color': '#00b336', +} + graph_info['veeam_o365jobs_transferred'] = { 'title': _('Veeam for Office 365 Job'), @@ -76,6 +83,12 @@ 'range': (0, 'veeam_o365jobs_items:max'), } +graph_info['veeam_o365jobs_age'] = { + 'title': _('Veeam for Office 365 Job'), + 'metrics': [('veeam_o365jobs_age', 'area')], + 'range': (0, 'veeam_o365jobs_age:max'), +} + perfometer_info.append({ 'type': 'stacked', diff --git a/web/plugins/metrics/veeam_o365licenses.py b/metrics/veeam_o365licenses.py similarity index 97% rename from web/plugins/metrics/veeam_o365licenses.py rename to metrics/veeam_o365licenses.py index 48d0e5b..1089241 100644 --- a/web/plugins/metrics/veeam_o365licenses.py +++ b/metrics/veeam_o365licenses.py @@ -19,7 +19,7 @@ from cmk.gui.i18n import _ -from cmk.gui.plugins.metrics import ( +from cmk.gui.plugins.metrics.utils import ( check_metrics, metric_info, graph_info, diff --git a/package b/package index a1ca21f..577ddce 100644 --- a/package +++ b/package @@ -8,16 +8,17 @@ 'windows/plugins/veeam_o365_status.ps1', ], 'checkman': ['veeam_o365jobs', 'veeam_o365licenses'], + 'gui': [ + 'metrics/veeam_o365jobs.py', + 'metrics/veeam_o365licenses.py', + 'wato/agent_bakery/veeam_o365.py', + 'wato/check_parameters/veeam_o365licenses.py', + 'wato/check_parameters/veeam_o365jobs.py', + ], 'lib': [ 'python3/cmk/base/cee/plugins/bakery/veeam_o365.py', ], - 'web': [ - 'plugins/metrics/veeam_o365jobs.py', - 'plugins/metrics/veeam_o365licenses.py', - 'plugins/wato/agent_bakery_veeam_o365.py', - 'plugins/wato/check_parameters_veeam_o365licenses.py', - 'plugins/wato/check_parameters_veeam_o365jobs.py', - ]}, + }, 'name': 'veeam_o365', 'title': u'Veeam for Office 365 Checks', 'version': '2.6.1', diff --git a/web/plugins/wato/agent_bakery_veeam_o365.py b/wato/agent_bakery/veeam_o365.py similarity index 97% rename from web/plugins/wato/agent_bakery_veeam_o365.py rename to wato/agent_bakery/veeam_o365.py index b3a976d..744c394 100644 --- a/web/plugins/wato/agent_bakery_veeam_o365.py +++ b/wato/agent_bakery/veeam_o365.py @@ -21,7 +21,7 @@ from cmk.gui.valuespec import ( DropdownChoice, ) -from cmk.gui.plugins.wato import ( +from cmk.gui.plugins.wato.utils import ( HostRulespec, rulespec_registry, ) diff --git a/web/plugins/wato/check_parameters_veeam_o365jobs.py b/wato/check_parameters/veeam_o365jobs.py similarity index 100% rename from web/plugins/wato/check_parameters_veeam_o365jobs.py rename to wato/check_parameters/veeam_o365jobs.py diff --git a/web/plugins/wato/check_parameters_veeam_o365licenses.py b/wato/check_parameters/veeam_o365licenses.py similarity index 98% rename from web/plugins/wato/check_parameters_veeam_o365licenses.py rename to wato/check_parameters/veeam_o365licenses.py index 3328920..079ba97 100644 --- a/web/plugins/wato/check_parameters_veeam_o365licenses.py +++ b/wato/check_parameters/veeam_o365licenses.py @@ -26,7 +26,7 @@ TextAscii, Tuple, ) -from cmk.gui.plugins.wato import ( +from cmk.gui.plugins.wato.utils import ( CheckParameterRulespecWithItem, RulespecGroupCheckParametersApplications, rulespec_registry,