Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / filerdisks.include
blobabe241f3d1de1e8bdc0dcaab72ba9bce40edee17
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 # disks = [
28 # { "state" : "failed",
29 # "identifier" : "Enclosure: 2, Slot: 1, Type: SATA",
30 # "type" : "parity",
31 # "capacity" : 1000000000000,
32 # }
33 factory_settings["filer_disks_default_levels"] = {
34 "failed_spare_ratio": (1.0, 50.0),
35 "offline_spare_ratio": (1.0, 50.0),
39 def check_filer_disks(disks, params):
40 state = {}
41 state['prefailed'] = []
42 state['failed'] = []
43 state['offline'] = []
44 state['spare'] = []
46 total_capacity = 0
48 for disk in disks:
49 total_capacity += disk.get("capacity", 0)
50 for what in state:
51 if disk['state'] == what:
52 state[what].append(disk)
54 yield 0, "Total raw capacity: %s" % get_bytes_human_readable(total_capacity), [
55 ("total_disk_capacity", total_capacity)
57 # TODO: Is a prefailed disk unavailable?
58 unavail_disks = len(state['prefailed']) + len(state['failed']) + len(state['offline'])
59 yield 0, "Total disks: %d" % (len(disks) - unavail_disks), [("total_disks", len(disks))]
61 spare_disks = len(state['spare'])
62 spare_state, spare_infotext = 0, "Spare disks: %d" % spare_disks
63 spare_disk_levels = params.get('number_of_spare_disks')
64 if spare_disk_levels:
65 warn, crit = spare_disk_levels
66 if spare_disks < crit:
67 spare_state = 2
68 elif spare_disks < warn:
69 spare_state = 1
71 if spare_state:
72 spare_infotext += " (warn/crit below %s/%s)" % (warn, crit)
73 yield spare_state, spare_infotext, [("spare_disks", spare_disks)]
75 parity_disks = [disk for disk in disks if disk['type'] == 'parity']
76 prefailed_parity = [disk for disk in parity_disks if disk['state'] == 'prefailed']
77 if len(parity_disks) > 0:
78 yield 0, "Parity disks: %d (%d prefailed)" % (len(parity_disks), len(prefailed_parity))
80 yield 0, "Failed disks: %d" % unavail_disks, [("failed_disks", unavail_disks)]
82 for name, disk_type in [("Data", "data"), ("Parity", "parity")]:
83 total_disks = [disk for disk in disks if disk['type'] == disk_type]
84 prefailed_disks = [disk for disk in total_disks if disk['state'] == 'prefailed']
85 if len(total_disks) > 0:
86 info_text = "%s disks" % len(total_disks)
87 if len(prefailed_disks) > 0:
88 info_text += " (%d prefailed)" % (prefailed_disks)
89 yield 0, info_text
90 info_texts = []
91 for disk in prefailed_disks:
92 info_texts.append(disk['identifier'])
93 if len(info_texts) > 0:
94 yield 0, "%s Disk Details: %s" % (name, " / ".join(info_texts))
96 for disk_state in ["failed", "offline"]:
97 info_texts = []
98 for disk in state[disk_state]:
99 info_texts.append(disk['identifier'])
100 if len(info_texts) > 0:
101 yield 0, "%s Disk Details: %s" % (disk_state, " / ".join(info_texts))
102 warn, crit = params["%s_spare_ratio" % disk_state]
103 ratio = float(len(
104 state[disk_state])) / (len(state[disk_state]) + len(state['spare'])) * 100
105 return_state = False
106 if ratio >= crit:
107 return_state = 2
108 elif ratio >= warn:
109 return_state = 1
110 if return_state:
111 yield return_state, "Too many %s disks (warn/crit at %.1f%%/%.1f%%)" % (disk_state,
112 warn, crit)