From 0c526fa0247e6c65223595c58cd156b1c500c255 Mon Sep 17 00:00:00 2001 From: Moritz Kiemer Date: Tue, 7 Nov 2023 00:14:40 +0100 Subject: [PATCH] f5_pools: make params a dict Change-Id: I34c6963a5c0806e577feacd601f7da4f183d144d --- cmk/base/legacy_checks/f5_bigip_pool.py | 20 +++++++--------- .../plugins/wato/check_parameters/f5_pools.py | 24 +++++++++++++------ .../generictests/datasets/f5_bigip_pool.py | 16 ++++++------- .../check_parameters/test_plugin_vs_wato.py | 1 - 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/cmk/base/legacy_checks/f5_bigip_pool.py b/cmk/base/legacy_checks/f5_bigip_pool.py index 40d55179502..73a1b9f630f 100644 --- a/cmk/base/legacy_checks/f5_bigip_pool.py +++ b/cmk/base/legacy_checks/f5_bigip_pool.py @@ -19,9 +19,6 @@ # F5-BIGIP-LOCAL-MIB::ltmPoolMemberCnt. 8.80.111.111.108.95.78.77.65 = 2 # F5-BIGIP-LOCAL-MIB::ltmPoolActiveMemberCnt. 8.80.111.111.108.95.78.77.65 = 0 -# warn, crit numbers of pool members -f5_bigip_pool_default_levels = (2, 1) - def parse_f5_bigip_pool(string_table): parsed = {} @@ -54,7 +51,7 @@ def inventory_f5_bigip_pool(parsed): # inventorize all pools and their member count for item in parsed: if item != "": - yield item, f5_bigip_pool_default_levels + yield item, {} def f5_bigip_pool_get_down_members(down_info): @@ -70,8 +67,6 @@ def f5_bigip_pool_get_down_members(down_info): def check_f5_bigip_pool(item, params, parsed): - warn, crit = params - pool_info = parsed.get(item) if not pool_info: return None @@ -79,15 +74,17 @@ def check_f5_bigip_pool(item, params, parsed): pool_act_members = pool_info["act_members"] pool_def_members = pool_info["def_members"] message = "%d of %d members are up" % (pool_act_members, pool_def_members) + + levels = params["levels_lower"] state = 0 - if pool_act_members == pool_def_members or pool_act_members >= warn: + if pool_act_members == pool_def_members or not levels or pool_act_members >= levels[0]: state = 0 - elif pool_act_members < crit: + elif pool_act_members < levels[1]: state = 2 - message += f" (warn/crit: {warn}/{crit})" - elif pool_act_members < warn: + message += f" (warn/crit: {levels[0]}/{levels[1]})" + elif pool_act_members < levels[0]: state = 1 - message += f" (warn/crit: {warn}/{crit})" + message += f" (warn/crit: {levels[0]}/{levels[1]})" if pool_act_members < pool_def_members: downs = f5_bigip_pool_get_down_members(pool_info["down_info"]) @@ -113,4 +110,5 @@ def check_f5_bigip_pool(item, params, parsed): discovery_function=inventory_f5_bigip_pool, check_function=check_f5_bigip_pool, check_ruleset_name="f5_pools", + check_default_parameters={"levels_lower": (2, 1)}, ) diff --git a/cmk/gui/plugins/wato/check_parameters/f5_pools.py b/cmk/gui/plugins/wato/check_parameters/f5_pools.py index 8623ba864df..955d7391d69 100644 --- a/cmk/gui/plugins/wato/check_parameters/f5_pools.py +++ b/cmk/gui/plugins/wato/check_parameters/f5_pools.py @@ -9,16 +9,26 @@ rulespec_registry, RulespecGroupCheckParametersApplications, ) -from cmk.gui.valuespec import Integer, TextInput, Tuple +from cmk.gui.plugins.wato.utils.simple_levels import SimpleLevels +from cmk.gui.valuespec import Dictionary, Integer, Migrate, TextInput def _parameter_valuespec_f5_pools(): - return Tuple( - title=_("Minimum number of pool members"), - elements=[ - Integer(title=_("Warning if below"), unit=_("Members ")), - Integer(title=_("Critical if below"), unit=_("Members")), - ], + return Migrate( + valuespec=Dictionary( + elements=[ + ( + "levels_lower", + SimpleLevels( + spec=Integer, + title=_("Minimum number of pool members"), + unit=_("Members "), + ), + ), + ], + optional_keys=[], + ), + migrate=lambda p: p if isinstance(p, dict) else {"levels_lower": p}, ) diff --git a/tests/unit/checks/generictests/datasets/f5_bigip_pool.py b/tests/unit/checks/generictests/datasets/f5_bigip_pool.py index fc6e553ef57..fbc4c1a36e8 100644 --- a/tests/unit/checks/generictests/datasets/f5_bigip_pool.py +++ b/tests/unit/checks/generictests/datasets/f5_bigip_pool.py @@ -28,18 +28,18 @@ discovery = { "": [ - ("/Common/ad_hubservice-pool", (2, 1)), - ("/Common/ad_testch-pool", (2, 1)), - ("/Common/ldap_testch-pool", (2, 1)), - ("/Common/ldap_testhk-pool", (2, 1)), + ("/Common/ad_hubservice-pool", {}), + ("/Common/ad_testch-pool", {}), + ("/Common/ldap_testch-pool", {}), + ("/Common/ldap_testhk-pool", {}), ] } checks = { "": [ - ("/Common/ad_hubservice-pool", (2, 1), [(0, "2 of 2 members are up", [])]), - ("/Common/ad_testch-pool", (2, 1), [(0, "2 of 2 members are up", [])]), - ("/Common/ldap_testch-pool", (2, 1), [(0, "2 of 2 members are up", [])]), - ("/Common/ldap_testhk-pool", (2, 1), [(0, "2 of 2 members are up", [])]), + ("/Common/ad_hubservice-pool", {"levels_lower": (2, 1)}, [(0, "2 of 2 members are up", [])]), + ("/Common/ad_testch-pool", {"levels_lower": (2, 1)}, [(0, "2 of 2 members are up", [])]), + ("/Common/ldap_testch-pool", {"levels_lower": (2, 1)}, [(0, "2 of 2 members are up", [])]), + ("/Common/ldap_testhk-pool", {"levels_lower": (2, 1)}, [(0, "2 of 2 members are up", [])]), ] } 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 53a5cbed343..15c2d10930e 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 @@ -503,7 +503,6 @@ class ErrorReporter: RuleGroup.CheckgroupParameters("vm_heartbeat"), ), ("check", "f5_bigip_fans", RuleGroup.CheckgroupParameters("hw_fans")), - ("check", "f5_bigip_pool", RuleGroup.CheckgroupParameters("f5_pools")), ( "check", "fortigate_antivirus",