Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / raritan.include
blobb39d47ff5e1ea81e663bae1909f21e7335006337
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # For raritan devices which support the PDU2-, EMD-, or LHX-MIB
29 # .--Maps----------------------------------------------------------------.
30 # | __ __ |
31 # | | \/ | __ _ _ __ ___ |
32 # | | |\/| |/ _` | '_ \/ __| |
33 # | | | | | (_| | |_) \__ \ |
34 # | |_| |_|\__,_| .__/|___/ |
35 # | |_| |
36 # +----------------------------------------------------------------------+
38 # The sensor types with an empty key have no values or levels
39 # nr. --> (key, additional type human readable)
40 # SensorTypeEnumeration (EMD-MIB, PDU2-MIB)
41 # If type_human_readable != '' then it's a more detailed item name.
42 # Otherwise the information is in the description (e.g. in the
43 # case of 'Temperature')
44 raritan_map_type = {
45 '1': ('current', 'RMS'),
46 '2': ('peak', 'Peak'),
47 '3': ('unbalanced', 'Unbalanced'),
48 '4': ('voltage', 'RMS'),
49 '5': ('power', 'Active'),
50 '6': ('appower', 'Apparent'),
51 # power factor is defined as the ratio of the real power flowing
52 # to the load to the apparent power
53 '7': ('power_factor', 'Power Factor'),
54 '8': ('energy', 'Active'),
55 '9': ('energy', 'Apparent'),
56 '10': ('temp', ''),
57 '11': ('humidity', ''),
58 '12': ('airflow', ''),
59 '13': ('pressure_pa', 'Air'),
60 '14': ('binary', 'On/Off'),
61 '15': ('binary', 'Trip'),
62 '16': ('binary', 'Vibration'),
63 '17': ('binary', 'Water Detector'),
64 '18': ('binary', 'Smoke Detector'),
65 '19': ('binary', ''),
66 '20': ('binary', 'Contact'),
67 '21': ('fanspeed', ''),
68 '30': ('', 'Other'),
69 '31': ('', 'None'),
72 # SensorUnitsEnumeration (EMD-, PDU2, LHX-MIB)
73 raritan_map_unit = {
74 '-1': "",
75 '0': " Other",
76 '1': " V",
77 '2': " A",
78 '3': " W",
79 '4': " VA",
80 '5': " Wh",
81 '6': " VAh",
82 # for dev_unit in check_temperature
83 '7': "c",
84 '8': " hz",
85 '9': "%",
86 '10': " m/s",
87 '11': " Pa",
88 # 1 psi = 6894,757293168 Pa
89 '12': " psi",
90 '13': " g",
91 # for dev_unit in check_temperature
92 '14': "f",
93 '15': " ft",
94 '16': " inch",
95 '17': " cm",
96 '18': " m",
97 '19': " RPM",
100 # SensorStateEnumeration (EMD-, PDU2, LHX-MIB)
101 # nr. --> (check state, state human readable)
102 raritan_map_state = {
103 '-1': (2, "unavailable"),
104 '0': (1, "open"),
105 '1': (0, "closed"),
106 '2': (2, "below lower critical"),
107 '3': (1, "below lower warning"),
108 '4': (0, "normal"),
109 '5': (1, "above upper warning"),
110 '6': (2, "above upper critical"),
111 '7': (0, "on"),
112 '8': (2, "off"),
113 '9': (0, "detected"),
114 '10': (2, "not detected"),
115 '11': (2, "alarmed"),
119 # .--Functions-----------------------------------------------------------.
120 # | _____ _ _ |
121 # | | ___| _ _ __ ___| |_(_) ___ _ __ ___ |
122 # | | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
123 # | | _|| |_| | | | | (__| |_| | (_) | | | \__ \ |
124 # | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
125 # | |
126 # +----------------------------------------------------------------------+
128 # snmp_info must be of the form:
129 # "X.Y.Z", # IsAvailable -> True/False (1/0)
130 # "X.Y.Z", # Number
131 # "X.Y.Z", # Name
132 # "X.Y.Z", # Type
133 # "X.Y.Z", # State
134 # "X.Y.Z", # Units
135 # "X.Y.Z", # DecimalDigits -> for scaling the values
136 # "X.Y.Z", # Value
137 # "X.Y.Z", # LowerCriticalThreshold
138 # "X.Y.Z", # LowerWarningThreshold
139 # "X.Y.Z", # UpperCriticalThreshold
140 # "X.Y.Z", # UpperWarningThreshold
143 def parse_raritan_sensors(info):
144 parsed = {}
145 for availability, sensor_id, sensor_name, sensor_type, sensor_state, sensor_unit, \
146 sensor_exponent, sensor_value_str, sensor_lower_crit_str, sensor_lower_warn_str, \
147 sensor_upper_crit_str, sensor_upper_warn_str in info:
149 sensor_type, sensor_type_readable = \
150 raritan_map_type.get(sensor_type, ('', "Other"))
152 extra_name = ""
153 if sensor_type_readable != '':
154 extra_name += " " + sensor_type_readable
156 sensor_name = ("Sensor %s%s %s" % (sensor_id, extra_name, sensor_name)).strip()
158 sensor_unit = raritan_map_unit.get(sensor_unit, " Other")
160 # binary sensors don't have any values or levels
161 if sensor_type in ['binary', '']:
162 sensor_data = []
163 else:
164 # 1 m/s = 8.11 l/s
165 if sensor_unit == " m/s":
166 sensor_unit = " l/s"
167 factor = 8.11
168 else:
169 factor = 1
170 # if the value is 5 and unitSensorDecimalDigits is 2
171 # then actual value is 0.05
172 sensor_data = [
173 factor * float(x) / pow(10, int(sensor_exponent)) for x in [
174 sensor_value_str, sensor_lower_crit_str, sensor_lower_warn_str,
175 sensor_upper_crit_str, sensor_upper_warn_str
179 parsed[sensor_name] = {
180 'availability': availability,
181 'state': raritan_map_state.get(sensor_state, (3, "unhandled state")),
182 'sensor_type': sensor_type,
183 'sensor_data': sensor_data,
184 'sensor_unit': sensor_unit,
187 return parsed
190 def inventory_raritan_sensors(parsed, sensor_type):
191 inventory = []
192 for key, values in parsed.items():
193 if values['availability'] == '1' and values['sensor_type'] == sensor_type:
194 inventory.append((key, None))
196 return inventory
199 def inventory_raritan_sensors_temp(parsed, sensor_type):
200 inventory = []
201 for key, values in parsed.items():
202 if values['availability'] == '1' and values['sensor_type'] == sensor_type:
203 inventory.append((key, {}))
205 return inventory
208 def check_raritan_sensors(item, _no_params, parsed):
209 if item in parsed:
210 state, state_readable = parsed[item]['state']
211 unit = parsed[item]['sensor_unit']
212 reading, crit_lower, warn_lower, crit, warn = parsed[item]['sensor_data']
213 infotext = "%s%s, status: %s" % (reading, unit, state_readable)
215 if state > 0 and reading >= warn:
216 infotext += " (device warn/crit at %.1f%s/%.1f%s)" \
217 % (warn, unit, crit, unit)
218 elif state > 0 and reading < warn_lower:
219 infotext += " (device warn/crit below %.1f%s/%.1f%s)" \
220 % (warn_lower, unit, crit_lower, unit)
222 return state, infotext, [(parsed[item]['sensor_type'], reading, warn, crit)]
225 def check_raritan_sensors_binary(item, _no_params, parsed):
226 if item in parsed:
227 state, state_readable = parsed[item]["state"]
228 return state, "Status: %s" % state_readable
231 def check_raritan_sensors_temp(item, params, parsed):
232 if item in parsed:
233 state, state_readable = parsed[item]['state']
234 reading, crit_lower, warn_lower, crit, warn = parsed[item]['sensor_data']
235 return check_temperature(
236 reading,
237 params,
238 "raritan_sensors_%s" % item,
239 dev_unit=parsed[item]['sensor_unit'],
240 dev_levels=(warn, crit),
241 dev_levels_lower=(warn_lower, crit_lower),
242 dev_status=state,
243 dev_status_name=state_readable)