Skip to content

Commit

Permalink
f5_pools: make params a dict
Browse files Browse the repository at this point in the history
Change-Id: I34c6963a5c0806e577feacd601f7da4f183d144d
  • Loading branch information
mo-ki committed Nov 17, 2023
1 parent 1afdcfb commit 0c526fa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
20 changes: 9 additions & 11 deletions cmk/base/legacy_checks/f5_bigip_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
Expand All @@ -70,24 +67,24 @@ 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

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"])
Expand All @@ -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)},
)
24 changes: 17 additions & 7 deletions cmk/gui/plugins/wato/check_parameters/f5_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)


Expand Down
16 changes: 8 additions & 8 deletions tests/unit/checks/generictests/datasets/f5_bigip_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])]),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0c526fa

Please sign in to comment.