From 2d1ae0323a6a0137db0188fd268d20ac4330ad08 Mon Sep 17 00:00:00 2001 From: Moritz Kiemer Date: Wed, 8 Nov 2023 23:28:30 +0100 Subject: [PATCH] db2_mem: make params a dict Change-Id: I8166f5f6416c5fa5df00363070e797f22ad249df --- cmk/base/legacy_checks/db2_mem.py | 9 ++---- .../plugins/wato/check_parameters/db2_mem.py | 32 +++++++++++-------- .../check_parameters/test_plugin_vs_wato.py | 1 - 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cmk/base/legacy_checks/db2_mem.py b/cmk/base/legacy_checks/db2_mem.py index 069c5ff73cc..7ef4b571f60 100644 --- a/cmk/base/legacy_checks/db2_mem.py +++ b/cmk/base/legacy_checks/db2_mem.py @@ -8,19 +8,15 @@ from cmk.base.config import check_info from cmk.base.plugins.agent_based.agent_based_api.v1 import IgnoreResultsError, render -db2_mem_default_levels = (10.0, 5.0) - def inventory_db2_mem(info): - return [(x[1], db2_mem_default_levels) for x in info if x[0] == "Instance"] + return [(x[1], {}) for x in info if x[0] == "Instance"] def check_db2_mem(item, params, info): # pylint: disable=too-many-branches if not info: raise IgnoreResultsError("Login into database failed") - warn, crit = params - in_block = False limit, usage = None, None for line in info: @@ -51,7 +47,7 @@ def check_db2_mem(item, params, info): # pylint: disable=too-many-branches yield check_levels( perc_free, None, - (None, None, warn, crit), + (None, None) + (params["levels_lower"] or (None, None)), human_readable_func=render.percent, infoname="Free", ) @@ -62,4 +58,5 @@ def check_db2_mem(item, params, info): # pylint: disable=too-many-branches discovery_function=inventory_db2_mem, check_function=check_db2_mem, check_ruleset_name="db2_mem", + check_default_parameters={"levels_lower": (10.0, 5.0)}, ) diff --git a/cmk/gui/plugins/wato/check_parameters/db2_mem.py b/cmk/gui/plugins/wato/check_parameters/db2_mem.py index 73b253ad4bf..4848a6c829c 100644 --- a/cmk/gui/plugins/wato/check_parameters/db2_mem.py +++ b/cmk/gui/plugins/wato/check_parameters/db2_mem.py @@ -9,23 +9,27 @@ rulespec_registry, RulespecGroupCheckParametersApplications, ) -from cmk.gui.valuespec import Percentage, TextInput, Tuple +from cmk.gui.plugins.wato.utils.simple_levels import SimpleLevels +from cmk.gui.valuespec import Dictionary, Migrate, Percentage, TextInput def _parameter_valuespec_db2_mem(): - return Tuple( - elements=[ - Percentage( - title=_("Warning if less than"), - # xgettext: no-python-format - unit=_("% memory left"), - ), - Percentage( - title=_("Critical if less than"), - # xgettext: no-python-format - unit=_("% memory left"), - ), - ], + return Migrate( + valuespec=Dictionary( + elements=[ + ( + "levels_lower", + SimpleLevels( + spec=Percentage, + # xgettext: no-python-format + unit=_("% memory left"), + direction="lower", + ), + ) + ], + optional_keys=[], + ), + migrate=lambda p: p if isinstance(p, dict) else {"levels_lower": p}, ) diff --git a/tests/unit/cmk/gui/plugins/wato/check_parameters/test_plugin_vs_wato.py b/tests/unit/cmk/gui/plugins/wato/check_parameters/test_plugin_vs_wato.py index 8fc205064a1..99bb806b517 100644 --- a/tests/unit/cmk/gui/plugins/wato/check_parameters/test_plugin_vs_wato.py +++ b/tests/unit/cmk/gui/plugins/wato/check_parameters/test_plugin_vs_wato.py @@ -459,7 +459,6 @@ class ErrorReporter: "couchbase_buckets_mem", RuleGroup.CheckgroupParameters("memory_multiitem"), ), - ("check", "db2_mem", RuleGroup.CheckgroupParameters("db2_mem")), ( "check", "ddn_s2a_stats_io",