Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / ra32e_sensors
blobd1c49a566c9db7d70e3f1847e6ef68f68ca9b34c
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 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.
28 def parse_ra32e_sensors(info):
29 def type_of(sensor):
30 def values_until(x):
31 return all(sensor[:x]) and not any(sensor[x:])
33 if values_until(2):
34 return 'temp'
35 elif values_until(3):
36 return 'temp/active'
37 elif values_until(4):
38 return 'temp/analog'
39 elif values_until(5):
40 return 'temp/humidity'
41 return 'unknown'
43 parsed = {
44 'temperature': {},
45 'humidity': {},
46 'voltage': {},
47 'power': {},
50 internal, sensors = info
52 for type_, item, value in zip(['temperature', 'humidity', 'temperature'],
53 ['Internal', 'Internal', 'Heat Index'], internal[0]):
54 if value:
55 parsed[type_][item] = float(value) / 100.0
57 for sensor in sensors:
58 oid_end, sensor_data = sensor[0], sensor[1:]
60 name = 'Sensor %d' % int(oid_end.split('.')[0])
61 type_ = type_of(sensor_data)
63 # uses the format of elphase.include for power and voltage
64 if type_ == 'temp':
65 temperature, _, _, _, _ = sensor_data
66 parsed['temperature'][name] = float(temperature) / 100.0
67 elif type_ == 'temp/active':
68 temperature, _, power_state, _, _ = sensor_data
69 parsed['temperature'][name] = float(temperature) / 100.0
71 power_status_map = {'1': (0, 'power detected'), '0': (2, 'no power detected')}
72 parsed['power'][name] = {'device_state': power_status_map.get(power_state)}
73 elif type_ == 'temp/analog':
74 temperature, _, voltage, _, _ = sensor_data
75 parsed['temperature'][name] = float(temperature) / 100.0
76 parsed['voltage'][name] = {'voltage': (int(voltage), None)}
77 elif type_ == 'temp/humidity':
78 temperature, _, humidity, _, heatindex = sensor_data
79 parsed['temperature'][name] = float(temperature) / 100.0
80 parsed['humidity'][name] = float(humidity) / 100.0
81 parsed['temperature'][name.replace('Sensor', 'Heat Index')] = float(heatindex) / 100.0
83 return parsed
86 def inventory_ra32e_sensors(parsed, quantity):
87 for name in parsed[quantity]:
88 yield name, {}
92 # .--Temperature---------------------------------------------------------.
93 # | _____ _ |
94 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
95 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
96 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
97 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
98 # | |_| |
99 # '----------------------------------------------------------------------'
101 factory_settings["ra32e_sensors_temperature_defaultlevels"] = {
102 "levels": (30.0, 35.0),
106 def check_ra32e_sensors(item, params, parsed):
107 temperature = parsed['temperature'].get(item)
108 if temperature is None:
109 return 3, 'no data for sensor'
111 unique_name = 'ra32e_temp_%s' % item.lower().replace(' ', '')
112 return check_temperature(temperature, params, unique_name)
115 check_info["ra32e_sensors"] = {
116 'parse_function': parse_ra32e_sensors,
117 'inventory_function': lambda x: inventory_ra32e_sensors(x, 'temperature'),
118 'check_function': check_ra32e_sensors,
119 'service_description': 'Temperature %s',
120 'snmp_info': [ # ROOMALERT32E-MIB
122 '.1.3.6.1.4.1.20916.1.8.1.1',
124 '1.2', # internal-tempc
125 '2.1', # internal-humidity
126 '4.2', # internal-heat-indexC
129 '.1.3.6.1.4.1.20916.1.8.1.2',
131 '1', # digital-sen1
132 '2', # digital-sen2
133 '3', # digital-sen3
134 '4', # digital-sen4
135 '5', # digital-sen5
136 '6', # digital-sen6
137 '7', # digital-sen7
138 '8', # digital-sen8
141 # Note:
142 # The output depends on the kind of sensor and a sensor only outputs relevant values.
143 # The following sensors are mentioned in the MIB from the 13th September 2017:
145 # sensor | values
146 # ---------------------------------
147 # Temperature | 1, 2
148 # Temp/Active Power | 1, 2, 3
149 # Temp/Analog | 1, 2, 3, 4
150 # Temp/Humidity | 1, 2, 3, 4, 5
152 OID_END,
153 '1', # digital-sen[1-8]-1 --> Temperature, Temp/Humidity, Temp/Analog, Temp/Active Power: temperature in Celsius
154 '2', # digital-sen[1-8]-2 --> Temperature, Temp/Humidity, Temp/Analog, Temp/Active Power: temperature in Fahrenheit
155 '3', # digital-sen[1-8]-3 --> Temp/Humidity: %RH - Temp/Analog: voltage - Temp/Active Power: power state (1=power detected, 0=no power detected)
156 '4', # digital-sen[1-8]-4 --> Temp/Humidity: heat index Fahrenheit - Temp/Analog: custom reading
157 '5', # digital-sen[1-8]-5 --> Temp/Humidity: heat index Celsius
160 'snmp_scan_function': lambda oid: "1.3.6.1.4.1.20916.1.8" in oid(".1.3.6.1.2.1.1.2.0"),
161 'has_perfdata': True,
162 'includes': ['temperature.include', 'humidity.include', 'elphase.include'],
163 'group': 'temperature',
164 'default_levels_variable': 'ra32e_temp_defaultlevels',
168 # .--Humidity------------------------------------------------------------.
169 # | _ _ _ _ _ _ |
170 # | | | | |_ _ _ __ ___ (_) __| (_) |_ _ _ |
171 # | | |_| | | | | '_ ` _ \| |/ _` | | __| | | | |
172 # | | _ | |_| | | | | | | | (_| | | |_| |_| | |
173 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
174 # | |___/ |
175 # '----------------------------------------------------------------------'
177 factory_settings["ra32e_sensors_humidity_defaultlevels"] = {
178 "levels": (70.0, 80.0),
182 def check_ra32e_humidity_sensors(item, params, parsed):
183 humidity = parsed['humidity'].get(item)
184 if humidity is None:
185 return 3, 'no data for sensor'
187 return check_humidity(humidity, params)
190 check_info["ra32e_sensors.humidity"] = {
191 'inventory_function': lambda x: inventory_ra32e_sensors(x, 'humidity'),
192 'check_function': check_ra32e_humidity_sensors,
193 'service_description': 'Humidity %s',
194 'has_perfdata': True,
195 'group': 'humidity',
196 'default_levels_variable': 'ra32e_humidity_defaultlevels',
200 # .--Voltage-------------------------------------------------------------.
201 # | __ __ _ _ |
202 # | \ \ / /__ | | |_ __ _ __ _ ___ |
203 # | \ \ / / _ \| | __/ _` |/ _` |/ _ \ |
204 # | \ V / (_) | | || (_| | (_| | __/ |
205 # | \_/ \___/|_|\__\__,_|\__, |\___| |
206 # | |___/ |
207 # '----------------------------------------------------------------------'
209 factory_settings["ra32e_sensors_voltage_defaultlevels"] = {
210 'voltage': (210, 180),
214 def check_ra32e_sensors_voltage(item, params, parsed):
215 return next(check_elphase(item, params, parsed['voltage']))
218 check_info["ra32e_sensors.voltage"] = {
219 'inventory_function': lambda x: inventory_ra32e_sensors(x, 'voltage'),
220 'check_function': check_ra32e_sensors_voltage,
221 'service_description': 'Voltage %s',
222 'has_perfdata': True,
223 'group': 'ups_outphase',
224 'default_levels_variable': 'ra32e_sensors_voltage_defaultlevels',
228 # .--Power---------------------------------------------------------------.
229 # | ____ |
230 # | | _ \ _____ _____ _ __ |
231 # | | |_) / _ \ \ /\ / / _ \ '__| |
232 # | | __/ (_) \ V V / __/ | |
233 # | |_| \___/ \_/\_/ \___|_| |
234 # | |
235 # '----------------------------------------------------------------------'
238 def check_ra32e_power_sensors(item, params, parsed):
239 return next(check_elphase(item, params, parsed['power']))
242 check_info["ra32e_sensors.power"] = {
243 'inventory_function': lambda x: inventory_ra32e_sensors(x, 'power'),
244 'check_function': check_ra32e_power_sensors,
245 'service_description': 'Power State %s',
246 'group': 'ups_outphase',