Skip to content

Commit

Permalink
Rework for Checkmk 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuka committed Jun 5, 2024
1 parent 79026c9 commit 75e913f
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 505 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash
set -e

NAME=$(python3 -c 'print(eval(open("package").read())["name"])')
VERSION=$(python3 -c 'print(eval(open("package").read())["version"])')
rm /omd/sites/cmk/var/check_mk/packages/${NAME} \
/omd/sites/cmk/var/check_mk/packages_local/${NAME}-*.mkp ||:

mkp -v package package 2>&1 | sed '/Installing$/Q' ||:
mkp -v package package

rm $NAME-$VERSION.mkp
cp /omd/sites/cmk/var/check_mk/packages_local/$NAME-$VERSION.mkp .

mkp inspect $NAME-$VERSION.mkp
19 changes: 10 additions & 9 deletions agent_based/veeam_o365jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
# 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 .agent_based_api.v1 import (
from cmk.agent_based.v2 import (
Service,
Result,
State,
check_levels,
render,
register,
CheckPlugin,
RuleSetType,
)

VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS = {
Expand Down Expand Up @@ -88,20 +89,20 @@ def check_veeam_o365jobs(item, params, section):
yield from check_levels(
float(job_duration),
metric_name='duration',
levels_upper=params.get('duration', None),
levels_upper=params.get('duration', ('no_levels', None)),
label='Backup duration',
render_func=render.timespan,
)


register.check_plugin(
name = 'veeam_o365jobs',
check_plugin_veeam_o365jobs = CheckPlugin(
name='veeam_o365jobs',
service_name = 'VEEAM O365 Job %s',
discovery_ruleset_name='inventory_veeam_o365jobs_rules',
discovery_ruleset_type=register.RuleSetType.MERGED,
discovery_function=discovery_veeam_o365jobs,
discovery_ruleset_name='veeam_o365jobs',
discovery_ruleset_type=RuleSetType.MERGED,
discovery_default_parameters={},
discovery_function = discovery_veeam_o365jobs,
check_function = check_veeam_o365jobs,
check_function=discovery_veeam_o365jobs,
check_ruleset_name='veeam_o365jobs',
check_default_parameters=VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS,
)
74 changes: 28 additions & 46 deletions agent_based/veeam_o365licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
# <<<veeam_o365licenses:sep(9) >>>
# Valid 28.06.2020 02:00:00 2592000 42 50000

from .agent_based_api.v1 import (
from cmk.agent_based.v2 import (
Service,
Result,
State,
check_levels,
render,
Metric,
register,
CheckPlugin,
)


Expand All @@ -50,54 +49,37 @@ def check_veeam_o365licenses(item, params, section):

yield from check_levels(
float(license_validity),
levels_lower=params.get('validity', (0, 0)),
levels_lower=params.get('validity', ('fixed', (0, 0))),
label='Period of validity' if float(license_validity) > 0 else 'Expired since',
render_func=lambda f: render.timespan(f if f > 0 else -f),
)

license_params = params.get('licenses', None)

if license_params is False:
license_warn = None
license_crit = None
elif not license_params:
license_warn = int(license_total)
license_crit = int(license_total)
elif isinstance(license_params[0], int):
license_warn = max(0, int(license_total) - license_params[0])
license_crit = max(0, int(license_total) - license_params[1])
else:
license_warn = int(license_total) * (1 - license_params[0] / 100.0)
license_crit = int(license_total) * (1 - license_params[1] / 100.0)

yield Metric('licenses',
int(license_used),
levels=(license_warn, license_crit),
boundaries=(0, int(license_total)))

if int(license_used) <= int(license_total):
infotext = 'used %d out of %d licenses' % (int(license_used), int(license_total))
else:
infotext = 'used %d licenses, but you have only %d' % (int(license_used), int(license_total))

if license_crit is not None and int(license_used) >= license_crit:
status = State.CRIT
elif license_warn is not None and int(license_used) >= license_warn:
status = State.WARN
else:
status = State.OK

if license_crit is not None:
infotext += ' (warn/crit at %d/%d)' % (license_warn, license_crit)

yield Result(state=status, summary=infotext)


register.check_plugin(
name = 'veeam_o365licenses',
license_used = int(license_used)
license_total = int(license_total)

match params.get('licenses', None):
case ('always_ok', None):
levels = ('no_levels', None)
case ('absolute', {'warn': warn, 'crit': crit}):
levels = ('fixed', (license_total - warn, license_total - crit))
case ('percentage', {'warn': warn, 'crit': crit}):
levels = ('fixed', (int(license_total * (100 - warn) / 100), int(license_total * (100 - crit) / 100)))
case _:
levels = ('fixed', (int(license_total), int(license_total)))

yield from check_levels(license_used,
label="used",
render_func=lambda v: f"{v:d}",
levels_upper=levels,
metric_name='licenses',
boundaries=(0, int(license_total)))


check_plugin_veeam_o365jobs = CheckPlugin(
name='veeam_o365licenses',
service_name = 'VEEAM O365 License %s',
discovery_function = discovery_veeam_o365licenses,
check_function = check_veeam_o365licenses,
discovery_function=discovery_veeam_o365licenses,
check_function=check_veeam_o365licenses,
check_ruleset_name='veeam_o365licenses',
check_default_parameters={},
)
3 changes: 2 additions & 1 deletion bakery/veeam_o365.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@


def get_veeam_o365_files(conf: Any) -> FileGenerator:
yield Plugin(base_os=OS.WINDOWS, source=Path('veeam_o365_status.ps1'))
if conf.get('agent', 'do_not_deploy') == 'deploy':
yield Plugin(base_os=OS.WINDOWS, source=Path('veeam_o365_status.ps1'))


register.bakery_plugin(
Expand Down
136 changes: 136 additions & 0 deletions graphing/veeam_o365.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# Copyright (C) 2020-2024 Marius Rieder <marius.rieder@durchmesser.ch>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from cmk.graphing.v1 import (
graphs as g,
metrics as m,
perfometers as p,
translations as t,
)

translation_veeam_o365jobs = t.Translation(
name='veeam_o365jobs',
check_commands=[t.PassiveCheck('veeam_o365jobs')],
translations={
'transferred': t.RenameTo('veeam_o365jobs_transferred'),
'duration': t.RenameTo('veeam_o365jobs_duration'),
'items': t.RenameTo('veeam_o365jobs_items'),
}
)

translation_veeam_o365licenses = t.Translation(
name='veeam_o365licenses',
check_commands=[t.PassiveCheck('veeam_o365licenses')],
translations={
'licenses': t.RenameTo('veeam_o365licenses_licenses'),
}
)

metric_veeam_o365jobs_transferred = m.Metric(
name='veeam_o365jobs_transferred',
title=m.Title('Data Transferred'),
unit=m.Unit(m.IECNotation("bits")),
color=m.Color.GREEN,
)

metric_veeam_o365jobs_duration = m.Metric(
name='veeam_o365jobs_duration',
title=m.Title('Job Duration'),
unit=m.Unit(m.TimeNotation()),
color=m.Color.GREEN,
)

metric_veeam_o365jobs_transferred = m.Metric(
name='veeam_o365jobs_items',
title=m.Title('Items Transferred'),
unit=m.Unit(m.DecimalNotation(""), m.StrictPrecision(0)),
color=m.Color.GREEN,
)

metric_veeam_o365licenses_licenses = m.Metric(
name='veeam_o365licenses_licenses',
title=m.Title('Used licenses'),
unit=m.Unit(m.DecimalNotation(""), m.StrictPrecision(0)),
color=m.Color.GREEN,
)

graph_veeam_o365jobs_transferred = g.Graph(
name='veeam_o365jobs_transferred',
title=g.Title('Veeam for Office 365 Job'),
minimal_range=g.MinimalRange(0, m.MaximumOf('veeam_o365jobs_transferred')),
compound_lines=['veeam_o365jobs_transferred'],
simple_lines=[
m.WarningOf('veeam_o365jobs_transferred'),
m.CriticalOf('veeam_o365jobs_transferred'),
]
)

graph_veeam_o365jobs_duration = g.Graph(
name='veeam_o365jobs_duration',
title=g.Title('Veeam for Office 365 Job'),
minimal_range=g.MinimalRange(0, m.MaximumOf('veeam_o365jobs_duration')),
compound_lines=['veeam_o365jobs_duration'],
simple_lines=[
m.WarningOf('veeam_o365jobs_duration'),
m.CriticalOf('veeam_o365jobs_duration'),
]
)

graph_veeam_o365jobs_items = g.Graph(
name='veeam_o365jobs_items',
title=g.Title('Veeam for Office 365 Job'),
minimal_range=g.MinimalRange(0, m.MaximumOf('veeam_o365jobs_items')),
compound_lines=['veeam_o365jobs_items'],
simple_lines=[
m.WarningOf('veeam_o365jobs_items'),
m.CriticalOf('veeam_o365jobs_items'),
]
)

graph_veeam_o365licenses_licenses = g.Graph(
name='veeam_o365licenses_licenses',
title=g.Title('Veeam for Office 365 licenses'),
minimal_range=g.MinimalRange(0, m.MaximumOf('veeam_o365licenses_licenses')),
compound_lines=['veeam_o365licenses_licenses'],
simple_lines=[
m.WarningOf('veeam_o365licenses_licenses'),
m.CriticalOf('veeam_o365licenses_licenses'),
m.MaximumOf('veeam_o365licenses_licenses', m.Color.BLACK)
]
)

perfometer_veeam_o365jobs = p.Stacked(
name='veeam_o365jobs',
upper=p.Perfometer(
name='veeam_o365jobs_transferred',
focus_range=p.FocusRange(p.Closed(0), p.Open(m.WarningOf('veeam_o365jobs_transferred'))),
segments=['veeam_o365jobs_transferred'],
),
lower=p.Perfometer(
name='veeam_o365jobs_duration',
focus_range=p.FocusRange(p.Closed(0), p.Open(m.WarningOf('veeam_o365jobs_duration'))),
segments=['veeam_o365jobs_duration'],
),
)

perfometer_veeam_o365licenses_licenses = p.Perfometer(
name='veeam_o365licenses_licenses',
focus_range=p.FocusRange(p.Closed(0), p.Open(m.MaximumOf('veeam_o365licenses_licenses'))),
segments=['veeam_o365licenses_licenses'],
)
30 changes: 15 additions & 15 deletions package
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
'description': u'Agent Plugin and Checks for Veeam for Office 365',
'download_url': 'https://github.com/jiuka/checkmk_veeam_o365/releases',
'files': {
'agent_based': ['veeam_o365jobs.py', 'veeam_o365licenses.py'],
'agents': [
'windows/plugins/veeam_o365_status.ps1',
'agents': ['windows/plugins/veeam_o365_status.ps1'],
'cmk_addons_plugins': [
'veeam_o365/agent_based/veeam_o365jobs.py',
'veeam_o365/agent_based/veeam_o365licenses.py',
'veeam_o365/checkman/veeam_o365jobs',
'veeam_o365/checkman/veeam_o365licenses',
'veeam_o365/graphing/veeam_o365.py',
'veeam_o365/rulesets/check_parameters.py',
'veeam_o365/rulesets/discovery_parameters.py',
'veeam_o365/rulesets/agent_config.py',
],
'checkman': ['veeam_o365jobs', 'veeam_o365licenses'],
'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.0',
'version.min_required': '2.2.0',
'version.packaged': '2.2.0',
'version.usable_until': '2.3.0'
'version': '2.7.0-0',
'version.min_required': '2.3.0p3',
'version.packaged': '2.3.0',
'version.usable_until': '2.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import pytest # type: ignore[import]
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
from cmk.agent_based.v2 import (
Metric,
Result,
Service,
State,
)
from cmk.base.plugins.agent_based import veeam_o365jobs
from cmk_addons.plugins.veeam_o365.agent_based import veeam_o365jobs


@pytest.mark.parametrize('params, section, result', [
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_discovery_veeam_o365jobs(params, section, result):
]
),
(
'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': (120, 300)},
'cmk.onmicrosoft.com Outlook Online', {'jobId': '12345678-9abc-def0-1234-56789abcdef0', 'duration': ('fixed', (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']
Expand Down
Loading

0 comments on commit 75e913f

Please sign in to comment.