Cleanup config.nodes_of
[check_mk.git] / checks / ibm_svc_enclosure
blobeea4e47f5efc205620dc4b086a2ca2bae7bebf51
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 # <<<ibm_svc_enclosure:sep(58)>>>
29 # 1:online:control:yes:0:io_grp0:2072-24C:7804037:2:2:2:2:24
30 # 2:online:expansion:yes:0:io_grp0:2072-24E:7804306:2:2:2:2:24
31 # 3:online:expansion:yes:0:io_grp0:2072-24E:7804326:2:2:2:2:24
32 # 4:online:expansion:yes:0:io_grp0:2072-24E:7804352:2:2:2:2:24
34 # After a firmware upgrade the output looked like this:
35 # 1:online:control:yes:0:io_grp0:2072-24C:7804037:2:2:2:2:24:0:0
36 # 2:online:expansion:yes:0:io_grp0:2072-24E:7804306:2:2:2:2:24:0:0
37 # 3:online:expansion:yes:0:io_grp0:2072-24E:7804326:2:2:2:2:24:0:0
38 # 4:online:expansion:yes:0:io_grp0:2072-24E:7804352:2:2:2:2:24:0:0
40 # FW >= 7.8
41 # 1:online:control:yes:0:io_grp0:2072-24C:7804037:2:2:2:2:24:0:0:0:0
42 # 2:online:expansion:yes:0:io_grp0:2072-24E:7804306:2:2:2:2:24:0:0:0:0
43 # 3:online:expansion:yes:0:io_grp0:2072-24E:7804326:2:2:2:2:24:0:0:0:0
44 # 4:online:expansion:yes:0:io_grp0:2072-24E:7804352:2:2:2:2:24:0:0:0:0
46 # The names of the columns are:
47 # id:status:type:managed:IO_group_id:IO_group_name:product_MTM:serial_number:total_canisters:online_canisters:total_PSUs:online_PSUs:drive_slots:total_fan_modules:online_fan_modules:total_sems:online_sems
49 # IBM-FLASH900
50 # <<<ibm_svc_enclosure:sep(58)>>>
51 # id:status:type:product_MTM:serial_number:total_canisters:online_canisters:online_PSUs:drive_slots
52 # 1:online:control:9843-AE2:6860407:2:2:2:12
55 def parse_ibm_svc_enclosure(info):
56 dflt_header = _get_ibm_svc_enclosure_dflt_header(info)
57 if dflt_header is None:
58 return {}
60 parsed = {}
61 for id_, rows in parse_ibm_svc_with_header(info, dflt_header).iteritems():
62 try:
63 data = rows[0]
64 except IndexError:
65 continue
66 parsed.setdefault(id_, data)
67 return parsed
70 def _try_int(string):
71 try:
72 return int(string)
73 except (ValueError, TypeError):
74 return None
77 @get_parsed_item_data
78 def check_ibm_svc_enclosure(item, params, data):
79 enclosure_status = data['status']
80 if enclosure_status == "online":
81 status = 0
82 else:
83 status = 2
84 yield status, 'Status: %s' % enclosure_status
86 for key, label in [
87 ('canisters', 'canisters'),
88 ('PSUs', 'PSUs'),
89 ('fan_modules', 'fan modules'),
90 ('sems', 'secondary expander modules'),
92 online = _try_int(data.get("online_%s" % key))
93 total = _try_int(data.get("total_%s" % key))
94 if online is None:
95 continue
96 # Valid values for WATO rule value levels_lower_online_canisters are
97 # False, which shall be mapped to (total, total) or (warn, crit).
98 levels_lower = params.get("levels_lower_online_%s" % key) or (total, total)
99 levels = (None, None) + levels_lower
100 state, infotext, _perfdata = check_levels(
101 online, None, levels, human_readable_func=int, infoname="Online %s" % label)
102 if total is not None:
103 infotext += " of %s" % total
104 yield state, infotext
107 check_info["ibm_svc_enclosure"] = {
108 "parse_function": parse_ibm_svc_enclosure,
109 "check_function": check_ibm_svc_enclosure,
110 "inventory_function": discover(),
111 "service_description": "Enclosure %s",
112 "includes": ["ibm_svc.include"],
113 "group": "ibm_svc_enclosure",
116 # .--helper--------------------------------------------------------------.
117 # | _ _ |
118 # | | |__ ___| |_ __ ___ _ __ |
119 # | | '_ \ / _ \ | '_ \ / _ \ '__| |
120 # | | | | | __/ | |_) | __/ | |
121 # | |_| |_|\___|_| .__/ \___|_| |
122 # | |_| |
123 # '----------------------------------------------------------------------'
126 def _get_ibm_svc_enclosure_dflt_header(info):
127 try:
128 first_line = info[0]
129 except IndexError:
130 return
132 if len(first_line) == 9:
133 return [
134 'id',
135 'status',
136 'type',
137 'product_MTM',
138 'serial_number',
139 'total_canisters',
140 'online_canisters',
141 'online_PSUs',
142 'drive_slots',
144 elif len(first_line) == 13:
145 return [
146 'id',
147 'status',
148 'type',
149 'managed',
150 'IO_group_id',
151 'IO_group_name',
152 'product_MTM',
153 'serial_number',
154 'total_canisters',
155 'online_canisters',
156 'total_PSUs',
157 'online_PSUs',
158 'drive_slots',
160 elif len(first_line) == 15:
161 return [
162 'id',
163 'status',
164 'type',
165 'managed',
166 'IO_group_id',
167 'IO_group_name',
168 'product_MTM',
169 'serial_number',
170 'total_canisters',
171 'online_canisters',
172 'total_PSUs',
173 'online_PSUs',
174 'drive_slots',
175 'total_fan_modules',
176 'online_fan_modules',
178 elif len(first_line) == 17:
179 return [
180 'id',
181 'status',
182 'type',
183 'managed',
184 'IO_group_id',
185 'IO_group_name',
186 'product_MTM',
187 'serial_number',
188 'total_canisters',
189 'online_canisters',
190 'total_PSUs',
191 'online_PSUs',
192 'drive_slots',
193 'total_fan_modules',
194 'online_fan_modules',
195 'total_sems',
196 'online_sems',
198 return