Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / hp_proliant.include
blobb3bf229e7f5b9522f319b7c142af9dd8028345aa
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 # ails. 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 hp_proliant_status_map = {
28 1: 'unknown',
29 2: 'ok',
30 3: 'degraded',
31 4: 'failed',
32 5: 'disabled',
35 hp_proliant_status2nagios_map = {
36 'unknown': 3,
37 'other': 3,
38 'ok': 0,
39 'degraded': 2,
40 'failed': 2,
41 'disabled': 1
44 hp_proliant_locale = {
45 1: "other",
46 2: "unknown",
47 3: "system",
48 4: "systemBoard",
49 5: "ioBoard",
50 6: "cpu",
51 7: "memory",
52 8: "storage",
53 9: "removableMedia",
54 10: "powerSupply",
55 11: "ambient",
56 12: "chassis",
57 13: "bridgeCard",
60 # .--da cntlr------------------------------------------------------------.
61 # | _ _ _ |
62 # | __| | __ _ ___ _ __ | |_| |_ __ |
63 # | / _` |/ _` | / __| '_ \| __| | '__| |
64 # | | (_| | (_| | | (__| | | | |_| | | |
65 # | \__,_|\__,_| \___|_| |_|\__|_|_| |
66 # | |
67 # '----------------------------------------------------------------------'
69 hp_proliant_da_cntlr_cond_map = {
70 '1': (3, 'other'),
71 '2': (0, 'ok'),
72 '3': (1, 'degraded'),
73 '4': (2, 'failed'),
76 hp_proliant_da_cntlr_role_map = {
77 '1': 'other',
78 '2': 'notDuplexed',
79 '3': 'active',
80 '4': 'backup',
83 hp_proliant_da_cntlr_state_map = {
84 '1': (3, 'other'),
85 '2': (0, 'ok'),
86 '3': (2, 'generalFailure'),
87 '4': (2, 'cableProblem'),
88 '5': (2, 'poweredOff'),
92 def inventory_hp_proliant_da_cntlr(info):
93 if info:
94 return [(line[0], None) for line in info]
97 def check_hp_proliant_da_cntlr(item, params, info):
98 for line in info:
99 index, model, slot, cond, role, b_status, b_cond, serial = line
100 if index == item:
101 sum_state = 0
102 output = []
104 for val, label, map_ in [(cond, 'Condition', hp_proliant_da_cntlr_cond_map),
105 (b_cond, 'Board-Condition', hp_proliant_da_cntlr_cond_map),
106 (b_status, 'Board-Status', hp_proliant_da_cntlr_state_map)]:
107 this_state = map_[val][0]
108 state_txt = ''
109 if this_state == 1:
110 state_txt = ' (!)'
111 elif this_state == 2:
112 state_txt = ' (!!)'
113 sum_state = max(sum_state, this_state)
114 output.append('%s: %s%s' % (label, map_[val][1], state_txt))
116 output.append('(Role: %s, Model: %s, Slot: %s, Serial: %s)' %
117 (hp_proliant_da_cntlr_role_map.get(role, 'unknown'), model, slot, serial))
119 return (sum_state, ', '.join(output))
120 return (3, "Controller not found in snmp data")
124 # .--cpu-----------------------------------------------------------------.
125 # | |
126 # | ___ _ __ _ _ |
127 # | / __| '_ \| | | | |
128 # | | (__| |_) | |_| | |
129 # | \___| .__/ \__,_| |
130 # | |_| |
131 # '----------------------------------------------------------------------'
133 hp_proliant_cpu_status_map = {1: "unknown", 2: "ok", 3: "degraded", 4: "failed", 5: "disabled"}
134 hp_proliant_cpu_status2nagios_map = {
135 'unknown': 3,
136 'ok': 0,
137 'degraded': 2,
138 'failed': 2,
139 'disabled': 1
143 def inventory_hp_proliant_cpu(info):
144 if len(info) > 0:
145 return [(line[0], None) for line in info]
148 def check_hp_proliant_cpu(item, params, info):
149 for line in info:
150 if line[0] == item:
151 index, slot, name, status = line
152 snmp_status = hp_proliant_cpu_status_map[int(status)]
153 status = hp_proliant_cpu_status2nagios_map[snmp_status]
155 return (status,
156 'CPU%s "%s" in slot %s is in state "%s"' % (index, name, slot, snmp_status))
157 return (3, "item not found in snmp data")
161 # .--fans----------------------------------------------------------------.
162 # | __ |
163 # | / _| __ _ _ __ ___ |
164 # | | |_ / _` | '_ \/ __| |
165 # | | _| (_| | | | \__ \ |
166 # | |_| \__,_|_| |_|___/ |
167 # | |
168 # '----------------------------------------------------------------------'
170 hp_proliant_fans_status_map = {1: 'other', 2: 'ok', 3: 'degraded', 4: 'failed'}
171 hp_proliant_status2nagios_map = {'other': 3, 'ok': 0, 'degraded': 2, 'failed': 2}
172 hp_proliant_present_map = {1: 'other', 2: 'absent', 3: 'present'}
173 hp_proliant_speed_map = {1: 'other', 2: 'normal', 3: 'high'}
174 hp_proliant_fans_locale = {
175 1: "other",
176 2: "unknown",
177 3: "system",
178 4: "systemBoard",
179 5: "ioBoard",
180 6: "cpu",
181 7: "memory",
182 8: "storage",
183 9: "removableMedia",
184 10: "powerSupply",
185 11: "ambient",
186 12: "chassis",
187 13: "bridgeCard",
191 def inventory_hp_proliant_fans(info):
192 if len(info) > 0:
193 items = []
194 for line in [line for line in info if line[2] == '3']:
195 label = 'other'
196 if int(line[1]) in hp_proliant_fans_locale:
197 label = hp_proliant_fans_locale[int(line[1])]
198 items.append(("%s (%s)" % (line[0], label), None))
199 return items
202 def check_hp_proliant_fans(item, params, info):
203 for line in info:
204 label = 'other'
205 if len(line) > 1 and int(line[1]) in hp_proliant_fans_locale:
206 label = hp_proliant_fans_locale[int(line[1])]
208 if "%s (%s)" % (line[0], label) == item:
209 index, _name, _present, speed, status, currentSpeed = line
210 snmp_status = hp_proliant_fans_status_map[int(status)]
211 status = hp_proliant_status2nagios_map[snmp_status]
213 detailOutput = ''
214 perfdata = []
215 if currentSpeed != '':
216 detailOutput = ', RPM: %s' % currentSpeed
217 perfdata = [('temp', int(currentSpeed))]
219 return (status, 'FAN Sensor %s "%s", Speed is %s, State is %s%s' %
220 (index, label, hp_proliant_speed_map[int(speed)], snmp_status, detailOutput),
221 perfdata)
222 return (3, "item not found in snmp data")
226 # .--mem-----------------------------------------------------------------.
227 # | |
228 # | _ __ ___ ___ _ __ ___ |
229 # | | '_ ` _ \ / _ \ '_ ` _ \ |
230 # | | | | | | | __/ | | | | | |
231 # | |_| |_| |_|\___|_| |_| |_| |
232 # | |
233 # '----------------------------------------------------------------------'
235 hp_proliant_mem_type_map = {
236 1: 'other',
237 2: 'board',
238 3: 'cpqSingleWidthModule',
239 4: 'cpqDoubleWidthModule',
240 5: 'simm',
241 6: 'pcmcia',
242 7: 'compaq-specific',
243 8: 'DIMM',
244 9: 'smallOutlineDimm',
245 10: 'RIMM',
246 11: 'SRIMM',
247 12: 'FB-DIMM',
248 13: 'DIMM DDR',
249 14: 'DIMM DDR2',
250 15: 'DIMM DDR3',
251 16: 'DIMM FBD2',
252 17: 'FB-DIMM DDR2',
253 18: 'FB-DIMM DDR3',
256 hp_proliant_mem_status_map = {
257 1: "other",
258 2: "notPresent",
259 3: "present",
260 4: "good",
261 5: "add",
262 6: "upgrade",
263 7: "missing",
264 8: "doesNotMatch",
265 9: "notSupported",
266 10: "badConfig",
267 11: "degraded",
268 12: "spare",
269 13: "partial",
272 hp_proliant_mem_status2nagios_map = {
273 'n/a': 3,
274 'other': 3,
275 'notPresent': 3,
276 'present': 1,
277 'good': 0,
278 'add': 1,
279 'upgrade': 1,
280 'missing': 2,
281 'doesNotMatch': 2,
282 'notSupported': 2,
283 'badConfig': 2,
284 'degraded': 2,
285 'spare': 0,
286 'partial': 1,
289 hp_proliant_mem_condition_status2nagios_map = {
290 'other': 3,
291 'ok': 0,
292 'degraded': 2,
293 'failed': 2,
294 'degradedModuleIndexUnknown': 3
297 hp_proliant_mem_condition_map = {
298 0: 'n/a',
299 1: 'other',
300 2: 'ok',
301 3: 'degraded',
302 4: 'degradedModuleIndexUnknown',
306 def inventory_hp_proliant_mem(info):
307 if len(info) > 0:
308 return [ (line[1], None) for line in info if line[2].isdigit() and \
309 int(line[2]) > 0 and int(line[4]) != 2 ]
312 def check_hp_proliant_mem(item, params, info):
313 for line in info:
314 if line[1] == item:
315 board_index, module_index, module_size, module_type, \
316 module_status, module_condition = line
318 module_size_mb = int(module_size) / 1024
320 type_ = 'n/a'
321 if int(module_type) in hp_proliant_mem_type_map:
322 type_ = hp_proliant_mem_type_map[int(module_type)]
324 snmp_status = 'n/a'
325 if int(module_status) in hp_proliant_mem_status_map:
326 snmp_status = hp_proliant_mem_status_map[int(module_status)]
328 detail_output = ', Status: %s ' % snmp_status
329 status = hp_proliant_mem_status2nagios_map[snmp_status]
330 if status == 0:
331 detail_output += ''
332 elif status == 1:
333 detail_output += '(!) '
334 elif status == 2:
335 detail_output += '(!!) '
336 else:
337 detail_output += '(?) '
339 condition = 'n/a'
340 if saveint(module_condition) in hp_proliant_mem_condition_map:
341 condition = hp_proliant_mem_condition_map[saveint(module_condition)]
342 condition_status = hp_proliant_mem_condition_status2nagios_map[condition]
344 detail_output += ', Condition: %s ' % condition
345 if condition_status == 0:
346 detail_output += ''
347 elif condition_status == 1:
348 detail_output += '(!) '
349 elif condition_status == 2:
350 detail_output += '(!!) '
351 else:
352 detail_output += '(?) '
353 if condition_status > status:
354 status = condition_status
356 return (status, 'Board: %s, Num: %s, Type: %s, Size: %s MB%s' %
357 (board_index, module_index, type_, module_size_mb, detail_output))
358 return (3, "item not found in snmp data")
362 # .--temperature---------------------------------------------------------.
363 # | _ _ |
364 # | | |_ ___ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
365 # | | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
366 # | | || __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
367 # | \__\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
368 # | |_| |
369 # '----------------------------------------------------------------------'
372 def format_hp_proliant_name(line):
373 return "%s (%s)" % (line[0], hp_proliant_locale[int(line[1])])
376 def inventory_hp_proliant_temp(info):
377 for line in info:
378 yield format_hp_proliant_name(line), {}
381 def check_hp_proliant_temp(item, params, info):
382 for line in info:
383 if format_hp_proliant_name(line) == item:
384 value, threshold, status = line[2:]
386 # This case means no threshold available and
387 # the devices' web interface displays "N/A"
388 if threshold == "-99" or threshold == "0":
389 devlevels = None
390 else:
391 threshold = float(threshold)
392 devlevels = (threshold, threshold)
394 snmp_status = hp_proliant_status_map[int(status)]
396 return check_temperature(
397 float(value),
398 params,
399 "hp_proliant_temp_%s" % item,
400 dev_levels=devlevels,
401 dev_status=hp_proliant_status2nagios_map[snmp_status],
402 dev_status_name="Unit: %s" % snmp_status)
403 return 3, "item not found in snmp data"