2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 # { "state" : "failed",
29 # "identifier" : "Enclosure: 2, Slot: 1, Type: SATA",
31 # "capacity" : 1000000000000,
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
):
41 state
['prefailed'] = []
49 total_capacity
+= disk
.get("capacity", 0)
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')
65 warn
, crit
= spare_disk_levels
66 if spare_disks
< crit
:
68 elif spare_disks
< warn
:
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
)
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"]:
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
]
104 state
[disk_state
])) / (len(state
[disk_state
]) + len(state
['spare'])) * 100
111 yield return_state
, "Too many %s disks (warn/crit at %.1f%%/%.1f%%)" % (disk_state
,