Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / lnx_thermal
blobf165b6806d9d29fbe2b65bd63b211bad044fcd83
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<lnx_thermal>>>
28 # thermal_zone0 enabled acpitz 57000 127000 critical
29 # thermal_zone1 enabled acpitz 65000 100000 critical 95500 passive
31 # <<<lnx_thermal>>>
32 # thermal_zone0 enabled acpitz 47000 90000 critical 79000 passive
34 # <<<lnx_thermal>>>
35 # thermal_zone0 enabled acpitz 38000 98000 critical
36 # thermal_zone1 pkg-temp-0 44000 0 passive 0 passive
38 factory_settings["lnx_thermal_default_levels"] = {
39 "levels": (70.0, 80.0),
40 "device_levels_handling": "devdefault",
44 def parse_lnx_thermal(info):
45 """
46 Supported format:
47 - Temperature is either the 3rd or 4th element in an info row.
48 - After temperature follows pairwise trip point temperature and trip point type.
49 - Considered trip points are critical, passive, hot.
50 - A known, not considered trip point is active.
51 - In case trip point values are 0 or negative (known default values) they are ignored.
52 """
53 if not info:
54 return {}
55 parsed = {}
56 for line in info:
57 zone_identifier = 0
58 temperature_3rd_element_idx = 2
59 temperature_4th_element_idx = 3
60 temperature_factor = 1000.0
61 zone_raw = line[zone_identifier]
62 try:
63 int(line[temperature_3rd_element_idx]) # may raise an exception
64 temperature = int(line[temperature_3rd_element_idx]) / temperature_factor
65 trip_points = dict(zip(line[4::2], [int(x) / temperature_factor for x in line[3::2]]))
66 except ValueError:
67 temperature = int(line[temperature_4th_element_idx]) / temperature_factor
68 trip_points = dict(zip(line[5::2], [int(x) / temperature_factor for x in line[4::2]]))
69 zone_formatted = zone_raw.replace('thermal_zone', 'Zone ')
70 parsed[zone_formatted] = {}
71 temperature_and_trip_points = ('temperature', 'passive', 'critical', 'hot')
72 for key in temperature_and_trip_points:
73 parsed[zone_formatted].setdefault(key, None)
74 parsed[zone_formatted]['temperature'] = temperature
75 for tp_name, tp_value in trip_points.items():
76 if tp_name in trip_points and tp_value > 0:
77 parsed[zone_formatted][tp_name] = tp_value
78 else:
79 # ignore trip point types not supported yet
80 pass
81 return parsed
84 def inventory_lnx_thermal(parsed):
85 for item in parsed.keys():
86 yield item, {}
89 def check_lnx_thermal(item, params, parsed):
90 """
91 - Trip points hot and critical are considered for the device crit level. In case both trip
92 points are given the lower value is considered for the device crit level.
93 - Trip point passive is considered for the device warn level.
94 - In case both hot and critical trip points are given the lower trip point value
95 is considered for the device crit level.
96 - Trip point temperatures are provided via performance data.
97 """
98 temperature = parsed.get(item).get('temperature')
99 warn_level = parsed.get(item).get('passive')
100 hot_value = parsed.get(item).get('hot')
101 critical_value = parsed.get(item).get('critical')
103 if not temperature:
104 return 3, "Item not found or invalid agent data."
106 if hot_value and critical_value:
107 crit_level = min(hot_value, critical_value)
108 else:
109 crit_level = hot_value or critical_value
111 if not crit_level or not warn_level:
112 crit_level = crit_level or warn_level
113 warn_level = warn_level or crit_level
115 if warn_level and crit_level:
116 levels = (warn_level, crit_level)
117 else:
118 levels = None
120 return check_temperature(temperature, params, "lnx_thermal_%s" % item, dev_levels=levels)
123 check_info['lnx_thermal'] = {
124 "parse_function": parse_lnx_thermal,
125 "inventory_function": inventory_lnx_thermal,
126 "check_function": check_lnx_thermal,
127 "service_description": "Temperature %s",
128 "has_perfdata": True,
129 "group": "temperature",
130 "default_levels_variable": "lnx_thermal_default_levels",
131 "includes": ["temperature.include"],