Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / brocade_sfp
blob10f95e2e1bcbebd7a7518c0a17a34072df021f48
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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.
28 def parse_brocade_sfp(info):
29 parsed = {}
31 isl_ports = [int(x[0]) for x in info[1]]
33 for fcport_info, values in zip(info[0], info[2]):
35 # Observed in the wild: Either all of the values are present
36 # or none of them.
37 if values[0] == "NA":
38 continue
40 port_index = int(fcport_info[0])
42 parsed[port_index] = {
43 "port_name": fcport_info[4],
44 "temp": int(values[0]), # °C
45 "phystate": int(fcport_info[1]),
46 "opstate": int(fcport_info[2]),
47 "admstate": int(fcport_info[3]),
48 "voltage": float(values[1]) / 1000, # mV -> V
49 "current": float(values[2]) / 1000, # mA -> A
50 "rx_power": float(values[3]), # dBm
51 "tx_power": float(values[4]), # dBm
52 "is_isl": bool(port_index in isl_ports),
55 return parsed
58 def inventory_brocade_sfp(parsed):
59 settings = host_extra_conf_merged(host_name(), brocade_fcport_inventory)
60 number_of_ports = len(parsed)
61 for port_index, port_info in parsed.iteritems():
62 if brocade_fcport_inventory_this_port(
63 admstate=port_info["admstate"],
64 phystate=port_info["phystate"],
65 opstate=port_info["opstate"],
66 settings=settings):
67 yield brocade_fcport_getitem(
68 number_of_ports=number_of_ports,
69 index=port_index,
70 portname=port_info["port_name"],
71 is_isl=port_info["is_isl"],
72 settings=settings), {}
75 # .--Temperature---------------------------------------------------------.
76 # | _____ _ |
77 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
78 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
79 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
80 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
81 # | |_| |
82 # '----------------------------------------------------------------------'
85 def check_brocade_sfp_temp(item, params, parsed):
87 port_index = int(item.split()[0]) + 1 # TODO: Move this magical plucking apart of the
88 port_info = parsed[port_index] # item to brocade.include and do the same
89 # for brocade.fcport.
91 return check_temperature(port_info["temp"], params, item)
94 check_info['brocade_sfp.temp'] = {
95 'inventory_function': inventory_brocade_sfp,
96 'check_function': check_brocade_sfp_temp,
97 'service_description': "SFP Temperature %s",
98 'has_perfdata': True,
99 'group': "temperature",
100 'includes': ["brocade.include", "temperature.include"],
104 # .--Power level - Main check--------------------------------------------.
105 # | ____ _ _ |
106 # | | _ \ _____ _____ _ __ | | _____ _____| | |
107 # | | |_) / _ \ \ /\ / / _ \ '__| | |/ _ \ \ / / _ \ | |
108 # | | __/ (_) \ V V / __/ | | | __/\ V / __/ | |
109 # | |_| \___/ \_/\_/ \___|_| |_|\___| \_/ \___|_| |
110 # | |
111 # +----------------------------------------------------------------------+
112 # | Also includes information about current and voltage |
113 # '----------------------------------------------------------------------'
116 def check_brocade_sfp(item, params, parsed):
118 # NOTE: We do not use the generic check_levels function from
119 # the API because its behaviour is undesirable, such as
120 # not providing an infotext or perfdata when no levels
121 # are set.
122 def check_levels(value, perf_name, params, infotext_prefix, unit):
123 infotext = infotext_prefix + ("%.2f %s" % (value, unit))
124 if not params:
125 return 0, infotext, [(perf_name, value)]
126 else:
127 crit_lower, warn_lower, warn, crit = params
128 perfdata = [(perf_name, value, warn, crit)]
129 if value >= crit or value < crit_lower:
130 status = 2
131 elif value >= warn or value < warn_lower:
132 status = 1
133 else:
134 status = 0
135 return status, infotext, perfdata
137 port_index = int(item.split()[0]) + 1 # TODO: Move this magical plucking apart of the
138 port_info = parsed[port_index] # item to brocade.include and do the same
139 # for brocade.fcport.
141 yield check_levels(port_info["rx_power"], "input_signal_power_dbm", params.get("rx_power"),
142 "Rx: ", "dBm")
143 yield check_levels(port_info["tx_power"], "output_signal_power_dbm", params.get("tx_power"),
144 "Tx: ", "dBm")
145 yield check_levels(port_info["current"], "current", params.get("current"), "current: ", "A")
146 yield check_levels(port_info["voltage"], "voltage", params.get("voltage"), "voltage: ", "V")
149 check_info['brocade_sfp'] = {
150 'parse_function' : parse_brocade_sfp,
151 'inventory_function' : inventory_brocade_sfp,
152 'check_function' : check_brocade_sfp,
153 'service_description' : 'SFP %s',
154 'snmp_scan_function' : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.1588.2.1.1") \
155 and oid(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.*") is not None,
156 'snmp_info' : [ ( ".1.3.6.1.4.1.1588.2.1.1.1.6.2.1", [
157 CACHED_OID("1"), # swFCPortIndex
158 CACHED_OID("3"), # swFCPortPhyState
159 CACHED_OID("4"), # swFCPortOpStatus
160 CACHED_OID("5"), # swFCPortAdmStatus
161 CACHED_OID("36"), # swFCPortName (not supported by all devices)
164 # Information about Inter-Switch-Links (contains baud rate of port)
165 ( ".1.3.6.1.4.1.1588.2.1.1.1.2.9.1", [
166 CACHED_OID("2"), # swNbMyPort
169 # NOTE: It appears that the port name and index in connUnitPortEntry
170 # are identical to the ones in the table used by
171 # brocade_fcport. We work on this assumption for the time being,
172 # meaning we use the same table as in brocade_fcport (see above)
173 # which we need anyway for PhyState, OpStatus and AdmStatus.
174 # Please check the connUnitPortEntry table (.1.3.6.1.3.94.1.10.1)
175 # should you come across a device for which this assumption
176 # does not hold.
177 ('.1.3.6.1.4.1.1588.2.1.1.1.28.1.1', [ # FA-EXT-MIB::swSfpStatEntry
178 # AUGMENTS {connUnitPortEntry}
179 "1", # swSfpTemperature
180 "2", # swSfpVoltage
181 "3", # swSfpCurrent
182 "4", # swSfpRxPower
183 "5", # swSfpTxPower
186 'has_perfdata' : True,
187 'includes' : [ "brocade.include" ],
188 'group' : "brocade_sfp",