Module: check_mk
Branch: master
Commit: c2a4de8d9341578b698a1fe64d2293bf3476850d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c2a4de8d934157…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Thu Jan 24 16:23:35 2019 +0100
Fix PS check grab user
The replacement of the usermane of a discovered process in the service
description was neglected. When later doing the replacements of the
match_groups the %u, because is a valid Python replace string, was left
expecting an unsigned int. If there were not match_groups the
replace_service_description would crash.
Change-Id: I5d5522c0cc2983674da34950ef84666360c2712d
---
checks/ps.include | 2 +-
tests/unit/checks/test_ps.py | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/checks/ps.include b/checks/ps.include
index 0aa208b..74e2a4c 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -137,7 +137,7 @@ def inventory_ps_common(invdata, invrules, parsed):
else:
match_groups = []
- i_servicedesc = replace_service_description(servicedesc, match_groups,
pattern)
+ i_servicedesc = replace_service_description(i_servicedesc, match_groups,
pattern)
# Problem here: We need to instantiate all subexpressions
# with their actual values of the found process.
diff --git a/tests/unit/checks/test_ps.py b/tests/unit/checks/test_ps.py
index 2bbd7a2..f7a1ad6 100644
--- a/tests/unit/checks/test_ps.py
+++ b/tests/unit/checks/test_ps.py
@@ -225,7 +225,7 @@ PS_DISCOVERY_WATO_RULES = [
"resident_levels": (1024**3, 2 * 1024**3),
"icon": "emacs.png",
},
- "descr": "emacs",
+ "descr": "emacs %u",
"match": "emacs",
"user": False
}, [], ["@all"], {
@@ -285,7 +285,7 @@ PS_DISCOVERY_SPECS = [
"process_info": "text",
'cpu_rescale_max': None,
}),
- ("emacs", "emacs", False, {
+ ("emacs %u", "emacs", False, {
"cpu_average": 15,
'cpu_rescale_max': True,
"process_info": "html",
@@ -400,7 +400,7 @@ def test_cleanup_params(check_manager, params, result):
PS_DISCOVERED_ITEMS = [
- ("emacs", {
+ ("emacs on", {
"cpu_average": 15,
'cpu_rescale_max': True,
"resident_levels_perc": (25.0, 50.0),
@@ -544,7 +544,7 @@ check_results = [
def test_check_ps_common(check_manager, monkeypatch, inv_item, reference):
check = check_manager.get_check("ps")
parsed = sum([check.run_parse(info)[1] for info in generate_inputs()], [])
- total_ram = 1024**3 if inv_item[0] == "emacs" else None
+ total_ram = 1024**3 if "emacs" in inv_item[0] else None
monkeypatch.setattr('time.time', lambda: 1540375342)
factory_defaults = {"levels": (1, 1, 99999, 99999)}
factory_defaults.update(inv_item[1])