Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cmk/gui/plugins/wato/check_parameters/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RulespecGroupCheckParametersApplications,
RulespecGroupEnforcedServicesApplications,
)
from cmk.gui.valuespec import Dictionary, DropdownChoice, TextInput
from cmk.gui.valuespec import Dictionary, DropdownChoice, FixedValue, TextInput

rulespec_registry.register(
ManualCheckParameterRulespec(
Expand Down Expand Up @@ -55,6 +55,21 @@ def _parameter_valuespec_local() -> Dictionary:
)


def _parameter_valuespec_show_cache_info_local() -> Dictionary:
return Dictionary(
elements=[
(
"hide_cache_info_from_summary",
FixedValue(
True,
title=_("Hide caching information from service summary"),
totext="",
),
),
]
)


rulespec_registry.register(
CheckParameterRulespecWithItem(
check_group_name="local",
Expand All @@ -66,3 +81,14 @@ def _parameter_valuespec_local() -> Dictionary:
is_deprecated=True,
)
)

rulespec_registry.register(
CheckParameterRulespecWithItem(
check_group_name="hide_cache_info_local",
group=RulespecGroupCheckParametersApplications,
item_spec=lambda: TextInput(title=_("Name of local item")),
match_type="dict",
parameter_valuespec=_parameter_valuespec_show_cache_info_local,
title=lambda: _("Local checks: Hide cache information"),
)
)
39 changes: 39 additions & 0 deletions cmk/gui/plugins/wato/check_parameters/mrpe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.gui.i18n import _
from cmk.gui.plugins.wato.utils import (
CheckParameterRulespecWithItem,
rulespec_registry,
RulespecGroupCheckParametersApplications,
)
from cmk.gui.valuespec import Dictionary, FixedValue, TextInput


def _parameter_valuespec_hide_cache_info_mrpe() -> Dictionary:
return Dictionary(
elements=[
(
"hide_cache_info_from_summary",
FixedValue(
True,
title=_("Hide caching information from service summary"),
totext="",
),
),
]
)


rulespec_registry.register(
CheckParameterRulespecWithItem(
check_group_name="hide_cache_info_mrpe",
group=RulespecGroupCheckParametersApplications,
item_spec=lambda: TextInput(title=_("Name of MRPE check")),
match_type="dict",
parameter_valuespec=_parameter_valuespec_hide_cache_info_mrpe,
title=lambda: _("MRPE checks: Hide cache information"),
)
)
11 changes: 9 additions & 2 deletions cmk/plugins/checkmk/agent_based/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ def check_local(item: str, params: Mapping[str, Any], section: LocalSection) ->
except ValueError:
summary, details = local_result.text, ""

hide = params.get("hide_cache_info_from_summary", False)

if local_result.cache_info is not None and hide:
summary = f"{summary} ◷" if summary else "◷"

if local_result.text:
yield Result(
state=local_result.state,
Expand All @@ -448,7 +453,9 @@ def check_local(item: str, params: Mapping[str, Any], section: LocalSection) ->
)
yield from _local_make_metrics(local_result)

if local_result.cache_info is not None:
if local_result.cache_info is not None and hide:
yield Result(state=State.OK, notice=render_cache_info(local_result.cache_info))
elif local_result.cache_info is not None and not hide:
yield Result(state=State.OK, summary=render_cache_info(local_result.cache_info))


Expand All @@ -457,6 +464,6 @@ def check_local(item: str, params: Mapping[str, Any], section: LocalSection) ->
service_name="%s",
discovery_function=discover_local,
check_default_parameters={},
check_ruleset_name="local",
check_ruleset_name="hide_cache_info_local",
check_function=check_local,
)
22 changes: 18 additions & 4 deletions cmk/plugins/checkmk/agent_based/mrpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import urllib.parse
from collections.abc import Mapping, Sequence
from typing import NamedTuple
from typing import NamedTuple, TypedDict

from cmk.agent_based.v2 import (
AgentSection,
Expand All @@ -32,6 +32,10 @@ class PluginData(NamedTuple):
MRPESection = Mapping[str, PluginData]


class MRPEParams(TypedDict, total=False):
hide_cache_info_from_summary: bool


def parse_mrpe(string_table: StringTable) -> MRPESection:
parsed = {}
for line in string_table:
Expand Down Expand Up @@ -143,7 +147,7 @@ def _parse_nagios_perfstring(perfinfo: str) -> Metric:
)


def check_mrpe(item: str, section: MRPESection) -> CheckResult:
def check_mrpe(item: str, params: MRPEParams, section: MRPESection) -> CheckResult:
dataset = section.get(item)
if dataset is None:
return
Expand All @@ -165,15 +169,23 @@ def check_mrpe(item: str, section: MRPESection) -> CheckResult:
perfdata += parts[1].strip().split()
now_comes_perfdata = True

hide = params.get("hide_cache_info_from_summary", False)

summary = output[0] if output[0] else "No further information available"
if dataset.cache_info is not None and hide:
summary = f"{summary} ◷"

yield Result(
state=dataset.state,
summary=output[0] if output[0] else "No further information available",
summary=summary,
details="\n".join(output) if output[0] else None,
)
yield from _output_metrics(perfdata)

# This is at the end of the summary, to be consistent with local checks.
if dataset.cache_info is not None:
if dataset.cache_info is not None and hide:
yield Result(state=State.OK, notice=cache_helper.render_cache_info(dataset.cache_info))
elif dataset.cache_info is not None and not hide:
yield Result(state=State.OK, summary=cache_helper.render_cache_info(dataset.cache_info))

# name of check command needed for PNP to choose the correct template
Expand All @@ -185,5 +197,7 @@ def check_mrpe(item: str, section: MRPESection) -> CheckResult:
name="mrpe",
discovery_function=discover_mrpe,
check_function=check_mrpe,
check_default_parameters={},
check_ruleset_name="hide_cache_info_mrpe",
service_name="%s",
)
10 changes: 5 additions & 5 deletions tests/unit/cmk/plugins/checkmk/agent_based/test_mrpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ def test_discovery() -> None:


def test_check_mrpe() -> None:
assert list(check_mrpe("Bar_Extender", SECTION)) == [
assert list(check_mrpe("Bar_Extender", {}, SECTION)) == [
Result(
state=State.WARN,
summary="Bar extender overload 6.012",
),
Metric("bar_load", 6.012),
]

assert list(check_mrpe("Foo_Application", SECTION)) == [
assert list(check_mrpe("Foo_Application", {}, SECTION)) == [
Result(
state=State.OK,
summary="Foo server up and running",
),
]

assert list(check_mrpe("Mutliliner", SECTION)) == [
assert list(check_mrpe("Mutliliner", {}, SECTION)) == [
Result(
state=State.UNKNOWN,
summary="Invalid plug-in status '§$%'. Output is: Output1",
Expand All @@ -124,7 +124,7 @@ def test_check_mrpe() -> None:


def test_check_invalid_metric() -> None:
assert list(check_mrpe("Invalid_Metric", SECTION)) == [
assert list(check_mrpe("Invalid_Metric", {}, SECTION)) == [
Result(
state=State.OK,
summary="I would be ok, if it wasn't for the metric",
Expand All @@ -146,7 +146,7 @@ def test_check_metric_name_with_invalid_character() -> None:
cache_info=None,
)
}
assert list(check_mrpe("Disk", section)) == [
assert list(check_mrpe("Disk", {}, section)) == [
Result(
state=State.OK,
summary="DISK OK - free space: / 12483 MB",
Expand Down
Loading