Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / cmctc_lcp
blob20e60689e6e0f687747875b38db75d23e399cc39
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 cmctc_lcp_sensors = {
28 4: (None, "access"),
29 12: (None, "humidity"),
31 # User Sensors
32 13: ("normally open", "user"),
33 14: ("normally closed", "user"),
35 # Leakage
36 23: (None, "flow"),
37 30: (None, "current"),
38 31: (None, "status"),
39 32: (None, "position"),
41 # Blower
42 40: ("1", "blower"),
43 41: ("2", "blower"),
44 42: ("3", "blower"),
45 43: ("4", "blower"),
46 44: ("5", "blower"),
47 45: ("6", "blower"),
48 46: ("7", "blower"),
49 47: ("8", "blower"),
51 # Server in/out
52 48: ("Server in 1", "temp"),
53 49: ("Server out 1", "temp"),
54 50: ("Server in 2", "temp"),
55 51: ("Server out 2", "temp"),
56 52: ("Server in 3", "temp"),
57 53: ("Server out 3", "temp"),
58 54: ("Server in 4", "temp"),
59 55: ("Server out 4", "temp"),
61 # Overview Server
62 56: ("Overview Server in", "temp"),
63 57: ("Overview Server out", "temp"),
65 # Water
66 58: ("Water in", "temp"),
67 59: ("Water out", "temp"),
68 60: (None, "flow"),
70 # Other stuff
71 61: (None, "blowergrade"),
72 62: (None, "regulator"),
76 def inventory_cmctc_lcp(info, sensortype):
77 inventory = []
78 for index, typeid, _status, _value, _high, _low, _warn, _description in info:
79 typeid = saveint(typeid)
80 if typeid in cmctc_lcp_sensors:
81 item, st = cmctc_lcp_sensors[typeid]
82 if st == sensortype:
83 if item:
84 item = item + " - " + index
85 else:
86 item = index
87 inventory.append((item, None))
88 return inventory
91 def check_cmctc_lcp(item, params, info, sensortype):
92 map_sensor_state = {
93 "1": (3, "not available"),
94 "2": (2, "lost"),
95 "3": (1, "changed"),
96 "4": (0, "ok"),
97 "5": (2, "off"),
98 "6": (0, "on"),
99 "7": (1, "warning"),
100 "8": (2, "too low"),
101 "9": (2, "too high"),
102 "10": (2, "error"),
105 map_unit = {
106 "access": "",
107 "current": " A",
108 "status": "",
109 "position": "",
110 "temp": u" °C",
111 "blower": " RPM",
112 "blowergrade": "",
113 "humidity": "%",
114 "flow": " l/min",
115 "regulator": "%",
116 "user": "",
119 itemindex = item.split(" - ")[-1]
120 for index, _typeid, statuscode, value, high, low, warn, description in info:
121 if itemindex == index:
122 unit = map_unit[sensortype]
123 value = int(value)
124 infotext = ""
125 if description:
126 infotext += "[%s] " % description
127 state, extra_info = map_sensor_state[statuscode]
128 yield state, "%s%d%s" % (infotext, value, unit)
130 extra_state = 0
131 if params:
132 warn, crit = params
133 perfdata = [(sensortype, value, warn, crit)]
134 if value >= crit:
135 extra_state = 2
136 elif value >= warn:
137 extra_state = 1
139 if extra_state:
140 extra_info += " (warn/crit at %d/%d%s)" % (warn, crit, unit)
141 else:
142 perfdata = [(sensortype, value)]
143 # Assumption: if high and low are both 0
144 # then there are no device levels
145 if not (int(high) == 0 and int(low) == 0) and int(high) > int(low):
146 if value >= int(high) or value <= int(low):
147 extra_state = 2
148 extra_info += " (device lower/upper crit at %s/%s%s)" % (low, high, unit)
150 yield extra_state, extra_info, perfdata
153 def inventory_cmctc_lcp_temp(info):
154 inventory = []
155 for index, typeid, _status, _value, _high, _low, _warn, _description in info:
156 typeid = saveint(typeid)
157 if typeid in cmctc_lcp_sensors:
158 item, st = cmctc_lcp_sensors[typeid]
159 if st == "temp":
160 if item:
161 item = item + " - " + index
162 else:
163 item = index
164 inventory.append((item, None))
165 return inventory
168 def check_cmctc_lcp_temp(item, params, info):
169 itemindex = item.split(" - ")[-1]
170 for index, _typeid, statuscode, value, high, low, warn, _description in info:
171 if itemindex == index:
172 status = int(statuscode)
173 levels = None if high == low == warn == "0" else \
174 (float(warn), float(high))
175 levels_low = None if high == low == warn == "0" else \
176 (float(low), float("-inf")) # no lower critical level specified
177 return check_temperature(
178 float(value),
179 params,
180 "cmctc_lcp_temp_%s" % item,
181 dev_levels=levels,
182 dev_levels_lower=levels_low,
183 dev_status=cmctc_translate_status(status),
184 dev_status_name="Unit: %s" % cmctc_translate_status_text(status))
185 return 3, "Sensor not found in SNMP output", []
188 snmp_scan_functions["cmctc_lcp"] = cmctc_snmp_scan_function
190 snmp_info["cmctc_lcp"] = (
191 ".1.3.6.1.4.1.2606.4.2",
193 "3", # cmcTcUnit1OutputTable
194 "4", # cmcTcUnit2OutputTable
195 "5", # cmcTcUnit3OutputTable
196 "6" # cmcTcUnit4OutputTable
199 "5.2.1.1", # Index
200 "5.2.1.2", # Sensor Type
201 "5.2.1.4", # Status
202 "5.2.1.5", # Value
203 "5.2.1.6", # High
204 "5.2.1.7", # Low
205 "5.2.1.8", # Warn
206 "7.2.1.2", # Description
209 check_info['cmctc_lcp.access'] = {
210 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'access'),
211 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'access'),
212 "has_perfdata": True,
213 "service_description": "Access %s",
216 check_info['cmctc_lcp.blower'] = {
217 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'blower'),
218 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'blower'),
219 "has_perfdata": True,
220 "service_description": "Blower %s",
223 check_info['cmctc_lcp.blowergrade'] = {
224 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'blowergrade'),
225 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'blowergrade'),
226 "has_perfdata": True,
227 "service_description": "Blower Grade %s",
230 check_info['cmctc_lcp.current'] = {
231 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'current'),
232 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'current'),
233 "has_perfdata": True,
234 "service_description": "Current %s",
237 check_info['cmctc_lcp.flow'] = {
238 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'flow'),
239 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'flow'),
240 "has_perfdata": True,
241 "service_description": "Waterflow %s",
244 check_info['cmctc_lcp.humidity'] = {
245 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'humidity'),
246 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'humidity'),
247 "has_perfdata": True,
248 "service_description": "Humidity %s",
251 check_info['cmctc_lcp.position'] = {
252 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'position'),
253 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'position'),
254 "has_perfdata": True,
255 "service_description": "Position %s",
258 check_info['cmctc_lcp.regulator'] = {
259 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'regulator'),
260 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'regulator'),
261 "has_perfdata": True,
262 "service_description": "Regulator %s",
265 check_info['cmctc_lcp.status'] = {
266 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'status'),
267 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'status'),
268 "has_perfdata": True,
269 "service_description": "Status %s",
272 check_info['cmctc_lcp.user'] = {
273 "check_function": lambda item, params, info: check_cmctc_lcp(item, params, info, 'user'),
274 "inventory_function": lambda info: inventory_cmctc_lcp(info, 'user'),
275 "has_perfdata": True,
276 "service_description": "User Sensor %s",
279 # temperature check is standardised
280 check_info['cmctc_lcp.temp'] = {
281 "check_function": check_cmctc_lcp_temp,
282 "inventory_function": inventory_cmctc_lcp_temp,
283 "has_perfdata": True,
284 "service_description": "Temperature %s",
285 "group": "temperature",
286 "includes": ["temperature.include", "cmctc.include"]