Module: check_mk
Branch: master
Commit: e6522087f042421d7d154b74fecd227ef5381fd6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e6522087f04242…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Thu Oct 18 09:57:18 2018 +0200
5847 FIX lnx_thermal: Fixed to only gather values of temp & type
The Linux agent collected too many values when hysteresis data was available and the check
crashed.
This has been fixed now by fixing the required values.
Jira: CMK-1121
Change-Id: I276cb7657db571b5532acddf583768bcc5c148fe
---
.werks/5847 | 11 +++++++
agents/check_mk_agent.linux | 13 ++++----
tests/unit/checks/test_lnx_thermal.py | 56 +++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/.werks/5847 b/.werks/5847
new file mode 100644
index 0000000..0eb9a4d
--- /dev/null
+++ b/.werks/5847
@@ -0,0 +1,11 @@
+Title: lnx_thermal: Fixed to only gather values of temp & type
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0p6
+Date: 1539338001
+Class: fix
+
+The Linux agent collected too many values when hysteresis data was available and the
check crashed.
+This has been fixed now by fixing the required values.
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index a90057d..13ee884 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -997,12 +997,15 @@ fi
# Gather thermal information provided e.g. by acpi
# At the moment only supporting thermal sensors
if [ -z "$MK_IN_CONTAINER" ] && ls /sys/class/thermal/thermal_zone*
>/dev/null 2>&1; then
- echo '<<<lnx_thermal>>>'
+ echo '<<<lnx_thermal:sep(124)>>>'
for F in /sys/class/thermal/thermal_zone*; do
- echo -n "${F##*/} "
- if [ ! -e "$F/mode" ] ; then echo -n "- " ; fi
- cat "$F"/{mode,type,temp,trip_point_*} | tr \\n " "
- echo
+ line="${F##*/}"
+ if [ ! -e "$F/mode" ] ; then line="${line}|-" ; else
line="${line}|$(cat "$F"/mode)"; fi
+ line="${line}|$(cat "$F"/{type,temp} | tr \\n
"|")"
+ for G in $(ls "$F"/trip_point_*_{temp,type}); do
+ line="${line}$(< "$G" tr \\n "|")"
+ done
+ echo "${line%?}"
done
fi
diff --git a/tests/unit/checks/test_lnx_thermal.py
b/tests/unit/checks/test_lnx_thermal.py
new file mode 100644
index 0000000..49497d4
--- /dev/null
+++ b/tests/unit/checks/test_lnx_thermal.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+import pytest
+
+# Mark all tests in this file as check related tests
+pytestmark = pytest.mark.checks
+
+
+def splitter(text, split_symbol=None):
+ return [line.split(split_symbol) for line in text.split("\n")]
+
+agent_info = [
+ splitter("""thermal_zone0 enabled acpitz 57000 127000 critical
+thermal_zone1 enabled acpitz 65000 100000 critical 95500 passive
+thermal_zone3 - pch_skylake 46000 115000 critical
+thermal_zone5 pkg-temp-0 44000 0 passive 0 passive"""),
+ splitter(
+ """thermal_zone0|enabled|acpitz|25000|107000|critical
+thermal_zone3|-|pch_skylake|45000|115000|critical
+thermal_zone4|-|INT3400 Thermal|20000
+thermal_zone5|-|x86_pkg_temp|48000|0|passive|0|passive
+thermal_zone6|-|B0D4|61000|127000|critical|127000|hot|99000|passive|99000|active|94000|active""",
+ '|')
+]
+result_discovery = [[('Zone %s' % i, {}) for i in [0, 1, 3, 5]],
+ [('Zone %s' % i, {}) for i in [0, 3, 4, 5, 6]]]
+
+
+(a)pytest.mark.parametrize("info;info, result", zip(agent_info, result_discovery))
+def test_parse(check_manager, info, result):
+ check = check_manager.get_check("lnx_thermal")
+ assert list(check.run_discovery(info)) == result
+
+
+result_check = [
+ [
+ (0, '57.0 °C', [('temp', 57.0, 127.0, 127.0)]),
+ (0, '65.0 °C', [('temp', 65.0, 95.5, 100.0)]),
+ (0, '46.0 °C', [('temp', 46.0, 115.0, 115.0)]),
+ (0, '44.0 °C', [('temp', 44.0, None, None)]),
+ ],
+ [
+ (0, '25.0 °C', [('temp', 25.0, 107.0, 107.0)]),
+ (0, '45.0 °C', [('temp', 45.0, 115.0, 115.0)]),
+ (0, '20.0 °C', [('temp', 20.0, None, None)]),
+ (0, '48.0 °C', [('temp', 48.0, None, None)]),
+ (0, '61.0 °C', [('temp', 61.0, 99.0, 127.0)]),
+ ],
+]
+
+(a)pytest.mark.parametrize("info;info, discovered, checked", zip(agent_info,
result_discovery,
+ result_check))
+def test_parse(check_manager, info, discovered, checked):
+ check = check_manager.get_check("lnx_thermal")
+ for (item, params), result in zip(discovered, checked):
+ assert check.run_check(item, params, info) == result