-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved check from base/legacy_checks to plugins/winperf * Removed `winperf_ts_sessions` from `expected_legacy_checks` * Moved manpage to comply with directory structure * Fixed typo in manpage CMK-21341 Change-Id: If5e391565cc5ae69dcf9470ecab2d31ebe9914c1
- Loading branch information
1 parent
50fcad8
commit 8bb0c64
Showing
6 changed files
with
188 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/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. | ||
|
||
# Example output from agent: | ||
# <<<winperf_ts_sessions>>> | ||
# 1385714515.93 2102 | ||
# 2 20 rawcount | ||
# 4 18 rawcount | ||
# 6 2 rawcount | ||
|
||
# Counters, relative to the base ID (e.g. 2102) | ||
# 2 Total number of Terminal Services sessions. | ||
# 4 Number of active Terminal Services sessions. | ||
# 6 Number of inactive Terminal Services sessions. | ||
from collections.abc import Mapping | ||
from typing import Any | ||
|
||
from cmk.agent_based.v2 import ( | ||
AgentSection, | ||
check_levels, | ||
CheckPlugin, | ||
CheckResult, | ||
DiscoveryResult, | ||
Result, | ||
Service, | ||
State, | ||
StringTable, | ||
) | ||
|
||
|
||
def discovery_winperf_ts_sessions( | ||
section: StringTable, | ||
) -> DiscoveryResult: | ||
if len(section) > 1: | ||
yield Service() | ||
|
||
|
||
def check_winperf_ts_sessions(params: Mapping[str, Any], section: StringTable) -> CheckResult: | ||
if not section or len(section) == 1: | ||
yield Result(state=State.UNKNOWN, summary="Performance counters not available") | ||
total, active, inactive = (int(l[1]) for l in section[1:4]) | ||
|
||
# Tom Moore said, that the order of the columns has recently changed | ||
# in newer Windows versions (hooray!) and is now active, inactive, total. | ||
# We try to accommodate for that. | ||
if active + inactive != total: | ||
active, inactive, total = total, active, inactive | ||
|
||
limit_active = params.get("active", None) | ||
limit_inactive = params.get("inactive", None) | ||
|
||
yield from check_levels( | ||
value=active, | ||
metric_name="active", | ||
levels_upper=("fixed", limit_active) if limit_active else ("no_levels", limit_active), | ||
render_func=lambda x: f"{x} Active", | ||
) | ||
yield from check_levels( | ||
value=inactive, | ||
metric_name="inactive", | ||
levels_upper=("fixed", limit_inactive) if limit_inactive else ("no_levels", limit_inactive), | ||
render_func=lambda x: f"{x} Inactive", | ||
) | ||
|
||
|
||
def parse_winperf_ts_sessions(string_table: StringTable) -> StringTable: | ||
return string_table | ||
|
||
|
||
agent_section_winperf_ts_sessions = AgentSection( | ||
name="winperf_ts_sessions", parse_function=parse_winperf_ts_sessions | ||
) | ||
check_plugin_winperf_ts_sessions = CheckPlugin( | ||
name="winperf_ts_sessions", | ||
service_name="Sessions", | ||
discovery_function=discovery_winperf_ts_sessions, | ||
check_function=check_winperf_ts_sessions, | ||
check_ruleset_name="winperf_ts_sessions", | ||
check_default_parameters={}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
tests/unit/cmk/base/legacy_checks/test_winperf_ts_sessions.py
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
tests/unit/cmk/plugins/winperf/agent_based/test_winperf_ts_sessions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2025 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 collections.abc import Mapping | ||
from typing import Any | ||
|
||
from pytest import mark, param | ||
|
||
from cmk.agent_based.v2 import ( | ||
CheckResult, | ||
DiscoveryResult, | ||
Metric, | ||
Result, | ||
Service, | ||
State, | ||
StringTable, | ||
) | ||
from cmk.plugins.winperf.agent_based.winperf_ts_sessions import ( | ||
check_winperf_ts_sessions, | ||
discovery_winperf_ts_sessions, | ||
) | ||
|
||
# Note: The order of columns was changed in Windows. For more details, see comment in plugin code. | ||
_SECTION = [[1385714515.93, 2102], [2, 20, "rawcount"], [4, 18, "rawcount"], [6, 2, "rawcount"]] | ||
_NEW_SECTION = [[1385714515.93, 2102], [4, 18, "rawcount"], [6, 2, "rawcount"], [2, 20, "rawcount"]] | ||
|
||
METRIC_ACTIVE_OK = Metric(name="active", value=18) | ||
METRIC_ACTIVE_WARN = Metric(name="active", value=18, levels=(10.0, 20.0)) | ||
METRIC_INACTIVE_OK = Metric(name="inactive", value=2) | ||
METRIC_INACTIVE_WARN = Metric(name="inactive", value=2, levels=(1.0, 20.0)) | ||
|
||
RESULT_ACTIVE_OK = Result(state=State.OK, summary="18 Active") | ||
RESULT_ACTIVE_WARN = Result( | ||
state=State.WARN, summary="18 Active (warn/crit at 10 Active/20 Active)" | ||
) | ||
RESULT_INACTIVE_OK = Result(state=State.OK, summary="2 Inactive") | ||
RESULT_INACTIVE_WARN = Result( | ||
state=State.WARN, summary="2 Inactive (warn/crit at 1 Inactive/20 Inactive)" | ||
) | ||
_PERFDATA = [Metric("active", 18), Metric("inactive", 2)] | ||
|
||
|
||
@mark.parametrize("section, expected", [[_SECTION, [Service()]], [[], []]]) | ||
def test_discovery_winperf_ts_sessions(section: StringTable, expected: DiscoveryResult) -> None: | ||
assert list(discovery_winperf_ts_sessions(section)) == expected | ||
|
||
|
||
@mark.parametrize( | ||
"section,params,expected", | ||
[ | ||
param( | ||
_SECTION, | ||
{}, | ||
[RESULT_ACTIVE_OK, METRIC_ACTIVE_OK, RESULT_INACTIVE_OK, METRIC_INACTIVE_OK], | ||
id="all ok (old column order)", | ||
), | ||
param( | ||
_SECTION, | ||
{"active": (10, 20)}, | ||
[RESULT_ACTIVE_WARN, METRIC_ACTIVE_WARN, RESULT_INACTIVE_OK, METRIC_INACTIVE_OK], | ||
id="number of active sessions exceeds warn threshold (old column order)", | ||
), | ||
param( | ||
_SECTION, | ||
{"inactive": (1, 20)}, | ||
[RESULT_ACTIVE_OK, METRIC_ACTIVE_OK, RESULT_INACTIVE_WARN, METRIC_INACTIVE_WARN], | ||
id="number of inactive sessions exceeds warn threshold (old column order)", | ||
), | ||
param( | ||
_SECTION, | ||
{"active": (10, 20), "inactive": (1, 20)}, | ||
[RESULT_ACTIVE_WARN, METRIC_ACTIVE_WARN, RESULT_INACTIVE_WARN, METRIC_INACTIVE_WARN], | ||
id="both warn thresholds exceeded (old column order)", | ||
), | ||
param( | ||
_NEW_SECTION, | ||
{}, | ||
[RESULT_ACTIVE_OK, METRIC_ACTIVE_OK, RESULT_INACTIVE_OK, METRIC_INACTIVE_OK], | ||
id="all ok (new column order)", | ||
), | ||
param( | ||
_NEW_SECTION, | ||
{"active": (10, 20)}, | ||
[RESULT_ACTIVE_WARN, METRIC_ACTIVE_WARN, RESULT_INACTIVE_OK, METRIC_INACTIVE_OK], | ||
id="number of active sessions exceeds warn threshold (new column order)", | ||
), | ||
param( | ||
_NEW_SECTION, | ||
{"inactive": (1, 20)}, | ||
[RESULT_ACTIVE_OK, METRIC_ACTIVE_OK, RESULT_INACTIVE_WARN, METRIC_INACTIVE_WARN], | ||
id="number of inactive sessions exceeds warn threshold (new column order)", | ||
), | ||
param( | ||
_NEW_SECTION, | ||
{"active": (10, 20), "inactive": (1, 20)}, | ||
[RESULT_ACTIVE_WARN, METRIC_ACTIVE_WARN, RESULT_INACTIVE_WARN, METRIC_INACTIVE_WARN], | ||
id="both warn thresholds exceeded (new column order)", | ||
), | ||
], | ||
) | ||
def test_check_winperf_ts_sessions( | ||
section: StringTable, params: Mapping[str, Any], expected: CheckResult | ||
) -> None: | ||
assert list(check_winperf_ts_sessions(params, section)) == expected |