Skip to content

Commit

Permalink
Fix bug in display
Browse files Browse the repository at this point in the history
Previously, the plugin displayed:
```
aThe uptime did not change since the last check cycle for these node(s): , b
```

Change-Id: Ibfd4696d4152e86262ea653eb207273cee5fa040
  • Loading branch information
SoloJacobs committed Nov 20, 2024
1 parent af8d215 commit 1ec06b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmk/base/plugins/agent_based/if64.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _check_timestamps(
yield Result(
state=State.OK,
notice="The uptime did not change since the last check cycle for these node(s): "
", ".join(nodes_without_uptime_increase)
+ ", ".join(nodes_without_uptime_increase)
+ "\n"
"It is likely that no new data was collected.",
)
Expand All @@ -145,7 +145,7 @@ def _check_timestamps(
yield Result(
state=State.OK,
notice="The uptime has decreased since the last check cycle for these node(s): "
", ".join(nodes_without_uptime_increase)
+ ", ".join(nodes_without_uptime_increase)
+ "\n"
"The device might have rebooted or its uptime counter overflowed.",
)
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/cmk/plugins/collection/agent_based/test_if64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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.base.plugins.agent_based import if64
from cmk.base.plugins.agent_based.agent_based_api.v1 import Result, State


def test_check_timestamps_decrease() -> None:
value_store: dict[str, object] = {}
assert not list(if64._check_timestamps({"a": 1, "b": 2}, value_store)) # pylint: disable=protected-access
assert list(if64._check_timestamps({"a": 0, "b": 1}, value_store)) == [ # pylint: disable=protected-access
Result(
state=State.OK,
notice="The uptime has decreased since the last check cycle for these node(s): \nThe device might have rebooted or its uptime counter overflowed.",
)
]


def test_check_timestamps_no_change() -> None:
value_store: dict[str, object] = {}
assert not list(if64._check_timestamps({"a": 1, "b": 2}, value_store)) # pylint: disable=protected-access
assert list(if64._check_timestamps({"a": 1, "b": 2}, value_store)) == [ # pylint: disable=protected-access
Result(
state=State.OK,
notice="The uptime did not change since the last check cycle for these node(s): a, b\nIt is likely that no new data was collected.",
)
]


def test_check_timestamps_valid() -> None:
value_store: dict[str, object] = {}
assert not list(if64._check_timestamps({"a": 1, "b": 2}, value_store)) # pylint: disable=protected-access
assert not list(if64._check_timestamps({"a": 61, "b": 62}, value_store)) # pylint: disable=protected-access

0 comments on commit 1ec06b2

Please sign in to comment.