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.
27 #TODO refactoring: use parse-function
29 brocade_mlx_states
= {
30 0: (1, "Slot is empty"),
31 2: (1, "Module is going down"),
32 3: (2, "Rejected due to wrong configuration"),
33 4: (2, "Hardware is bad"),
34 8: (1, "Configured / Stacking"),
35 9: (1, "In power-up cycle"),
37 11: (0, "Blocked for full height card"),
41 ('.1.3.6.1.4.1.1991.1.1.2.2.1.1', [1, 2, 12, 24, 25]),
42 # id, descr, overall status, MemoryTotal, MemoryAvailable
43 ('.1.3.6.1.4.1.1991.1.1.2.11.1.1.5', [OID_END
, ""]),
44 # Rest of OId starting with module ID, CpuUtilPercent
48 def brocade_mlx_get_state(state
):
49 return brocade_mlx_states
.get(state
, (3, 'Unhandled state - %d' % state
))
52 def brocade_mlx_scan(oid
):
53 return oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.1991.1.")
56 def brocade_mlx_combine_item(id_
, descr
):
59 descr
= re
.sub(" *Module", "", descr
)
60 return "%s %s" % (id_
, descr
)
63 # .--Overall Status------------------------------------------------------.
64 # | ___ _ _ ____ _ _ |
65 # | / _ \__ _____ _ __ __ _| | | / ___|| |_ __ _| |_ _ _ ___ |
66 # | | | | \ \ / / _ \ '__/ _` | | | \___ \| __/ _` | __| | | / __| |
67 # | | |_| |\ V / __/ | | (_| | | | ___) | || (_| | |_| |_| \__ \ |
68 # | \___/ \_/ \___|_| \__,_|_|_| |____/ \__\__,_|\__|\__,_|___/ |
70 # +----------------------------------------------------------------------+
73 def inventory_brocade_mlx_module(info
):
75 for module_id
, module_descr
, module_state
, _mem_total
, _mem_avail
in info
[0]:
76 # do not inventorize modules reported as empty
77 if module_state
!= "0":
78 inventory
.append((brocade_mlx_combine_item(module_id
, module_descr
), None))
82 def check_brocade_mlx_module(item
, _no_params
, info
):
83 for module_id
, module_descr
, module_state
, _mem_total
, _mem_avail
in info
[0]:
84 if brocade_mlx_combine_item(module_id
, module_descr
) == item
:
85 return brocade_mlx_get_state(int(module_state
))
86 return 3, "Module not found"
89 check_info
["brocade_mlx.module_status"] = {
90 "check_function": check_brocade_mlx_module
,
91 "inventory_function": inventory_brocade_mlx_module
,
92 "service_description": "Status Module %s",
93 "snmp_info": brocade_mlx_info
,
94 "snmp_scan_function": brocade_mlx_scan
,
98 # .--Memory--------------------------------------------------------------.
100 # | | \/ | ___ _ __ ___ ___ _ __ _ _ |
101 # | | |\/| |/ _ \ '_ ` _ \ / _ \| '__| | | | |
102 # | | | | | __/ | | | | | (_) | | | |_| | |
103 # | |_| |_|\___|_| |_| |_|\___/|_| \__, | |
105 # +----------------------------------------------------------------------+
107 brocade_mlx_mem_default_levels
= {"levels": (80.0, 90.0)}
110 def parse_brocade_mlx_module_mem(info
):
112 for module_id
, module_descr
, module_state
, mem_total
, mem_avail
in info
[0]:
113 item
= brocade_mlx_combine_item(module_id
, module_descr
)
115 _
, state_readable
= brocade_mlx_get_state(int(module_state
))
117 state_readable
= 'Device did not return any state'
119 parsed
.setdefault(item
, {
120 "state_readable": state_readable
,
121 "descr": module_descr
,
125 parsed
[item
]["mem_total"] = int(mem_total
)
130 parsed
[item
]["mem_avail"] = int(mem_avail
)
137 def inventory_brocade_mlx_module_mem(info
):
138 parsed
= parse_brocade_mlx_module_mem(info
)
140 for k
, v
in parsed
.iteritems():
141 # do not inventorize modules reported as empty or "Blocked for full height card"
142 # and: monitor cpu only on NI-MLX and BR-MLX modules
144 if v
['state_readable'] not in ["Slot is empty", "Blocked for full height card"] \
145 and (descr
.startswith("NI-MLX") or descr
.startswith("BR-MLX")):
146 inventory
.append((k
, "brocade_mlx_mem_default_levels"))
150 def check_brocade_mlx_module_mem(item
, params
, info
):
151 parsed
= parse_brocade_mlx_module_mem(info
)
152 if item
not in parsed
:
153 yield 3, '%s not found in agent output' % item
157 state_readable
= data
['state_readable']
158 if state_readable
.lower() != "running":
159 yield 3, "Module is not running (Current State: %s)" % state_readable
162 yield check_memory_multiitem(params
, data
)
165 check_info
["brocade_mlx.module_mem"] = {
166 "check_function": check_brocade_mlx_module_mem
,
167 "inventory_function": inventory_brocade_mlx_module_mem
,
168 "service_description": "Memory Module %s",
169 "snmp_info": brocade_mlx_info
,
170 "snmp_scan_function": brocade_mlx_scan
,
171 "has_perfdata": True,
172 "group": "memory_multiitem",
173 "includes": ["memory.include"],
177 # .--CPU-----------------------------------------------------------------.
179 # | / ___| _ \| | | | |
180 # | | | | |_) | | | | |
181 # | | |___| __/| |_| | |
184 # +----------------------------------------------------------------------+
186 brocade_mlx_cpu_default_levels
= {"levels": (80.0, 90.0)}
189 def inventory_brocade_mlx_module_cpu(info
):
191 for module_id
, module_descr
, module_state
, _mem_total
, _mem_avail
in info
[0]:
192 # do not inventorize modules reported as empty or "Blocked for full height card"
193 # and: monitor cpu only on NI-MLX and BR-MLX modules
194 if module_state
!= "0" and module_state
!= "11" and (module_descr
.startswith("NI-MLX") or
195 module_descr
.startswith("BR-MLX")):
196 inventory
.append((brocade_mlx_combine_item(module_id
, module_descr
),
197 "brocade_mlx_cpu_default_levels"))
201 def check_brocade_mlx_module_cpu(item
, params
, info
):
202 warn
, crit
= params
["levels"]
203 for module_id
, module_descr
, module_state
, _mem_total
, _mem_avail
in info
[0]:
204 if brocade_mlx_combine_item(module_id
, module_descr
) == item
:
205 if module_state
!= "10":
206 return 3, "Module is not in state running"
212 for oid_end
, cpu_util
in info
[1]:
213 if oid_end
== "%s.1.1" % module_id
:
214 cpu_util1
= saveint(cpu_util
)
215 if oid_end
== "%s.1.5" % module_id
:
216 cpu_util5
= saveint(cpu_util
)
217 if oid_end
== "%s.1.60" % module_id
:
218 cpu_util60
= saveint(cpu_util
)
219 if oid_end
== "%s.1.300" % module_id
:
220 cpu_util300
= saveint(cpu_util
)
222 if cpu_util1
== "" or cpu_util5
== "" or cpu_util60
== "" or cpu_util300
== "":
223 return 3, "did not find all cpu utilization values in snmp output"
226 ('cpu_util1', str(cpu_util1
) + '%', '', '', 0, 100),
227 ('cpu_util5', str(cpu_util5
) + '%', '', '', 0, 100),
228 ('cpu_util60', str(cpu_util60
) + '%', warn
, crit
, 0, 100),
229 ('cpu_util300', str(cpu_util300
) + '%', '', '', 0, 100),
234 if cpu_util60
> warn
:
237 if cpu_util60
> crit
:
241 return status
, "CPU utilization was %s/%s/%s%s/%s%% for the last 1/5/60/300 sec" % \
242 (cpu_util1
, cpu_util5
, cpu_util60
, errorstring
, cpu_util300
), perfdata
244 return 3, "Module not found"
247 check_info
["brocade_mlx.module_cpu"] = {
248 "check_function": check_brocade_mlx_module_cpu
,
249 "inventory_function": inventory_brocade_mlx_module_cpu
,
250 "service_description": "CPU utilization Module %s",
251 "snmp_info": brocade_mlx_info
,
252 "snmp_scan_function": brocade_mlx_scan
,
253 "has_perfdata": True,
254 "group": "cpu_utilization_multiitem",