Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / allnet_ip_sensoric
blob60bfec80e3507194fcbe230f735ce054f833719c
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 # Example output from agent:
29 # <<<allnet_ip_sensoric:sep(59)>>>
30 # sensor0.alarm0;0
31 # sensor0.all4000_typ;0
32 # sensor0.function;1
33 # sensor0.limit_high;50.00
34 # sensor0.limit_low;10.00
35 # sensor0.maximum;28.56
36 # sensor0.minimum;27.50
37 # sensor0.name;Temperatur intern
38 # sensor0.value_float;27.50
39 # sensor0.value_int;2750
40 # sensor0.value_string;27.50
41 # sensor1.alarm1;0
42 # sensor1.all4000_typ;0
43 # sensor1.function;3
44 # sensor1.limit_high;50.00
45 # sensor1.limit_low;-0.50
46 # sensor1.maximum;0.00
47 # sensor1.minimum;2048000.00
48 # sensor1.name;ADC 0
49 # sensor1.value_float;0.00
50 # sensor1.value_int;0
51 # sensor1.value_string;0.00
52 # [...]
53 # sensor9.alarm9;1
54 # sensor9.all4000_typ;101
55 # sensor9.function;12
56 # sensor9.limit_high;85.00
57 # sensor9.limit_low;10.00
58 # sensor9.maximum;100.00
59 # sensor9.minimum;2048000.02
60 # sensor9.name;USV Spannung
61 # sensor9.value_float;100.00
62 # sensor9.value_int;100
63 # sensor9.value_string;100
64 # system.alarmcount;4
65 # system.date;30.06.2014
66 # system.devicename;all5000
67 # system.devicetype;ALL5000
68 # system.sys;114854
69 # system.time;16:08:48
72 def parse_allnet_ip_sensoric(info):
73 '''parses agent output in a structure like:
74 {'sensor0': {'alarm0': '0',
75 'all4000_typ': '0',
76 'function': '1',
77 'limit_high': '50.00',
78 'limit_low': '10.00',
79 'maximum': '28.56',
80 'minimum': '27.43',
81 'name': 'Temperatur intern',
82 'value_float': '27.50',
83 'value_int': '2750',
84 'value_string': '27.50'},
85 [...]
86 'system': {'alarmcount': '4',
87 'date': '30.06.2014',
88 'devicename': 'all5000',
89 'devicetype': 'ALL5000',
90 'sys': '116240',
91 'time': '16:57:50'}}
92 '''
93 parsed = {}
94 for key, value in info:
95 match = re.search(r'(\w+)\.(\w+)', key)
96 if match:
97 sensor = match.group(1)
98 field = match.group(2)
99 parsed.setdefault(sensor, {})
100 parsed[sensor][field] = value
102 return parsed
105 def allnet_ip_sensoric_compose_item(sensor_id, sensor):
106 sensor_id = re.sub("sensor", "", sensor_id)
107 if "name" in sensor.keys():
108 item = "%s Sensor %s" % (sensor["name"], sensor_id)
109 else:
110 item = "Sensor %s" % (sensor_id)
111 return item
114 # .--el. tension---------------------------------------------------------.
115 # | _ _ _ |
116 # | ___| | | |_ ___ _ __ ___(_) ___ _ __ |
117 # | / _ \ | | __/ _ \ '_ \/ __| |/ _ \| '_ \ |
118 # | | __/ |_ | || __/ | | \__ \ | (_) | | | | |
119 # | \___|_(_) \__\___|_| |_|___/_|\___/|_| |_| |
120 # | |
121 # '----------------------------------------------------------------------'
124 def inventory_allnet_ip_sensoric_tension(parsed):
125 inventory = []
126 for sensor in parsed.keys():
127 if "function" in parsed[sensor].keys() and parsed[sensor]["function"] == "12":
128 item = allnet_ip_sensoric_compose_item(sensor, parsed[sensor])
129 inventory.append((item, None))
130 return inventory
133 def check_allnet_ip_sensoric_tension(item, _no_params, parsed):
134 sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
136 if sensor_id not in parsed.keys():
137 return 3, "%s not found in agent output" % item
139 value = float(parsed[sensor_id]["value_float"])
141 perfdata = [("tension", value, None, None, 0, 100)]
143 status = 0
144 if value == 0:
145 status = 2
147 return status, "%d%% of the normal level" % value, perfdata
150 check_info["allnet_ip_sensoric.tension"] = {
151 "check_function": check_allnet_ip_sensoric_tension,
152 "inventory_function": inventory_allnet_ip_sensoric_tension,
153 "service_description": "Electric Tension %s",
154 "has_perfdata": True,
158 # .--temp----------------------------------------------------------------.
159 # | _ |
160 # | | |_ ___ _ __ ___ _ __ |
161 # | | __/ _ \ '_ ` _ \| '_ \ |
162 # | | || __/ | | | | | |_) | |
163 # | \__\___|_| |_| |_| .__/ |
164 # | |_| |
165 # '----------------------------------------------------------------------'
167 factory_settings["allnet_ip_sensoric_temp_default_levels"] = {"levels": (35, 40)}
170 def inventory_allnet_ip_sensoric_temp(parsed):
171 for sensor in parsed.keys():
172 if (parsed[sensor].get('function') and parsed[sensor]["function"] == "1") \
173 or (parsed[sensor].get('unit') and parsed[sensor]['unit'] == u'°C'):
174 item = allnet_ip_sensoric_compose_item(sensor, parsed[sensor])
175 yield item, {}
178 def check_allnet_ip_sensoric_temp(item, params, parsed):
179 sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
181 if sensor_id not in parsed.keys():
182 return 3, "Sensor not found in agent output"
184 temp = float(parsed[sensor_id]["value_float"])
186 return check_temperature(temp, params, "allnet_ip_sensoric_temp_%s" % item)
189 check_info["allnet_ip_sensoric.temp"] = {
190 "check_function": check_allnet_ip_sensoric_temp,
191 "inventory_function": inventory_allnet_ip_sensoric_temp,
192 "service_description": "Temperature %s",
193 "has_perfdata": True,
194 "group": "temperature",
195 "includes": ["temperature.include"],
196 "default_levels_variable": "allnet_ip_sensoric_temp_default_levels"
200 # .--humidity------------------------------------------------------------.
201 # | _ _ _ _ _ |
202 # | | |__ _ _ _ __ ___ (_) __| (_) |_ _ _ |
203 # | | '_ \| | | | '_ ` _ \| |/ _` | | __| | | | |
204 # | | | | | |_| | | | | | | | (_| | | |_| |_| | |
205 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
206 # | |___/ |
207 # '----------------------------------------------------------------------'
209 allnet_ip_sensoric_humidity_default_levels = (35, 40, 60, 65)
212 def inventory_allnet_ip_sensoric_humidity(parsed):
213 inventory = []
214 for sensor in parsed.keys():
215 if "function" in parsed[sensor].keys() and parsed[sensor]["function"] == "2":
216 item = allnet_ip_sensoric_compose_item(sensor, parsed[sensor])
217 inventory.append((item, "allnet_ip_sensoric_humidity_default_levels"))
218 return inventory
221 def check_allnet_ip_sensoric_humidity(item, params, parsed):
222 sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
223 if sensor_id not in parsed.keys():
224 return 3, "%s not found in agent output" % item
226 return check_humidity(float(parsed[sensor_id]["value_float"]), params)
229 check_info["allnet_ip_sensoric.humidity"] = {
230 "check_function": check_allnet_ip_sensoric_humidity,
231 "inventory_function": inventory_allnet_ip_sensoric_humidity,
232 "service_description": "Humidity %s",
233 "has_perfdata": True,
234 "group": "humidity",
235 "includes": ["humidity.include"],
239 # .--pressure------------------------------------------------------------.
240 # | |
241 # | _ __ _ __ ___ ___ ___ _ _ _ __ ___ |
242 # | | '_ \| '__/ _ \/ __/ __| | | | '__/ _ \ |
243 # | | |_) | | | __/\__ \__ \ |_| | | | __/ |
244 # | | .__/|_| \___||___/___/\__,_|_| \___| |
245 # | |_| |
246 # '----------------------------------------------------------------------'
249 def inventory_allnet_ip_sensoric_pressure(parsed):
250 inventory = []
251 for sensor in parsed.keys():
252 if "function" in parsed[sensor].keys() and parsed[sensor]["function"] == "16":
253 item = allnet_ip_sensoric_compose_item(sensor, parsed[sensor])
254 inventory.append((item, None))
255 return inventory
258 def check_allnet_ip_sensoric_pressure(item, _no_params, parsed):
259 sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
261 if sensor_id not in parsed.keys():
262 return 3, "%s not found in agent output" % item
264 pressure = float(parsed[sensor_id]["value_float"]) / 1000
266 perfdata = [("pressure", str(pressure) + "bars", None, None, 0)]
268 return 0, "%s is %0.5f bars" % (item, pressure), perfdata
271 check_info["allnet_ip_sensoric.pressure"] = {
272 "check_function": check_allnet_ip_sensoric_pressure,
273 "inventory_function": inventory_allnet_ip_sensoric_pressure,
274 "service_description": "Pressure %s",
275 "has_perfdata": True,
280 check_info["allnet_ip_sensoric"] = {
281 "parse_function": parse_allnet_ip_sensoric,