Cleanup config.nodes_of
[check_mk.git] / checks / lnx_thermal
blobf01808d24ae187c50fe3d1dc4daffa69e02aa815
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 @get_parsed_item_data
90 def check_lnx_thermal(item, params, data):
91 """
92 - Trip points hot and critical are considered for the device crit level. In case both trip
93 points are given the lower value is considered for the device crit level.
94 - Trip point passive is considered for the device warn level.
95 - In case both hot and critical trip points are given the lower trip point value
96 is considered for the device crit level.
97 - Trip point temperatures are provided via performance data.
98 """
99 temperature = data.get('temperature')
100 warn_level = data.get('passive')
101 hot_value = data.get('hot')
102 critical_value = data.get('critical')
104 if temperature is None:
105 return
107 if hot_value and critical_value:
108 crit_level = min(hot_value, critical_value)
109 else:
110 crit_level = hot_value or critical_value
112 if not crit_level or not warn_level:
113 crit_level = crit_level or warn_level
114 warn_level = warn_level or crit_level
116 if warn_level and crit_level:
117 levels = (warn_level, crit_level)
118 else:
119 levels = None
121 return check_temperature(temperature, params, "lnx_thermal_%s" % item, dev_levels=levels)
124 check_info['lnx_thermal'] = {
125 "parse_function": parse_lnx_thermal,
126 "inventory_function": inventory_lnx_thermal,
127 "check_function": check_lnx_thermal,
128 "service_description": "Temperature %s",
129 "has_perfdata": True,
130 "group": "temperature",
131 "default_levels_variable": "lnx_thermal_default_levels",
132 "includes": ["temperature.include"],