Cleanup config.nodes_of
[check_mk.git] / checks / enviromux.include
blobab8f564221261b4493366f9b249d3d4ceb0cebad
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 # .--parse functions-----------------------------------------------------.
29 # | |
30 # | _ __ __ _ _ __ ___ ___ |
31 # | | '_ \ / _` | '__/ __|/ _ \ |
32 # | | |_) | (_| | | \__ \ __/ |
33 # | | .__/ \__,_|_| |___/\___| |
34 # | |_| |
35 # | __ _ _ |
36 # | / _|_ _ _ __ ___| |_(_) ___ _ __ ___ |
37 # | | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
38 # | | _| |_| | | | | (__| |_| | (_) | | | \__ \ |
39 # | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
40 # | |
41 # +----------------------------------------------------------------------+
42 # | |
43 # '----------------------------------------------------------------------'
45 sensor_type_names = {
46 "0": "undefined",
47 "1": "temperature",
48 "2": "humidity",
49 "3": "power",
50 "4": "lowVoltage",
51 "5": "current",
52 "6": "aclmvVoltage",
53 "7": "aclmpVoltage",
54 "8": "aclmpPower",
55 "9": "water",
56 "10": "smoke",
57 "11": "vibration",
58 "12": "motion",
59 "13": "glass",
60 "14": "door",
61 "15": "keypad",
62 "16": "panicButton",
63 "17": "keyStation",
64 "18": "digInput",
65 "22": "light",
66 "41": "rmsVoltage",
67 "42": "rmsCurrent",
68 "43": "activePower",
69 "513": "tempHum",
70 "32767": "custom",
71 "32769": "temperatureCombo",
72 "32770": "humidityCombo",
73 "540": "tempHum",
76 sensor_type_names_sems_external = {
77 "0": "undefined",
78 "1": "temperature",
79 "2": "humidity",
80 "3": "power",
81 "4": "lowVoltage",
82 "5": "current",
83 "6": "aclmvVoltage",
84 "7": "aclmpVoltage",
85 "8": "aclmpPower",
86 "9": "water",
87 "10": "smoke",
88 "11": "vibration",
89 "12": "motion",
90 "13": "glass",
91 "14": "door",
92 "15": "keypad",
93 "16": "panicButton",
94 "17": "keyStation",
95 "18": "dryContact",
96 "22": "light",
97 "513": "tempHum",
98 "32767": "custom",
99 "32769": "temperatureCombo",
100 "32770": "humidityCombo",
103 sensor_type_names_external = {
104 "0": "undefined",
105 "1": "temperature",
106 "2": "humidity",
107 "3": "power",
108 "4": "lowVoltage",
109 "5": "current",
110 "6": "aclmvVoltage",
111 "7": "aclmpVoltage",
112 "8": "aclmpPower",
113 "9": "water",
114 "10": "smoke",
115 "11": "vibration",
116 "12": "motion",
117 "13": "glass",
118 "14": "door",
119 "15": "keypad",
120 "16": "panicButton",
121 "17": "keyStation",
122 "18": "digInput",
123 "22": "light",
124 "26": "tacDio",
125 "36": "acVoltage",
126 "37": "acCurrent",
127 "38": "dcVoltage",
128 "39": "dcCurrent",
129 "41": "rmsVoltage",
130 "42": "rmsCurrent",
131 "43": "activePower",
132 "44": "reactivePower",
133 "513": "tempHum",
134 "32767": "custom",
135 "32769": "temperatureCombo",
136 "32770": "humidityCombo",
139 sensor_status_names = {
140 "0": "notconnected",
141 "1": "normal",
142 "2": "prealert",
143 "3": "alert",
144 "4": "acknowledged",
145 "5": "dismissed",
146 "6": "disconnected",
149 sensor_digital_value_names = {
150 "0": "closed",
151 "1": "open",
154 factory_settings["enviromux_default_levels"] = {
155 "levels": (15, 16),
156 "levels_lower": (10, 9),
160 def parse_enviromux(info):
161 parsed = {}
163 for line in info:
164 sensor_descr = line[2]
165 sensor_index = line[0]
166 item = sensor_descr + " " + sensor_index
168 sensor_type = sensor_type_names.get(line[1], "unknown")
169 sensor_status = sensor_status_names.get(line[8], "unknown")
170 # Observed in the wild: "power" may actually be a voltage m(
171 if sensor_type in ["temperature", "power", "current"]:
172 # The MIB specifies that currents, voltages and temperatures have a scaling factor 10
173 sensor_value = int(line[5]) / 10.0
174 sensor_min = int(line[9]) / 10.0
175 sensor_max = int(line[10]) / 10.0
176 else:
177 sensor_value = int(line[5])
178 sensor_min = int(line[9])
179 sensor_max = int(line[10])
181 parsed[item] = {
182 "sensor_type": sensor_type,
183 "sensor_status": sensor_status,
184 "sensor_value": sensor_value,
185 "sensor_min": sensor_min,
186 "sensor_max": sensor_max,
187 "sensor_unit": line[6], # e.g. V, C, %
190 return parsed
193 def parse_enviromux_sems_external(info):
194 parsed = {}
196 for line in info:
197 sensor_descr = line[2]
198 sensor_index = line[0]
199 item = sensor_descr + " " + sensor_index
201 sensor_type = sensor_type_names.get(line[1], "unknown")
202 sensor_status = sensor_status_names.get(line[8], "unknown")
203 # Observed in the wild: "power" may actually be a voltage m(
204 if sensor_type in ["temperature", "power", "current"]:
205 # The MIB specifies that currents, voltages and temperatures have a scaling factor 10
206 sensor_value = int(line[6]) / 10.0
207 sensor_min = int(line[10]) / 10.0
208 sensor_max = int(line[11]) / 10.0
209 else:
210 sensor_value = int(line[6])
211 sensor_min = int(line[10])
212 sensor_max = int(line[11])
214 parsed[item] = {
215 "sensor_type": sensor_type,
216 "sensor_status": sensor_status,
217 "sensor_value": sensor_value,
218 "sensor_min": sensor_min,
219 "sensor_max": sensor_max,
220 "sensor_unit": line[6], # e.g. V, C, %
223 return parsed
226 def parse_enviromux_external(info):
227 parsed = {}
229 for line in info:
230 sensor_descr = line[2]
231 sensor_index = line[0]
232 item = sensor_descr + " " + sensor_index
234 sensor_type = sensor_type_names.get(line[1], "unknown")
235 sensor_status = sensor_status_names.get(line[8], "unknown")
236 # Observed in the wild: "power" may actually be a voltage m(
237 if sensor_type in ["temperature", "power", "current", "temperatureCombo"]:
238 # The MIB specifies that currents, voltages and temperatures have a scaling factor 10
239 sensor_value = int(line[6]) / 10.0
240 sensor_min = int(line[10]) / 10.0
241 sensor_max = int(line[11]) / 10.0
242 else:
243 sensor_value = int(line[6])
244 sensor_min = int(line[10])
245 sensor_max = int(line[11])
247 parsed[item] = {
248 "sensor_type": sensor_type,
249 "sensor_status": sensor_status,
250 "sensor_value": sensor_value,
251 "sensor_min": sensor_min,
252 "sensor_max": sensor_max,
253 "sensor_unit": line[6], # e.g. V, C, %
256 return parsed
259 def parse_enviromux_digital(info):
260 parsed = {}
262 for line in info:
263 sensor_descr = line[2]
264 sensor_index = line[0]
265 sensor_normal_value = sensor_digital_value_names.get(line[8], "unknown")
266 sensor_value = sensor_digital_value_names.get(line[6], "unknown")
267 item = sensor_descr + " " + sensor_index
268 sensor_status = sensor_status_names.get(line[7], "unknown")
269 parsed[item] = {
270 "sensor_status": sensor_status,
271 "sensor_value": sensor_value,
272 "sensor_normal_value": sensor_normal_value,
275 return parsed
278 def parse_enviromux_sems_digital(info):
279 parsed = {}
281 for line in info:
282 sensor_descr = line[1]
283 sensor_index = line[0]
284 sensor_normal_value = sensor_digital_value_names.get(line[5], "unknown")
285 sensor_value = sensor_digital_value_names.get(line[4], "unknown")
286 item = sensor_descr + " " + sensor_index
287 sensor_status = sensor_status_names.get(line[6], "unknown")
288 parsed[item] = {
289 "sensor_status": sensor_status,
290 "sensor_value": sensor_value,
291 "sensor_normal_value": sensor_normal_value,
294 return parsed
298 # .--inventory functions-------------------------------------------------.
299 # | _ _ |
300 # | (_)_ ____ _____ _ __ | |_ ___ _ __ _ _ |
301 # | | | '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | |
302 # | | | | | \ V / __/ | | | || (_) | | | |_| | |
303 # | |_|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | |
304 # | |___/ |
305 # | __ _ _ |
306 # | / _|_ _ _ __ ___| |_(_) ___ _ __ ___ |
307 # | | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
308 # | | _| |_| | | | | (__| |_| | (_) | | | \__ \ |
309 # | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
310 # | |
311 # +----------------------------------------------------------------------+
312 # | |
313 # '----------------------------------------------------------------------'
316 def inventory_enviromux_temperature(parsed):
317 for item, sensor_data in parsed.items():
318 if sensor_data["sensor_type"] in ["temperature", "temperatureCombo"]:
319 yield item, {}
322 def inventory_enviromux_voltage(parsed):
323 for item, sensor_data in parsed.items():
324 if sensor_data["sensor_type"] == "power":
325 yield item, {}
328 def inventory_enviromux_humidity(parsed):
329 for item, sensor_data in parsed.items():
330 if sensor_data["sensor_type"] in ["humidity", "humidityCombo"]:
331 yield item, {}
335 # .--scan functions------------------------------------------------------.
336 # | __ _ _ |
337 # | ___ ___ __ _ _ __ / _|_ _ _ __ ___| |_(_) ___ _ __ ___ |
338 # | / __|/ __/ _` | '_ \ | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
339 # | \__ \ (_| (_| | | | | | _| |_| | | | | (__| |_| | (_) | | | \__ \ |
340 # | |___/\___\__,_|_| |_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
341 # | |
342 # +----------------------------------------------------------------------+
343 # | |
344 # '----------------------------------------------------------------------'
347 def enviromux_scan_function(oid):
348 return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.3699.1.1.11")
351 def enviromux_sems_scan_function(oid):
352 return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.3699.1.1.2")
356 # .--check functions-----------------------------------------------------.
357 # | _ _ |
358 # | ___| |__ ___ ___| | __ |
359 # | / __| '_ \ / _ \/ __| |/ / |
360 # | | (__| | | | __/ (__| < |
361 # | \___|_| |_|\___|\___|_|\_\ |
362 # | |
363 # | __ _ _ |
364 # | / _|_ _ _ __ ___| |_(_) ___ _ __ ___ |
365 # | | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
366 # | | _| |_| | | | | (__| |_| | (_) | | | \__ \ |
367 # | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
368 # | |
369 # +----------------------------------------------------------------------+
370 # | |
371 # '----------------------------------------------------------------------'
374 def check_enviromux_temperature(item, params, parsed):
375 dev_levels_lower = (parsed[item]['sensor_min'], parsed[item]['sensor_min'])
376 dev_levels = (parsed[item]['sensor_max'], parsed[item]['sensor_max'])
377 return check_temperature(
378 parsed[item]['sensor_value'],
379 params,
380 item,
381 dev_levels_lower=dev_levels_lower,
382 dev_levels=dev_levels)
385 def check_enviromux_voltage(item, params, parsed):
386 sensor_value = parsed[item]['sensor_value']
387 perf = [("voltage", sensor_value)]
388 infotext = "Input Voltage is %.1f V" % sensor_value
389 min_warn = params['levels_lower'][0]
390 min_crit = params['levels_lower'][1]
391 max_warn = params['levels'][0]
392 max_crit = params['levels'][1]
393 levelstext_lower = " (warn/crit below %s/%s)" % (min_warn, min_crit)
394 levelstext_upper = " (warn/crit at %s/%s)" % (max_warn, max_crit)
395 levelstext = ""
396 if sensor_value >= max_crit:
397 state = 2
398 levelstext = levelstext_upper
399 elif sensor_value < min_crit:
400 state = 2
401 levelstext = levelstext_lower
402 elif sensor_value < min_warn:
403 state = 1
404 levelstext = levelstext_lower
405 elif sensor_value >= max_warn:
406 state = 1
407 levelstext = levelstext_upper
408 else:
409 state = 0
410 if state:
411 infotext += levelstext
412 return state, infotext, perf
415 def check_enviromux_humidity(item, params, parsed):
416 return check_humidity(parsed[item]['sensor_value'], params)