2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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----------------------------------------------------------------.
31 # | | \/ | __ _ _ __ ___ |
32 # | | |\/| |/ _` | '_ \/ __| |
33 # | | | | | (_| | |_) \__ \ |
34 # | |_| |_|\__,_| .__/|___/ |
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')
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'),
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'),
66 '20': ('binary', 'Contact'),
67 '21': ('fanspeed', ''),
72 # SensorUnitsEnumeration (EMD-, PDU2, LHX-MIB)
82 # for dev_unit in check_temperature
88 # 1 psi = 6894,757293168 Pa
91 # for dev_unit in check_temperature
100 # SensorStateEnumeration (EMD-, PDU2, LHX-MIB)
101 # nr. --> (check state, state human readable)
102 raritan_map_state
= {
103 '-1': (2, "unavailable"),
106 '2': (2, "below lower critical"),
107 '3': (1, "below lower warning"),
109 '5': (1, "above upper warning"),
110 '6': (2, "above upper critical"),
113 '9': (0, "detected"),
114 '10': (2, "not detected"),
115 '11': (2, "alarmed"),
119 # .--Functions-----------------------------------------------------------.
121 # | | ___| _ _ __ ___| |_(_) ___ _ __ ___ |
122 # | | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __| |
123 # | | _|| |_| | | | | (__| |_| | (_) | | | \__ \ |
124 # | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ |
126 # +----------------------------------------------------------------------+
128 # snmp_info must be of the form:
129 # "X.Y.Z", # IsAvailable -> True/False (1/0)
135 # "X.Y.Z", # DecimalDigits -> for scaling the values
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
):
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"))
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', '']:
165 if sensor_unit
== " m/s":
170 # if the value is 5 and unitSensorDecimalDigits is 2
171 # then actual value is 0.05
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
,
190 def inventory_raritan_sensors(parsed
, sensor_type
):
192 for key
, values
in parsed
.items():
193 if values
['availability'] == '1' and values
['sensor_type'] == sensor_type
:
194 inventory
.append((key
, None))
199 def inventory_raritan_sensors_temp(parsed
, sensor_type
):
201 for key
, values
in parsed
.items():
202 if values
['availability'] == '1' and values
['sensor_type'] == sensor_type
:
203 inventory
.append((key
, {}))
208 def check_raritan_sensors(item
, _no_params
, 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
):
227 state
, state_readable
= parsed
[item
]["state"]
228 return state
, "Status: %s" % state_readable
231 def check_raritan_sensors_temp(item
, params
, parsed
):
233 state
, state_readable
= parsed
[item
]['state']
234 reading
, crit_lower
, warn_lower
, crit
, warn
= parsed
[item
]['sensor_data']
235 return check_temperature(
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
),
243 dev_status_name
=state_readable
)