Cleanup config.nodes_of
[check_mk.git] / checks / fjdarye.include
blobdc94c54bef434100cab396559e2de90bf707e500
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 # check_mk plugin to monitor Fujitsu storage systems supporting FJDARY-E60.MIB or FJDARY-E100.MIB
28 # Copyright (c) 2012 FuH Entwicklungsgesellschaft mbH, Umkirch, Germany. All rights reserved.
29 # Author: Philipp Hoefflin, 2012, hoefflin+cmk@fuh-e.de
31 # generic data structure widely used in the FJDARY-Mibs:
32 # <oid>
33 # <oid>.1: Index
34 # <oid>.3: Status
35 # the latter can be one of the following:
36 fjdarye_item_status = {
37 1: 'normal',
38 2: 'alarm',
39 3: 'warning',
40 4: 'invalid',
41 5: 'maintenance',
42 6: 'undefined'
46 # generic inventory item - status other than 'invalid' is ok for inventory
47 def inventory_fjdarye_item(info):
48 return [(int(index), '', None) for index, status in info if int(status) != 4]
51 # generic check_function returning the nagios-code and the status text
52 def check_fjdarye_item(index, _no_param, info):
53 for line in info:
54 if int(line[0]) == index:
55 status = int(line[1])
56 if status == 1:
57 code = 0
58 elif status == 3:
59 code = 1
60 else:
61 code = 2
62 return (code, "Status is %s" % (fjdarye_item_status[status]))
63 return (3, 'No status for item %d present' % index)
67 # .--single disks--------------------------------------------------------.
68 # | _ _ _ _ _ |
69 # | ___(_)_ __ __ _| | ___ __| (_)___| | _____ |
70 # | / __| | '_ \ / _` | |/ _ \ / _` | / __| |/ / __| |
71 # | \__ \ | | | | (_| | | __/ | (_| | \__ \ <\__ \ |
72 # | |___/_|_| |_|\__, |_|\___| \__,_|_|___/_|\_\___/ |
73 # | |___/ |
74 # +----------------------------------------------------------------------+
75 # | disks main check |
76 # '----------------------------------------------------------------------'
78 fjdarye_disks_status = {
79 "1": (0, 'available'),
80 "2": (2, 'broken'),
81 "3": (1, 'notavailable'),
82 "4": (1, 'notsupported'),
83 "5": (0, 'present'),
84 "6": (1, 'readying'),
85 "7": (1, 'recovering'),
86 "64": (1, 'partbroken'),
87 "65": (1, 'spare'),
88 "66": (0, 'formatting'),
89 "67": (0, 'unformated'),
90 "68": (1, 'notexist'),
91 "69": (1, 'copying'),
95 def parse_fjdarye_disks(info):
96 parsed = {}
97 for idx, disk_state in info:
98 state, state_readable = fjdarye_disks_status.get(disk_state,
99 (3, "unknown[%s]" % disk_state))
100 parsed.setdefault(
101 int(idx), {
102 "state": state,
103 "state_readable": state_readable,
104 "state_disk": disk_state,
106 return parsed
109 def inventory_fjdarye_disks(parsed):
110 return [(idx, repr(attrs["state_readable"]))
111 for idx, attrs in parsed.items()
112 if attrs["state_disk"] != "3"]
115 def check_fjdarye_disks(item, params, parsed):
116 if isinstance(params, str):
117 params = {"expected_state": params}
119 if item in parsed:
120 attrs = parsed[item]
121 state_readable = attrs["state_readable"]
122 expected_state = params.get("expected_state")
123 check_state = 0
124 infotext = "Status: %s" % state_readable
125 if params.get("use_device_states"):
126 check_state = attrs["state"]
127 if check_state > 0:
128 infotext += " (use device states)"
129 elif expected_state and state_readable != expected_state:
130 check_state = 2
131 infotext += " (expected: %s)" % expected_state
132 return check_state, infotext
134 return 3, "No status for disk number %s present" % item
138 # .--summary disks-------------------------------------------------------.
139 # | |
140 # | ___ _ _ _ __ ___ _ __ ___ __ _ _ __ _ _ |
141 # | / __| | | | '_ ` _ \| '_ ` _ \ / _` | '__| | | | |
142 # | \__ \ |_| | | | | | | | | | | | (_| | | | |_| | |
143 # | |___/\__,_|_| |_| |_|_| |_| |_|\__,_|_| \__, | |
144 # | |___/ |
145 # | _ _ _ |
146 # | __| (_)___| | _____ |
147 # | / _` | / __| |/ / __| |
148 # | | (_| | \__ \ <\__ \ |
149 # | \__,_|_|___/_|\_\___/ |
150 # | |
151 # '----------------------------------------------------------------------'
154 def fjdarye_disks_summary(parsed):
155 states = {}
156 for attrs in parsed.itervalues():
157 if attrs["state_disk"] != "3":
158 states.setdefault(attrs["state_readable"], 0)
159 states[attrs["state_readable"]] += 1
160 return states
163 def inventory_fjdarye_disks_summary(parsed):
164 current_state = fjdarye_disks_summary(parsed)
165 if len(current_state) > 0:
166 return [(None, current_state)]
169 def fjdarye_disks_printstates(states):
170 return ", ".join(["%s: %s" % (s.title(), c) for s, c in states.items()])
173 def check_fjdarye_disks_summary(index, params, parsed):
174 map_states = {
175 'available': 0,
176 'broken': 2,
177 'notavailable': 1,
178 'notsupported': 1,
179 'present': 0,
180 'readying': 1,
181 'recovering': 1,
182 'partbroken': 1,
183 'spare': 1,
184 'formatting': 0,
185 'unformated': 0,
186 'notexist': 1,
187 'copying': 1,
190 use_devices_states = False
191 if "use_device_states" in params:
192 use_devices_states = params["use_device_states"]
193 del params["use_device_states"]
194 expected_state = params
196 current_state = fjdarye_disks_summary(parsed)
197 infotext = fjdarye_disks_printstates(current_state)
198 if use_devices_states:
199 state = 0
200 for state_readable in current_state:
201 state = max(state, map_states.get(state_readable, 3))
202 infotext += " (ignore expected state)"
203 return state, infotext
205 if current_state == expected_state:
206 return 0, infotext
208 result = 1
209 for ename, ecount in expected_state.items():
210 if current_state.get(ename, 0) < ecount:
211 result = 2
212 break
214 return result, "%s (expected: %s)" % (infotext, fjdarye_disks_printstates(expected_state))
218 # .--rluns---------------------------------------------------------------.
219 # | _ |
220 # | _ __| |_ _ _ __ ___ |
221 # | | '__| | | | | '_ \/ __| |
222 # | | | | | |_| | | | \__ \ |
223 # | |_| |_|\__,_|_| |_|___/ |
224 # | |
225 # '----------------------------------------------------------------------'
228 def inventory_fjdarye_rluns(info):
229 for line in info:
230 rawdata = line[1]
231 if rawdata[3] == u'\xa0': # RLUN is present
232 yield line[0], "", None
235 def check_fjdarye_rluns(item, _no_params, info):
236 for line in info:
237 if item == line[0]:
238 rawdata = line[1]
239 if rawdata[3] != u'\xa0':
240 return (2, "RLUN is not present")
241 elif rawdata[2] == u'\x08':
242 return (1, "RLUN is rebuilding")
243 elif rawdata[2] == u'\x07':
244 return (1, "RLUN copyback in progress")
245 elif rawdata[2] == u'\x41':
246 return (1, "RLUN spare is in use")
247 elif rawdata[2] == u'B':
248 return (0, "RLUN is in RAID0 state") # assumption state 42
249 elif rawdata[2] == u'\x00':
250 return (0, "RLUN is in normal state") # assumption
251 return (2, "RLUN in unknown state %02x" % ord(rawdata[2]))
256 fjdarye_sum_status = {1: 'unknown', 2: 'unused', 3: 'ok', 4: 'warning', 5: 'failed'}
259 def inventory_fjdarye_sum(info):
260 if len(info[0]) == 1:
261 return [(0, None)]
264 def check_fjdarye_sum(index, _no_param, info):
265 for line in info:
266 if len(info[0]) == 1:
267 status = int(line[0])
268 text = "Status is %s" % fjdarye_sum_status[status]
270 if status == 3:
271 return (0, "%s" % text)
272 elif status == 4:
273 return (1, "%s" % text)
274 return (2, "%s" % text)
276 return (3, "No status summary present")