Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / netapp_api_disk
blob351a154b552be7d9d757542075d39f47d15883fc
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 # Agent output:
28 # <<<netapp_api_disk:sep(9)>>>
31 def inventory_netapp_api_disk_summary(info):
32 return [(None, {})]
35 def check_netapp_api_disk_summary(_no_item, params, info):
36 disks_info = {}
37 for line in info:
38 disk_uid = line[0].split()[1]
39 disks_info.setdefault(disk_uid, {})
40 for entry in line[1:]:
41 tokens = entry.split(" ", 1)
42 disks_info[disk_uid][tokens[0]] = tokens[1]
44 # Convert legacy levels
45 if "broken_spare_ratio" in params:
46 params = {"failed_spare_ratio": params["broken_spare_ratio"]}
48 disks = disks_info
50 # The device can contain disks who belongs to another filer. We only check the ones
51 # belonging to this filer.
52 # TODO Do we need that?
53 my_disks = dict(
54 [disk for disk in disks.items() if not disk[1].get("raid-state") in ["remote", "partner"]])
56 disks_converted = []
57 for disk in my_disks.itervalues():
58 # Collection the disk identity
59 disk_info = "Serial: %s" % disk.get("serial-number")
60 if "physical-space" in disk:
61 disk_info += ", Size: %s" % get_bytes_human_readable(int(disk["physical-space"]))
62 disk['capacity'] = int(disk['physical-space'])
64 disk['identifier'] = disk_info
65 disk['type'] = False
66 raid_type = disk.get("raid-type")
67 raid_state = disk.get("raid-state")
68 if raid_state == "broken":
69 disk['state'] = 'failed'
70 elif disk.get("prefailed", "false") not in ["false", "None"]:
71 disk['state'] = 'prefailed'
72 if raid_type in ["parity", "dparity"]:
73 disk['type'] = 'parity'
74 elif raid_type == "data":
75 disk['type'] = 'data'
76 elif raid_state == "spare":
77 disk['state'] = "spare"
78 else:
79 disk['state'] = 'ok'
81 disks_converted.append(disk)
83 return check_filer_disks(disks_converted, params)
86 check_info["netapp_api_disk.summary"] = {
87 'check_function': check_netapp_api_disk_summary,
88 'inventory_function': inventory_netapp_api_disk_summary,
89 'service_description': 'NetApp Disks Summary',
90 'group': 'netapp_disks',
91 'has_perfdata': True,
92 'default_levels_variable': 'filer_disks_default_levels',
93 'includes': ['filerdisks.include'],