Refactored snapin server_time to new snapin API
[check_mk.git] / checks / watchdog_sensors
blob11b2d6204c771016a92428097c7461dbe615b460
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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 # very odd and confusing example outputs:
30 # version 3.0.0
31 # .1.3.6.1.4.1.21239.5.1.1.2.0 3.0.0
32 # .1.3.6.1.4.1.21239.5.1.1.7.0 1
33 # .1.3.6.1.4.1.21239.5.1.2.1.3.1 Data Center 1
34 # .1.3.6.1.4.1.21239.5.1.2.1.5.1 1
35 # .1.3.6.1.4.1.21239.5.1.2.1.4.1 "91 54 06 9D C9 54 06 9D E9 C9 06 9D BD 9B 06 9D "
36 # .1.3.6.1.4.1.21239.5.1.2.1.6.1 199
37 # .1.3.6.1.4.1.21239.5.1.2.1.7.1 36
38 # .1.3.6.1.4.1.21239.5.1.2.1.8.1 44
40 # version 3.2.0
41 # .1.3.6.1.4.1.21239.5.1.1.2.0 3.2.0
42 # .1.3.6.1.4.1.21239.5.1.1.7.0 1
43 # .1.3.6.1.4.1.21239.5.1.2.1.1.1 1
44 # .1.3.6.1.4.1.21239.5.1.2.1.2.1 41D88039003580C3
45 # .1.3.6.1.4.1.21239.5.1.2.1.3.1 RSGLDN Watchdog 15
46 # .1.3.6.1.4.1.21239.5.1.2.1.4.1 1
47 # .1.3.6.1.4.1.21239.5.1.2.1.5.1 173
48 # .1.3.6.1.4.1.21239.5.1.2.1.6.1 46
49 # .1.3.6.1.4.1.21239.5.1.2.1.7.1 56
51 def parse_watchdog_sensors(info):
52 translate_unit = {
53 '1' : 'C',
54 '0' : 'F',
57 translate_availability = {
58 '0' : (2, 'unavailable'),
59 '1' : (0, 'available'),
60 '2' : (1, 'partially unavailable'),
63 parsed = {}
65 general, data = info
66 # sometimes there is an empty string in
67 # the output. We need to handle this...
68 if not general[0][1] == "":
69 unit = translate_unit[general[0][1]]
70 else:
71 unit = "C"
73 version = int(general[0][0].replace('.', ''))
75 if version <= 300:
76 for line in data:
77 item = line[0]
79 parsed[item] = {}
80 parsed[item]['descr'] = line[1]
81 parsed[item]['availability'] = translate_availability[line[3]]
82 parsed[item]['temp'] = (line[4], unit)
83 parsed[item]['humidity'] = line[5]
84 parsed[item]['dew'] = (line[6], unit)
85 else:
86 for line in data:
87 item = line[0]
89 parsed[item] = {}
90 parsed[item]['descr'] = line[1]
91 parsed[item]['availability'] = translate_availability[line[2]]
92 parsed[item]['temp'] = (line[3], unit)
93 parsed[item]['humidity'] = line[4]
94 parsed[item]['dew'] = (line[5], unit)
96 return parsed
100 # .--general-------------------------------------------------------------.
101 # | _ |
102 # | __ _ ___ _ __ ___ _ __ __ _| | |
103 # | / _` |/ _ \ '_ \ / _ \ '__/ _` | | |
104 # | | (_| | __/ | | | __/ | | (_| | | |
105 # | \__, |\___|_| |_|\___|_| \__,_|_| |
106 # | |___/ |
107 # +----------------------------------------------------------------------+
108 # | |
109 # '----------------------------------------------------------------------'
111 def inventory_watchdog_sensors(parsed):
112 for key in parsed:
113 yield ( key, {} )
116 def check_watchdog_sensors(item, params, parsed):
117 data = None
118 for key in parsed:
119 if key == item:
120 data = parsed[key]
122 if data:
123 descr = data['descr']
124 state, state_readable = data['availability']
126 yield state, state_readable
128 if not descr == '':
129 yield 0, "Location: %s" % descr
132 check_info['watchdog_sensors'] = {
133 'parse_function' : parse_watchdog_sensors,
134 'inventory_function' : inventory_watchdog_sensors,
135 'check_function' : check_watchdog_sensors,
136 'service_description' : 'Watchdog %s',
137 'snmp_info' : [ ('.1.3.6.1.4.1.21239.5.1.1', [
138 '2', #GEIST-V4-MIB::productVersion
139 '7', #GEIST-V4-MIB::temperatureUnits
141 ('.1.3.6.1.4.1.21239.5.1.2.1', [OID_END,
142 '3', #GEIST-V4-MIB::internalName
143 '4', #GEIST-V4-MIB::internalLabel but internalAvail if version 3.2.0
144 '5', #GEIST-V4-MIB::internalAvail but internalTemp if version 3.2.0
145 '6', #GEIST-V4-MIB::internalTemp but internalHumidity if version 3.2.0
146 '7', #GEIST-V4-MIB::internalHumidity but internalDewPoint if version 3.2.0
147 '8', #GEIST-V4-MIB::internalDewPoint but empty if version 3.2.0
148 ]) ],
149 'snmp_scan_function' : lambda oid: oid('.1.3.6.1.2.1.1.2.0').startswith('.1.3.6.1.4.1.21239.5.1'),
150 'includes' : [ 'temperature.include' ]
155 # .--temp----------------------------------------------------------------.
156 # | _ |
157 # | | |_ ___ _ __ ___ _ __ |
158 # | | __/ _ \ '_ ` _ \| '_ \ |
159 # | | || __/ | | | | | |_) | |
160 # | \__\___|_| |_| |_| .__/ |
161 # | |_| |
162 # +----------------------------------------------------------------------+
163 # | |
164 # '----------------------------------------------------------------------'
166 def inventory_watchdog_sensors_temp(parsed):
167 for key in parsed:
168 yield (key, {})
171 def check_watchdog_sensors_temp(item, params, parsed):
172 if item in parsed:
173 temperature_str, unit = parsed[item]['temp']
174 return check_temperature(float(temperature_str) / 10.0, params,
175 "check_watchdog_sensors.%s" % item,
176 dev_unit=unit.lower())
179 check_info['watchdog_sensors.temp'] = {
180 'inventory_function' : inventory_watchdog_sensors_temp,
181 'check_function' : check_watchdog_sensors_temp,
182 'service_description' : 'Temperature %s ',
183 'has_perfdata' : True,
184 'group' : 'temperature',
188 # .--humidity------------------------------------------------------------.
189 # | _ _ _ _ _ |
190 # | | |__ _ _ _ __ ___ (_) __| (_) |_ _ _ |
191 # | | '_ \| | | | '_ ` _ \| |/ _` | | __| | | | |
192 # | | | | | |_| | | | | | | | (_| | | |_| |_| | |
193 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
194 # | |___/ |
195 # +----------------------------------------------------------------------+
196 # | |
197 # '----------------------------------------------------------------------'
199 factory_settings['watchdog_sensors_humidity_default_levels'] = {
200 'levels' : (50, 55),
201 'levels_lower' : (10, 15),
204 def inventory_watchdog_sensors_humidity(parsed):
205 for key in parsed:
206 yield ( key, {} )
209 def check_watchdog_sensors_humidity(item, params, parsed):
210 for key in parsed:
211 if key == item:
212 data = parsed[key]
214 humidity = int(data['humidity'])
215 warn, crit = params['levels']
216 warn_lower, crit_lower = params['levels_lower']
218 yield 0, "%.1f%%" % humidity, [ ('humidity', humidity, warn, crit) ]
220 if humidity >= crit:
221 yield 2, "warn/crit at %s/%s" % (warn, crit)
222 elif humidity <= crit_lower:
223 yield 2, "warn/crit at %s/%s" % (warn, crit)
224 elif humidity >= warn:
225 yield 1, "warn/crit below %s/%s" % (warn, crit)
226 elif humidity <= warn_lower:
227 yield 1, "warn/crit below %s/%s" % (warn, crit)
230 check_info['watchdog_sensors.humidity'] = {
231 'inventory_function' : inventory_watchdog_sensors_humidity,
232 'check_function' : check_watchdog_sensors_humidity,
233 'service_description' : 'Humidity %s',
234 'has_perfdata' : True,
235 'group' : 'humidity',
236 'default_levels_variable' : 'watchdog_sensors_humidity_default_levels',
240 # .--dew-----------------------------------------------------------------.
241 # | _ |
242 # | __| | _____ __ |
243 # | / _` |/ _ \ \ /\ / / |
244 # | | (_| | __/\ V V / |
245 # | \__,_|\___| \_/\_/ |
246 # | |
247 # +----------------------------------------------------------------------+
248 # | |
249 # '----------------------------------------------------------------------'
251 def inventory_watchdog_sensors_dew(parsed):
252 for key in parsed:
253 yield ( key, {} )
256 def check_watchdog_sensors_dew(item, params, parsed):
257 for key in parsed:
258 if key == item:
259 data = parsed[key]
261 dew = float(data['dew'][0])/10.0
262 unit = data['dew'][1]
263 if unit == "F":
264 dew = 5.0/9.0*(dew-32)
265 yield check_temperature(dew, params, "check_watchdog_sensors.%s" % item)
268 check_info['watchdog_sensors.dew'] = {
269 'inventory_function' : inventory_watchdog_sensors_dew,
270 'check_function' : check_watchdog_sensors_dew,
271 'service_description' : 'Dew point %s',
272 'has_perfdata' : True,
273 'group' : 'temperature',