Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / ddn_s2a_faultsbasic
blob477240a3c9a2b170cd369e76d6708431cc091619
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.
27 # .--Parse function------------------------------------------------------.
28 # | ____ __ _ _ |
29 # | | _ \ __ _ _ __ ___ ___ / _|_ _ _ __ ___| |_(_) ___ _ __ |
30 # | | |_) / _` | '__/ __|/ _ \ | |_| | | | '_ \ / __| __| |/ _ \| '_ \ |
31 # | | __/ (_| | | \__ \ __/ | _| |_| | | | | (__| |_| | (_) | | | | |
32 # | |_| \__,_|_| |___/\___| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |
33 # | |
34 # '----------------------------------------------------------------------'
37 def parse_ddn_s2a_faultsbasic(info):
38 parsed = parse_ddn_s2a_api_response(info)
40 non_unique_keys = [
41 u"failed_avr_fan_ctrl_item",
42 u"failed_avr_pwr_sup_item",
43 u"failed_avr_temp_W_item",
44 u"failed_avr_temp_C_item",
45 u"failed_disk_item",
48 for key in parsed:
49 if key not in non_unique_keys:
50 parsed[key] = parsed[key][0]
52 return parsed
56 # .--Disks---------------------------------------------------------------.
57 # | ____ _ _ |
58 # | | _ \(_)___| | _____ |
59 # | | | | | / __| |/ / __| |
60 # | | |_| | \__ \ <\__ \ |
61 # | |____/|_|___/_|\_\___/ |
62 # | |
63 # '----------------------------------------------------------------------'
65 ddn_s2a_faultsbasic_disks_default_levels = (1, 2)
68 def inventory_ddn_s2a_faultsbasic_disks(parsed):
69 if u"disk_failures_count" in parsed:
70 return [(None, "ddn_s2a_faultsbasic_disks_default_levels")]
73 def check_ddn_s2a_faultsbasic_disks(_no_item, params, parsed):
74 warn, crit = params
75 num_failures = int(parsed[u"disk_failures_count"])
77 if num_failures >= crit:
78 status = 2
79 elif num_failures >= warn:
80 status = 1
81 else:
82 status = 0
84 infotext = "%d failures detected" % num_failures
85 if parsed.get(u"failed_disk_item"):
86 infotext += ". Failed disks: " + ", ".join(parsed[u"failed_disk_item"])
88 return status, infotext
91 check_info["ddn_s2a_faultsbasic.disks"] = {
92 "inventory_function": inventory_ddn_s2a_faultsbasic_disks,
93 "check_function": check_ddn_s2a_faultsbasic_disks,
94 "service_description": "DDN S2A Disks",
95 "group": "disk_failures",
99 # .--Temperature---------------------------------------------------------.
100 # | _____ _ |
101 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
102 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
103 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
104 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
105 # | |_| |
106 # '----------------------------------------------------------------------'
109 def inventory_ddn_s2a_faultsbasic_temp(parsed):
110 if u"avr_temp_W_failures_count" in parsed:
111 return [(None, None)]
114 def check_ddn_s2a_faultsbasic_temp(_no_item, _no_params, parsed):
115 crit_failures = int(parsed[u"avr_temp_C_failures_count"])
116 warn_failures = int(parsed[u"avr_temp_W_failures_count"])
118 if crit_failures:
119 status = 2
120 elif warn_failures:
121 status = 1
122 else:
123 status = 0
125 infotext = "%d critical failures, %d warnings" % (crit_failures, warn_failures)
127 crit_failures_items = parsed.get(u"failed_avr_temp_C_item")
128 if crit_failures_items:
129 infotext += ". Critical failures: " + ", ".join(crit_failures_items)
131 warn_failures_items = parsed.get(u"failed_avr_temp_W_item")
132 if warn_failures_items:
133 infotext += ". Warnings: " + ", ".join(warn_failures_items)
135 return status, infotext
138 check_info["ddn_s2a_faultsbasic.temp"] = {
139 "inventory_function": inventory_ddn_s2a_faultsbasic_temp,
140 "check_function": check_ddn_s2a_faultsbasic_temp,
141 "service_description": "DDN S2A Temperature",
145 # .--Power supplies------------------------------------------------------.
146 # | ____ _ _ |
147 # | | _ \ _____ _____ _ __ ___ _ _ _ __ _ __ | (_) ___ ___ |
148 # | | |_) / _ \ \ /\ / / _ \ '__| / __| | | | '_ \| '_ \| | |/ _ \/ __| |
149 # | | __/ (_) \ V V / __/ | \__ \ |_| | |_) | |_) | | | __/\__ \ |
150 # | |_| \___/ \_/\_/ \___|_| |___/\__,_| .__/| .__/|_|_|\___||___/ |
151 # | |_| |_| |
152 # '----------------------------------------------------------------------'
155 def inventory_ddn_s2a_faultsbasic_ps(parsed):
156 if u"avr_pwr_sup_failures_count" in parsed:
157 return [(None, None)]
160 def check_ddn_s2a_faultsbasic_ps(_no_item, _no_params, parsed):
161 ps_failures = int(parsed[u"avr_pwr_sup_failures_count"])
162 if ps_failures > 0:
163 infotext = "Power supply failure: "
164 infotext += ", ".join(parsed[u"failed_avr_pwr_sup_item"])
165 return 2, infotext
166 return 0, "No power supply failures detected"
169 check_info["ddn_s2a_faultsbasic.ps"] = {
170 "inventory_function": inventory_ddn_s2a_faultsbasic_ps,
171 "check_function": check_ddn_s2a_faultsbasic_ps,
172 "service_description": "DDN S2A Power Supplies",
176 # .--Fans----------------------------------------------------------------.
177 # | _____ |
178 # | | ___|_ _ _ __ ___ |
179 # | | |_ / _` | '_ \/ __| |
180 # | | _| (_| | | | \__ \ |
181 # | |_| \__,_|_| |_|___/ |
182 # | |
183 # '----------------------------------------------------------------------'
185 ddn_s2a_faultsbasic_fans_default_levels = (1, 2)
188 def inventory_ddn_s2a_faultsbasic_fans(parsed):
189 if u'avr_fan_ctrl_failures_count' in parsed:
190 return [(None, "ddn_s2a_faultsbasic_fans_default_levels")]
193 def check_ddn_s2a_faultsbasic_fans(_no_item, params, parsed):
194 fan_failures = int(parsed[u"avr_fan_ctrl_failures_count"])
195 warn, crit = params
197 if fan_failures >= crit:
198 status = 2
199 elif fan_failures >= warn:
200 status = 1
201 else:
202 status = 0
204 if fan_failures:
205 infotext = "%d fan failures detected: " % fan_failures
206 infotext += ", ".join(parsed[u"failed_avr_fan_ctrl_item"])
207 else:
208 infotext = "No fan failures detected"
210 return status, infotext
213 check_info["ddn_s2a_faultsbasic.fans"] = {
214 "inventory_function": inventory_ddn_s2a_faultsbasic_fans,
215 "check_function": check_ddn_s2a_faultsbasic_fans,
216 "service_description": "DDN S2A Fans",
217 "group": "fan_failures",
221 # .--Ping fault----------------------------------------------------------.
222 # | ____ _ __ _ _ |
223 # | | _ \(_)_ __ __ _ / _| __ _ _ _| | |_ |
224 # | | |_) | | '_ \ / _` | | |_ / _` | | | | | __| |
225 # | | __/| | | | | (_| | | _| (_| | |_| | | |_ |
226 # | |_| |_|_| |_|\__, | |_| \__,_|\__,_|_|\__| |
227 # | |___/ |
228 # '----------------------------------------------------------------------'
231 def inventory_ddn_s2a_faultsbasic_pingfault(parsed):
232 if u"ping_fault" in parsed:
233 return [(None, None)]
236 def check_ddn_s2a_faultsbasic_pingfault(_no_item, _no_params, parsed):
237 if parsed[u"ping_fault"] == u"FALSE":
238 return 0, "No fault detected"
239 elif u"ping_fault_tag" in parsed:
240 return 1, "Ping Fault: " + parsed[u"ping_fault_tag"]
241 elif parsed[u"ping_fault"] == u"TRUE":
242 return 1, "Ping Fault"
245 check_info["ddn_s2a_faultsbasic.pingfault"] = {
246 "inventory_function": inventory_ddn_s2a_faultsbasic_pingfault,
247 "check_function": check_ddn_s2a_faultsbasic_pingfault,
248 "service_description": "DDN S2A Ping Fault Status",
252 # .--Boot status---------------------------------------------------------.
253 # | ____ _ _ _ |
254 # | | __ ) ___ ___ | |_ ___| |_ __ _| |_ _ _ ___ |
255 # | | _ \ / _ \ / _ \| __| / __| __/ _` | __| | | / __| |
256 # | | |_) | (_) | (_) | |_ \__ \ || (_| | |_| |_| \__ \ |
257 # | |____/ \___/ \___/ \__| |___/\__\__,_|\__|\__,_|___/ |
258 # | |
259 # '----------------------------------------------------------------------'
262 def inventory_ddn_s2a_faultsbasic_bootstatus(parsed):
263 if u"system_fully_booted" in parsed:
264 return [(None, None)]
267 def check_ddn_s2a_faultsbasic_bootstatus(_no_item, _no_params, parsed):
268 if parsed[u"system_fully_booted"] == u"TRUE":
269 return 0, "System fully booted"
270 return 1, "System not fully booted"
273 check_info["ddn_s2a_faultsbasic.bootstatus"] = {
274 "inventory_function": inventory_ddn_s2a_faultsbasic_bootstatus,
275 "check_function": check_ddn_s2a_faultsbasic_bootstatus,
276 "service_description": "DDN S2A Boot Status",
280 # .--Cache coherency-----------------------------------------------------.
281 # | ____ _ |
282 # | / ___|__ _ ___| |__ ___ |
283 # | | | / _` |/ __| '_ \ / _ \ |
284 # | | |__| (_| | (__| | | | __/ |
285 # | \____\__,_|\___|_| |_|\___| |
286 # | |
287 # | _ |
288 # | ___ ___ | |__ ___ _ __ ___ _ __ ___ _ _ |
289 # | / __/ _ \| '_ \ / _ \ '__/ _ \ '_ \ / __| | | | |
290 # | | (_| (_) | | | | __/ | | __/ | | | (__| |_| | |
291 # | \___\___/|_| |_|\___|_| \___|_| |_|\___|\__, | |
292 # | |___/ |
293 # '----------------------------------------------------------------------'
296 def inventory_ddn_s2a_faultsbasic_cachecoh(parsed):
297 if u"hstd1_online_failure" in parsed:
298 return [(None, None)]
301 def check_ddn_s2a_faultsbasic_cachecoh(_no_item, _no_params, parsed):
302 cache_coherency = parsed.get(u"cache_coherency")
303 if cache_coherency:
305 cache_coherency_states = {
306 u"established": 0,
307 u"not enabled": 1,
308 u"not established": 2,
311 return cache_coherency_states.get(cache_coherency, 3), "Cache coherency: " + cache_coherency
313 # The value is only supplied in case of a failure. A missing value is an implicit OK
314 # according to the API documentation.
315 return 0, "Cache coherency: established"
318 check_info["ddn_s2a_faultsbasic.cachecoh"] = {
319 "inventory_function": inventory_ddn_s2a_faultsbasic_cachecoh,
320 "check_function": check_ddn_s2a_faultsbasic_cachecoh,
321 "service_description": "DDN S2A Cache Coherency",
325 # .--Dual communication--------------------------------------------------.
326 # | ____ _ |
327 # | | _ \ _ _ __ _| | ___ ___ _ __ ___ _ __ ___ |
328 # | | | | | | | |/ _` | | / __/ _ \| '_ ` _ \| '_ ` _ \ |
329 # | | |_| | |_| | (_| | | | (_| (_) | | | | | | | | | | | |
330 # | |____/ \__,_|\__,_|_| \___\___/|_| |_| |_|_| |_| |_| |
331 # | |
332 # '----------------------------------------------------------------------'
335 def inventory_ddn_s2a_faultsbasic_dualcomm(parsed):
336 if u"hstd1_online_failure" in parsed:
337 return [(None, None)]
340 def check_ddn_s2a_faultsbasic_dualcomm(_no_item, _no_params, parsed):
341 dual_comm_established = parsed.get(u"dual_comm_established")
343 # This value is only transmitted by the API in case of a failure.
344 # Therefore, a non-existant value is an implicit "TRUE" here.
345 if dual_comm_established == "TRUE" or dual_comm_established is None:
346 return 0, "Dual comm established"
347 elif dual_comm_established == "FALSE":
348 return 2, "Dual comm not established"
351 check_info["ddn_s2a_faultsbasic.dualcomm"] = {
352 "inventory_function": inventory_ddn_s2a_faultsbasic_dualcomm,
353 "check_function": check_ddn_s2a_faultsbasic_dualcomm,
354 "service_description": "DDN S2A Dual Communication",
358 # .--Ethernet------------------------------------------------------------.
359 # | _____ _ _ _ |
360 # | | ____| |_| |__ ___ _ __ _ __ ___| |_ |
361 # | | _| | __| '_ \ / _ \ '__| '_ \ / _ \ __| |
362 # | | |___| |_| | | | __/ | | | | | __/ |_ |
363 # | |_____|\__|_| |_|\___|_| |_| |_|\___|\__| |
364 # | |
365 # '----------------------------------------------------------------------'
368 def inventory_ddn_s2a_faultsbasic_ethernet(parsed):
369 if u"hstd1_online_failure" in parsed:
370 return [(None, None)]
373 def check_ddn_s2a_faultsbasic_ethernet(_no_item, _no_params, parsed):
374 ethernet_working = parsed.get(u"ethernet_working")
376 # This value is only transmitted by the API in case of a failure.
377 # Therefore, a non-existant value is an implicit "established" here.
378 if ethernet_working == u"established" or ethernet_working is None:
379 yield 0, "Ethernet connection established"
380 else:
381 yield 1, "Ethernet " + ethernet_working
384 check_info["ddn_s2a_faultsbasic.ethernet"] = {
385 "inventory_function": inventory_ddn_s2a_faultsbasic_ethernet,
386 "check_function": check_ddn_s2a_faultsbasic_ethernet,
387 "service_description": "DDN S2A Ethernet",
391 # .--Unit status---------------------------------------------------------.
392 # | _ _ _ _ _ _ |
393 # | | | | |_ __ (_) |_ ___| |_ __ _| |_ _ _ ___ |
394 # | | | | | '_ \| | __| / __| __/ _` | __| | | / __| |
395 # | | |_| | | | | | |_ \__ \ || (_| | |_| |_| \__ \ |
396 # | \___/|_| |_|_|\__| |___/\__\__,_|\__|\__,_|___/ |
397 # | |
398 # '----------------------------------------------------------------------'
401 def inventory_ddn_s2a_faultsbasic(parsed):
402 for index in ["1", "2"]:
403 if u"hstd%s_online_failure" % index in parsed:
404 yield index, None
407 def check_ddn_s2a_faultsbasic(item, _no_params, parsed):
408 online_failure = parsed[u"hstd%s_online_failure" % item]
409 online_status = parsed.get(u"hstd%s_online_status" % item, u"")
411 if online_failure == "TRUE":
412 if online_status.lower() in ["restarting", "not installed"]:
413 yield 1, "Unit " + online_status
414 else:
415 yield 2, "Failure detected - Online status: " + online_status
416 elif online_failure == "FALSE":
417 yield 0, "No failure detected"
420 check_info['ddn_s2a_faultsbasic'] = {
421 'parse_function': parse_ddn_s2a_faultsbasic,
422 "inventory_function": inventory_ddn_s2a_faultsbasic,
423 "check_function": check_ddn_s2a_faultsbasic,
424 "service_description": "DDN S2A Unit %s",
425 'includes': ["ddn_s2a.include"],