Skip to content

Commit 7f1e10e

Browse files
committed
Cisco ESA: Implement memory service
CMK-20862 Change-Id: I9d22e9ad37497dfc5c5c223c4e1aa7133fb7dd03
1 parent 339ed89 commit 7f1e10e

File tree

16 files changed

+228
-159
lines changed

16 files changed

+228
-159
lines changed

cmk/base/legacy_checks/tplink_mem.py

-59
This file was deleted.

cmk/gui/plugins/wato/check_parameters/memory_percentage_used.py

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2025 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
from cmk.agent_based.v2 import (
7+
SimpleSNMPSection,
8+
SNMPTree,
9+
StringTable,
10+
)
11+
from cmk.plugins.cisco_sma.agent_based.detect import DETECT_CISCO_SMA_SNMP
12+
13+
14+
def _parse_memory_percentage_used(string_table: StringTable) -> float | None:
15+
if not string_table or not string_table[0]:
16+
return None
17+
18+
return float(string_table[0][0])
19+
20+
21+
snmp_section_memory_utilization = SimpleSNMPSection(
22+
parsed_section_name="memory_utilization",
23+
name="cisco_sma_memory_utilization",
24+
detect=DETECT_CISCO_SMA_SNMP,
25+
fetch=SNMPTree(
26+
base=".1.3.6.1.4.1.15497.1.1.1",
27+
oids=["1.0"],
28+
),
29+
parse_function=_parse_memory_percentage_used,
30+
supersedes=["hr_mem"],
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2025 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
from typing import TypedDict
6+
7+
from cmk.agent_based.v2 import (
8+
check_levels,
9+
CheckPlugin,
10+
CheckResult,
11+
DiscoveryResult,
12+
render,
13+
Service,
14+
)
15+
from cmk.rulesets.v1.form_specs import SimpleLevelsConfigModel
16+
17+
18+
class Params(TypedDict):
19+
levels: SimpleLevelsConfigModel[float]
20+
21+
22+
def _check_memory_utilization(params: Params, section: float) -> CheckResult:
23+
yield from check_levels(
24+
section,
25+
label="Utilization",
26+
metric_name="mem_used_percent",
27+
render_func=render.percent,
28+
levels_upper=params["levels"],
29+
)
30+
31+
32+
def _discover_memory_utilization(section: float) -> DiscoveryResult:
33+
yield Service()
34+
35+
36+
check_plugin_memory_utilization = CheckPlugin(
37+
name="memory_utilization",
38+
service_name="Memory",
39+
discovery_function=_discover_memory_utilization,
40+
check_function=_check_memory_utilization,
41+
check_ruleset_name="memory_percentage_used",
42+
check_default_parameters=Params(levels=("fixed", (70.0, 80.0))),
43+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: Memory utilization
2+
agents: snmp
3+
catalog: os/storage
4+
license: GPLv2
5+
distribution: check_mk
6+
description:
7+
This check monitors the memory utilization.
8+
9+
Warning and critical levels are configurable.
10+
discovery:
11+
One service is created.

cmk/plugins/collection/checkman/tplink_mem

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2025 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
from cmk.rulesets.v1 import Title
7+
from cmk.rulesets.v1.form_specs import (
8+
DefaultValue,
9+
DictElement,
10+
Dictionary,
11+
InputHint,
12+
LevelDirection,
13+
LevelsType,
14+
migrate_to_float_simple_levels,
15+
Percentage,
16+
SimpleLevels,
17+
SimpleLevelsConfigModel,
18+
)
19+
from cmk.rulesets.v1.rule_specs import CheckParameters, HostCondition, Topic
20+
21+
22+
def _parameter_form_memory_utilization() -> Dictionary:
23+
return Dictionary(
24+
elements={
25+
"levels": DictElement[SimpleLevelsConfigModel[float]](
26+
required=True,
27+
parameter_form=SimpleLevels(
28+
title=Title("Upper thresholds"),
29+
level_direction=LevelDirection.UPPER,
30+
form_spec_template=Percentage(),
31+
prefill_levels_type=DefaultValue(LevelsType.FIXED),
32+
prefill_fixed_levels=InputHint((70.0, 80.0)),
33+
migrate=migrate_to_float_simple_levels,
34+
),
35+
),
36+
}
37+
)
38+
39+
40+
rule_spec_memory_utilization_percentage = CheckParameters(
41+
name="memory_percentage_used",
42+
topic=Topic.OPERATING_SYSTEM,
43+
parameter_form=_parameter_form_memory_utilization,
44+
title=Title("Memory utilization"),
45+
condition=HostCondition(),
46+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
7+
from cmk.agent_based.v2 import (
8+
SimpleSNMPSection,
9+
SNMPTree,
10+
StringTable,
11+
)
12+
from cmk.plugins.lib.tplink import DETECT_TPLINK
13+
14+
15+
def _parse_memory_percentage_used(string_table: StringTable) -> float | None:
16+
if not string_table or not string_table[0]:
17+
return None
18+
19+
utilization_of_units = [float(line[0]) for line in string_table]
20+
return sum(utilization_of_units) / len(utilization_of_units)
21+
22+
23+
snmp_section_memory_utilization = SimpleSNMPSection(
24+
parsed_section_name="memory_utilization",
25+
name="tplink_memory_utilization",
26+
detect=DETECT_TPLINK,
27+
fetch=SNMPTree(
28+
base=".1.3.6.1.4.1.11863.6.4.1.2.1.1",
29+
oids=["2"],
30+
),
31+
parse_function=_parse_memory_percentage_used,
32+
)

cmk/update_config/plugins/lib/replaced_check_plugins.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from cmk.checkengine.checking import CheckPluginName
99

1010
# Please keep this functionality even if we currently don't have any replaced check plugins!
11-
_REPLACED_CHECK_PLUGINS: dict[CheckPluginName, CheckPluginName] = {}
11+
_REPLACED_CHECK_PLUGINS: dict[CheckPluginName, CheckPluginName] = {
12+
CheckPluginName("tplink_mem"): CheckPluginName("memory_utilization")
13+
}
1214

1315
ALL_REPLACED_CHECK_PLUGINS: Mapping[CheckPluginName, CheckPluginName] = {
1416
**_REPLACED_CHECK_PLUGINS,

tests/unit/checks/generictests/datasets/tplink_mem_1.py

-15
This file was deleted.

tests/unit/checks/generictests/datasets/tplink_mem_2.py

-29
This file was deleted.

tests/unit/checks/test_generic_legacy_conversion.py

-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ def test_no_new_or_vanished_legacy_checks(fix_plugin_legacy: FixPluginLegacy) ->
11031103
"tinkerforge_humidity",
11041104
"tinkerforge_motion",
11051105
"tplink_cpu",
1106-
"tplink_mem",
11071106
"tplink_poe_summary",
11081107
"tsm_drives",
11091108
"tsm_paths",

tests/unit/cmk/gui/openapi/test_openapi_rules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def test_openapi_create_rule_regression(clients: ClientRegistry) -> None:
149149

150150

151151
def test_openapi_value_raw_is_unaltered(clients: ClientRegistry) -> None:
152-
value_raw = "{'levels': (10.0, 5.0)}"
152+
value_raw = "{'levels': ('fixed', (10.0, 5.0))}"
153153
resp = clients.Rule.create(
154154
ruleset=RuleGroup.CheckgroupParameters("memory_percentage_used"),
155155
value_raw=value_raw,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
7+
import pytest
8+
9+
from cmk.agent_based.v2 import StringTable
10+
from cmk.plugins.cisco_sma.agent_based.memory_utilization import _parse_memory_percentage_used
11+
12+
13+
@pytest.mark.parametrize(
14+
"string_table, expected",
15+
(
16+
([[]], None),
17+
([["2"]], 2.0),
18+
),
19+
)
20+
def test_parse_memory_percentage_used(string_table: StringTable, expected: None | float) -> None:
21+
assert _parse_memory_percentage_used(string_table) == expected

0 commit comments

Comments
 (0)