Skip to content

Commit

Permalink
db2_mem: make params a dict
Browse files Browse the repository at this point in the history
Change-Id: I8166f5f6416c5fa5df00363070e797f22ad249df
  • Loading branch information
mo-ki committed Nov 22, 2023
1 parent befdf2c commit 2d1ae03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
9 changes: 3 additions & 6 deletions cmk/base/legacy_checks/db2_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
)
Expand All @@ -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)},
)
32 changes: 18 additions & 14 deletions cmk/gui/plugins/wato/check_parameters/db2_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2d1ae03

Please sign in to comment.