Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / emcvnx_raidgroups
blobe6bfa0cc863d56531e819dcbda02ec51d7ac88a6
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 # Example output from agent:
28 # <<<emcvnx_raidgroups>>>
31 # Server IP Address: 172.16.8.82
32 # Agent Rev: 7.32.27 (0.14)
35 # All RAID Groups Information
36 # ----------------------------
39 # RaidGroup ID: 0
40 # RaidGroup Type: r5
41 # RaidGroup State: Explicit_Remove
42 # Valid_luns
43 # List of disks: Bus 0 Enclosure 0 Disk 0
44 # Bus 0 Enclosure 0 Disk 1
45 # Bus 0 Enclosure 0 Disk 2
46 # Bus 0 Enclosure 0 Disk 3
47 # List of luns: 4
48 # Max Number of disks: 16
49 # Max Number of luns: 256
50 # Raw Capacity (Blocks): 702504960
51 # Logical Capacity (Blocks): 526878720
52 # Free Capacity (Blocks,non-contiguous): 0
53 # Free contiguous group of unbound segments: 0
54 # Defrag/Expand priority: Medium
55 # Percent defragmented: 100
56 # Percent expanded: N/A
57 # Disk expanding onto: N/A
58 # Lun Expansion enabled: NO
59 # Legal RAID types: r5
61 # RaidGroup ID: 124
62 # RaidGroup Type: hot_spare
63 # [...]
65 # Parse agent output into a dict of the form:
66 # (where the RAID Group ID is used as key)
67 # parsed = {'0': {'luns': '4'},
68 # '1': {'luns': '0,1'},
69 # '124': {'luns': '4089'},
70 # '2': {'luns': '2,3'}}
73 def parse_emcvnx_raidgroups(info):
74 parsed = {}
75 append = False
76 for line in info:
77 if len(line) > 2 and line[0] == "RaidGroup" and line[1] == "ID:":
78 rg = {}
79 parsed[line[2]] = rg
80 elif len(line) > 3 and line[0] == "List" and line[1] == "of" and line[2] == "luns:":
81 rg["luns"] = ",".join(line[3:])
82 elif len(line) > 8 and line[0] == "List" and line[1] == "of" and line[2] == "disks:":
83 disks = []
84 disk = line[4] + "/" + line[6] + " Disk " + line[8]
85 disks.append(disk)
86 rg["disks"] = disks
87 append = True
88 elif append is True and len(
89 line) > 5 and line[0] == "Bus" and line[2] == "Enclosure" and line[4] == "Disk":
90 disk = line[1] + "/" + line[3] + " Disk " + line[5]
91 disks.append(disk)
92 elif append is True:
93 append = False
94 elif len(
95 line) > 3 and line[0] == "Raw" and line[1] == "Capacity" and line[2] == "(Blocks):":
96 rg["capacity_raw_blocks"] = line[3]
97 elif len(line
98 ) > 3 and line[0] == "Logical" and line[1] == "Capacity" and line[2] == "(Blocks):":
99 rg["capacity_logical_blocks"] = line[3]
100 elif len(line) > 3 and line[0] == "Free" and line[1] == "Capacity" and line[
101 2] == "(Blocks,non-contiguous):":
102 rg["capacity_free_total_blocks"] = line[3]
103 elif len(line) > 6 and line[0] == "Free" and line[1] == "contiguous" and line[
104 4] == "unbound" and line[5] == "segments:":
105 rg["capacity_free_contiguous_blocks"] = line[6]
106 return parsed
109 def inventory_emcvnx_raidgroups(info):
110 parsed = parse_emcvnx_raidgroups(info)
111 inventory = []
112 for rg in parsed:
113 inventory.append((rg, None))
114 return inventory
117 # .--list of LUNs--------------------------------------------------------.
118 # | _ _ _ __ _ _ _ _ _ |
119 # | | (_)___| |_ ___ / _| | | | | | | \ | |___ |
120 # | | | / __| __| / _ \| |_ | | | | | | \| / __| |
121 # | | | \__ \ |_ | (_) | _| | |__| |_| | |\ \__ \ |
122 # | |_|_|___/\__| \___/|_| |_____\___/|_| \_|___/ |
123 # | |
124 # '----------------------------------------------------------------------'
127 def check_emcvnx_raidgroups_list_luns(item, _no_params, info):
128 parsed = parse_emcvnx_raidgroups(info)
129 if item not in parsed:
130 return 3, "RAID Group %s not found in agent output" % item
131 return 0, "List of LUNs: " + parsed[item]["luns"]
134 check_info['emcvnx_raidgroups.list_luns'] = {
135 "inventory_function": inventory_emcvnx_raidgroups,
136 "check_function": check_emcvnx_raidgroups_list_luns,
137 "service_description": "RAID Group %s LUNs"
141 # .--list of disks-------------------------------------------------------.
142 # | _ _ _ __ _ _ _ |
143 # | | (_)___| |_ ___ / _| __| (_)___| | _____ |
144 # | | | / __| __| / _ \| |_ / _` | / __| |/ / __| |
145 # | | | \__ \ |_ | (_) | _| | (_| | \__ \ <\__ \ |
146 # | |_|_|___/\__| \___/|_| \__,_|_|___/_|\_\___/ |
147 # | |
148 # '----------------------------------------------------------------------'
151 def check_emcvnx_raidgroups_list_disks(item, _no_params, info):
152 parsed = parse_emcvnx_raidgroups(info)
153 if item not in parsed:
154 return 3, "RAID Group %s not found in agent output" % item
156 message = ""
157 enc = ""
158 for disk in sorted(parsed[item]["disks"]):
159 if message != "":
160 message += ", "
161 enc_id, disk_id = disk.split(' ', 1)
162 if enc_id == enc:
163 message += disk_id
164 else:
165 message += "Enclosure " + enc_id + " " + disk_id
166 enc = enc_id
168 return 0, "List of Disks: " + message
171 check_info['emcvnx_raidgroups.list_disks'] = {
172 "inventory_function": inventory_emcvnx_raidgroups,
173 "check_function": check_emcvnx_raidgroups_list_disks,
174 "service_description": "RAID Group %s Disks"
178 # .--capacity------------------------------------------------------------.
179 # | _ _ |
180 # | ___ __ _ _ __ __ _ ___(_) |_ _ _ |
181 # | / __/ _` | '_ \ / _` |/ __| | __| | | | |
182 # | | (_| (_| | |_) | (_| | (__| | |_| |_| | |
183 # | \___\__,_| .__/ \__,_|\___|_|\__|\__, | |
184 # | |_| |___/ |
185 # '----------------------------------------------------------------------'
188 def inventory_emcvnx_raidgroups_capacity(info):
189 parsed = parse_emcvnx_raidgroups(info)
190 inventory = []
191 for rg in parsed:
192 inventory.append((rg, {}))
193 return inventory
196 def check_emcvnx_raidgroups_capacity(item, params, info):
197 parsed = parse_emcvnx_raidgroups(info)
198 if item not in parsed:
199 return 3, "RAID Group %s not found in agent output" % item
201 fslist = []
202 # Blocksize in Bytes, seems to be fix
203 # (is not listed in the naviseccli output anywhere)
204 blocksize = 512
205 size_mb = int(parsed[item]["capacity_logical_blocks"]) * blocksize / 1048576.0
206 avail_mb = int(parsed[item]["capacity_free_total_blocks"]) * blocksize / 1048576.0
207 fslist.append((item, size_mb, avail_mb, 0))
209 # variable name in perfdata is not allowed to be just a number
210 # especially 0 does not work, so prefix it generally with "rg"
211 rc, message, perfdata = df_check_filesystem_list(item, params, fslist)
212 # note: on very first run perfdata is empty
213 if len(perfdata) > 0:
214 perfdata[0] = ("rg" + perfdata[0][0], perfdata[0][1], perfdata[0][2], perfdata[0][3],
215 perfdata[0][4], perfdata[0][5])
216 return rc, message, perfdata
219 check_info['emcvnx_raidgroups.capacity'] = {
220 "inventory_function": inventory_emcvnx_raidgroups_capacity,
221 "check_function": check_emcvnx_raidgroups_capacity,
222 "service_description": "RAID Group %s Capacity",
223 "has_perfdata": True,
224 "group": "filesystem",
225 "includes": ["size_trend.include", "df.include"],
226 "default_levels_variable": "filesystem_default_levels",
230 # .--capacity contiguous-------------------------------------------------.
231 # | _ _ |
232 # | ___ ___ _ __ | |_(_) __ _ _ _ ___ _ _ ___ |
233 # | / __/ _ \| '_ \| __| |/ _` | | | |/ _ \| | | / __| |
234 # | | (_| (_) | | | | |_| | (_| | |_| | (_) | |_| \__ \ |
235 # | \___\___/|_| |_|\__|_|\__, |\__,_|\___/ \__,_|___/ |
236 # | |___/ |
237 # '----------------------------------------------------------------------'
240 def inventory_emcvnx_raidgroups_capacity_contiguous(info):
241 parsed = parse_emcvnx_raidgroups(info)
242 inventory = []
243 for rg in parsed:
244 inventory.append((rg, {}))
245 return inventory
248 def check_emcvnx_raidgroups_capacity_contiguous(item, params, info):
249 parsed = parse_emcvnx_raidgroups(info)
250 if item not in parsed:
251 return 3, "RAID Group %s not found in agent output" % item
253 fslist = []
254 # Blocksize in Bytes, seems to be fix
255 # (is not listed in the naviseccli output anywhere)
256 blocksize = 512
257 size_mb = int(parsed[item]["capacity_logical_blocks"]) * blocksize / 1048576.0
258 avail_mb = int(parsed[item]["capacity_free_contiguous_blocks"]) * blocksize / 1048576.0
259 fslist.append((item, size_mb, avail_mb, 0))
261 # variable name in perfdata is not allowed to be just a number
262 # especially 0 does not work, so prefix it generally with "rg"
263 rc, message, perfdata = df_check_filesystem_list(item, params, fslist)
264 perfdata[0] = ("rg" + perfdata[0][0], perfdata[0][1], perfdata[0][2], perfdata[0][3],
265 perfdata[0][4], perfdata[0][5])
266 return rc, message, perfdata
269 check_info['emcvnx_raidgroups.capacity_contiguous'] = {
270 "inventory_function": inventory_emcvnx_raidgroups_capacity_contiguous,
271 "check_function": check_emcvnx_raidgroups_capacity_contiguous,
272 "service_description": "RAID Group %s Capacity Contiguous",
273 "has_perfdata": True,
274 "group": "filesystem",
275 "includes": ["size_trend.include", "df.include"],
276 "default_levels_variable": "filesystem_default_levels",