Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / akcp_sensor.include
blobe85dc589c1df3db1a2632a47b389c82f2a273d73
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 # .--General-------------------------------------------------------------.
28 # | _ |
29 # | __ _ ___ _ __ ___ _ __ __ _| | |
30 # | / _` |/ _ \ '_ \ / _ \ '__/ _` | | |
31 # | | (_| | __/ | | | __/ | | (_| | | |
32 # | \__, |\___|_| |_|\___|_| \__,_|_| |
33 # | |___/ |
34 # +----------------------------------------------------------------------+
36 # States for sensors with levels as they are defined in SPAGENT-MIB
37 akcp_sensor_level_states = {
38 "1": (2, "no status"),
39 "2": (0, "normal"),
40 "3": (1, "high warning"),
41 "4": (2, "high critical"),
42 "5": (1, "low warning"),
43 "6": (2, "low critical"),
44 "7": (2, "sensor error"),
48 def snmp_scan_akcp_sensor(oid):
49 return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.3854.1") \
50 and not oid(".1.3.6.1.4.1.3854.2.*")
53 def snmp_scan_akcp_exp(oid):
54 return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.3854.1") \
55 and oid(".1.3.6.1.4.1.3854.2.*")
58 def inventory_akcp_sensor_no_params(info):
59 for line in info:
60 # "1" means online, "2" offline
61 if line[-1] == "1":
62 yield line[0], None
66 # .--Humidity------------------------------------------------------------.
67 # | _ _ _ _ _ |
68 # | | |__ _ _ _ __ ___ (_) __| (_) |_ _ _ |
69 # | | '_ \| | | | '_ ` _ \| |/ _` | | __| | | | |
70 # | | | | | |_| | | | | | | | (_| | | |_| |_| | |
71 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
72 # | |___/ |
73 # +----------------------------------------------------------------------+
75 akcp_humidity_defaultlevels = (30, 35, 60, 65)
78 def inventory_akcp_humidity(info):
79 for description, _percent, _status, online in info:
80 if online == "1":
81 yield description, "akcp_humidity_defaultlevels"
84 def check_akcp_humidity(item, params, info):
85 for description, percent, status, online in info:
86 if description == item:
87 # Online is set to "2" if sensor is offline
88 if online != "1":
89 yield 2, "sensor is offline"
91 if status in ["1", "7"]:
92 state, state_name = akcp_sensor_level_states[status]
93 yield state, "State: %s" % state_name
95 yield check_humidity(int(percent), params)
99 # .--Temperature---------------------------------------------------------.
100 # | _ _ |
101 # | | |_ ___ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
102 # | | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
103 # | | || __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
104 # | \__\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
105 # | |_| |
106 # +----------------------------------------------------------------------+
108 factory_settings["akcp_temp_default_levels"] = {
109 "levels": (32, 35),
113 def inventory_akcp_sensor_temp(info):
114 for line in info:
115 # sensorProbeTempOnline or sensorTemperatureGoOffline has to be at last index
116 # "1" means online, "2" offline
117 if line[-1] == "1":
118 yield line[0], {}
121 def check_akcp_sensor_temp(item, params, info):
122 for description, degree, unit, status, \
123 low_crit, low_warn, high_warn, high_crit, \
124 degreeraw, online \
125 in info:
127 if description == item:
128 # Online is set to "2" if sensor is offline
129 if online != "1":
130 return 2, "sensor is offline"
132 if status in ["1", "7"]:
133 state, state_name = akcp_sensor_level_states[status]
134 return state, "State: %s" % state_name
136 # Unit "F" or "0" stands for Fahrenheit and "C" or "1" for Celsius
137 if unit.isdigit():
138 if unit == "0":
139 unit_normalised = "f"
140 else:
141 unit_normalised = "c"
142 low_crit, low_warn, high_warn, high_crit = \
143 map(float, (low_crit, low_warn, high_warn, high_crit))
144 else:
145 unit_normalised = unit.lower()
146 if int(high_crit) > 100:
147 # Devices with "F" or "C" have the levels in degrees * 10
148 low_crit, low_warn, high_warn, high_crit = \
149 [float(t) / 10 for t in (low_crit, low_warn, high_warn, high_crit)]
150 else:
151 low_crit, low_warn, high_warn, high_crit = \
152 [float(t) for t in (low_crit, low_warn, high_warn, high_crit)]
154 if degreeraw and degreeraw != "0":
155 temperature = float(degreeraw) / 10.0
156 elif not degree:
157 return 3, "Temperature information not found"
158 else:
159 temperature = float(degree)
161 return check_temperature(temperature, params, "akcp_sensor_temp_%s" % item, unit_normalised, \
162 (high_warn, high_crit), (low_warn, low_crit))
166 # .--Water & Smoke-------------------------------------------------------.
167 # | _ ___ _ |
168 # |__ ____ _| |_ ___ _ __ ( _ ) ___ _ __ ___ ___ | | _____ |
169 # |\ \ /\ / / _` | __/ _ \ '__| / _ \/\ / __| '_ ` _ \ / _ \| |/ / _ \ |
170 # | \ V V / (_| | || __/ | | (_> < \__ \ | | | | | (_) | < __/ |
171 # | \_/\_/ \__,_|\__\___|_| \___/\/ |___/_| |_| |_|\___/|_|\_\___| |
172 # | |
173 # +----------------------------------------------------------------------+
176 def check_akcp_sensor_relay(item, _no_params, info):
177 # States for sensors with relays as they are defined in SPAGENT-MIB
178 relay_states = {
179 "1": (2, "no status"),
180 "2": (0, "normal"),
181 "4": (2, "high critical"),
182 "6": (2, "low critical"),
183 "7": (2, "sensor error"),
184 "8": (2, "relay on"),
185 "9": (0, "relay off"),
188 for description, status, online in info:
189 if description == item:
190 # Online is set to "2" if sensor is offline
191 if online != "1":
192 return 2, "sensor is offline"
194 state, state_name = relay_states[status]
195 return state, "State: %s" % state_name
199 # .--Drycontact----------------------------------------------------------.
200 # | _ _ _ |
201 # | __| |_ __ _ _ ___ ___ _ __ | |_ __ _ ___| |_ |
202 # | / _` | '__| | | |/ __/ _ \| '_ \| __/ _` |/ __| __| |
203 # | | (_| | | | |_| | (_| (_) | | | | || (_| | (__| |_ |
204 # | \__,_|_| \__, |\___\___/|_| |_|\__\__,_|\___|\__| |
205 # | |___/ |
206 # +----------------------------------------------------------------------+
209 def check_akcp_sensor_drycontact(item, _no_params, info):
210 # States which are not configurable by user as they are defined in SPAGENT-MIB
211 states = {
212 "1": (2, "no status"),
213 "7": (2, "sensor error"),
214 "8": (2, "output low"),
215 "9": (2, "output high"),
218 for line in info:
219 if item == line[0]:
220 if len(line) == 5:
221 status, crit_desc, normal_desc, online = line[1:]
222 else:
223 status, online = line[1:]
224 normal_desc = "Drycontact OK"
225 crit_desc = "Drycontact on Error"
227 if online != "1":
228 infotext = "Sensor is offline"
229 state = 2
230 elif status == "2":
231 state = 0
232 infotext = normal_desc
233 elif status in ["4", "6"]:
234 state = 2
235 infotext = crit_desc
236 else:
237 state, infotext = states[status]
239 return state, infotext