Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / entity_sensors
blob522aa086f4640346d8eab057202cb7a8a22cef27
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2016 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 # .1.3.6.1.2.1.47.1.1.1.1.7.1 PA-3020 --> ENTITY-MIB::entPhysicalName.1
28 # .1.3.6.1.2.1.47.1.1.1.1.7.2 Fan #1 RPM --> ENTITY-MIB::entPhysicalName.2
29 # .1.3.6.1.2.1.47.1.1.1.1.7.3 Fan #2 RPM --> ENTITY-MIB::entPhysicalName.3
30 # .1.3.6.1.2.1.47.1.1.1.1.7.4 Fan #3 RPM --> ENTITY-MIB::entPhysicalName.4
31 # .1.3.6.1.2.1.47.1.1.1.1.7.5 Fan #4 RPM --> ENTITY-MIB::entPhysicalName.5
32 # .1.3.6.1.2.1.47.1.1.1.1.7.6 Temperature @ Ocelot --> ENTITY-MIB::entPhysicalName.6
33 # .1.3.6.1.2.1.47.1.1.1.1.7.7 Temperature @ Switch --> ENTITY-MIB::entPhysicalName.7
34 # .1.3.6.1.2.1.47.1.1.1.1.7.8 Temperature @ Cavium --> ENTITY-MIB::entPhysicalName.8
35 # .1.3.6.1.2.1.47.1.1.1.1.7.9 Temperature @ Intel PHY --> ENTITY-MIB::entPhysicalName.9
36 # .1.3.6.1.2.1.47.1.1.1.1.7.10 Temperature @ Switch Core --> ENTITY-MIB::entPhysicalName.10
37 # .1.3.6.1.2.1.47.1.1.1.1.7.11 Temperature @ Cavium Core --> ENTITY-MIB::entPhysicalName.11
39 # .1.3.6.1.2.1.99.1.1.1.1.2 10 --> ENTITY-SENSOR-MIB::entPhySensorType.2
40 # .1.3.6.1.2.1.99.1.1.1.1.3 10 --> ENTITY-SENSOR-MIB::entPhySensorType.3
41 # .1.3.6.1.2.1.99.1.1.1.1.4 10 --> ENTITY-SENSOR-MIB::entPhySensorType.4
42 # .1.3.6.1.2.1.99.1.1.1.1.5 10 --> ENTITY-SENSOR-MIB::entPhySensorType.5
43 # .1.3.6.1.2.1.99.1.1.1.1.6 8 --> ENTITY-SENSOR-MIB::entPhySensorType.6
44 # .1.3.6.1.2.1.99.1.1.1.1.7 8 --> ENTITY-SENSOR-MIB::entPhySensorType.7
45 # .1.3.6.1.2.1.99.1.1.1.1.8 8 --> ENTITY-SENSOR-MIB::entPhySensorType.8
46 # .1.3.6.1.2.1.99.1.1.1.1.9 8 --> ENTITY-SENSOR-MIB::entPhySensorType.9
47 # .1.3.6.1.2.1.99.1.1.1.1.10 8 --> ENTITY-SENSOR-MIB::entPhySensorType.10
48 # .1.3.6.1.2.1.99.1.1.1.1.11 8 --> ENTITY-SENSOR-MIB::entPhySensorType.11
49 # .1.3.6.1.2.1.99.1.1.1.2.2 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.2
50 # .1.3.6.1.2.1.99.1.1.1.2.3 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.3
51 # .1.3.6.1.2.1.99.1.1.1.2.4 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.4
52 # .1.3.6.1.2.1.99.1.1.1.2.5 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.5
53 # .1.3.6.1.2.1.99.1.1.1.2.6 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.6
54 # .1.3.6.1.2.1.99.1.1.1.2.7 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.7
55 # .1.3.6.1.2.1.99.1.1.1.2.8 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.8
56 # .1.3.6.1.2.1.99.1.1.1.2.9 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.9
57 # .1.3.6.1.2.1.99.1.1.1.2.10 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.10
58 # .1.3.6.1.2.1.99.1.1.1.2.11 9 --> ENTITY-SENSOR-MIB::entPhySensorScale.11
59 # .1.3.6.1.2.1.99.1.1.1.4.2 9665 --> ENTITY-SENSOR-MIB::entPhySensorValue.2
60 # .1.3.6.1.2.1.99.1.1.1.4.3 9529 --> ENTITY-SENSOR-MIB::entPhySensorValue.3
61 # .1.3.6.1.2.1.99.1.1.1.4.4 9552 --> ENTITY-SENSOR-MIB::entPhySensorValue.4
62 # .1.3.6.1.2.1.99.1.1.1.4.5 9225 --> ENTITY-SENSOR-MIB::entPhySensorValue.5
63 # .1.3.6.1.2.1.99.1.1.1.4.6 32 --> ENTITY-SENSOR-MIB::entPhySensorValue.6
64 # .1.3.6.1.2.1.99.1.1.1.4.7 40 --> ENTITY-SENSOR-MIB::entPhySensorValue.7
65 # .1.3.6.1.2.1.99.1.1.1.4.8 42 --> ENTITY-SENSOR-MIB::entPhySensorValue.8
66 # .1.3.6.1.2.1.99.1.1.1.4.9 28 --> ENTITY-SENSOR-MIB::entPhySensorValue.9
67 # .1.3.6.1.2.1.99.1.1.1.4.10 61 --> ENTITY-SENSOR-MIB::entPhySensorValue.10
68 # .1.3.6.1.2.1.99.1.1.1.4.11 48 --> ENTITY-SENSOR-MIB::entPhySensorValue.11
69 # .1.3.6.1.2.1.99.1.1.1.5.2 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.2
70 # .1.3.6.1.2.1.99.1.1.1.5.3 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.3
71 # .1.3.6.1.2.1.99.1.1.1.5.4 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.4
72 # .1.3.6.1.2.1.99.1.1.1.5.5 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.5
73 # .1.3.6.1.2.1.99.1.1.1.5.6 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.6
74 # .1.3.6.1.2.1.99.1.1.1.5.7 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.7
75 # .1.3.6.1.2.1.99.1.1.1.5.8 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.8
76 # .1.3.6.1.2.1.99.1.1.1.5.9 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.9
77 # .1.3.6.1.2.1.99.1.1.1.5.10 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.10
78 # .1.3.6.1.2.1.99.1.1.1.5.11 1 --> ENTITY-SENSOR-MIB::entPhySensorOperStatus.11
81 def parse_entity_sensors(info):
82 map_types = {
83 "1": ("other", "other"),
84 "2": ("unknown", "unknown"),
85 "3": ("voltage", "V"),
86 "4": ("voltage", "V"),
87 "5": ("current", "A"),
88 "6": ("power", "W"),
89 "7": ("freqeuncy", "hz"),
90 "8": ("temp", "c"),
91 "9": ("percent", "%"),
92 "10": ("fan", "RPM"),
93 "11": ("volume", "cmm"), # cubic decimetre dm^3
94 "12": ("binary", "")
96 map_scaling = {
97 "1": 10**(-24),
98 "2": 10**(-21),
99 "3": 10**(-18),
100 "4": 10**(-15),
101 "5": 10**(-12),
102 "6": 10**(-9),
103 "7": 10**(-6),
104 "8": 10**(-3),
105 "9": 1,
106 "10": 10**(3),
107 "11": 10**(6),
108 "12": 10**(9),
109 "13": 10**(12),
110 "14": 10**(15),
111 "15": 10**(18),
112 "16": 10**(21),
113 "17": 10**(24),
115 map_operstate = {"1": (0, "OK"), "2": (2, "unavailable"), "3": (1, "nonoperational")}
116 # Some devices such as Palo Alto Network series 3000 support
117 # the ENTITY-MIB including sensor/entity names.
118 # Others (e.g. Palo Alto Networks Series 200) do not support
119 # this MIB, thus we use OID as item instead
120 pre_parsed = {}
121 for oid, name in info[0]:
122 sensor_name = ""
123 if name:
124 sensor_name = "Sensor %s" % \
125 (name.replace("Temperature", "") \
126 .replace("Fan", "") \
127 .replace("@", "") \
128 .replace("#", "").strip())
130 pre_parsed.setdefault(oid, sensor_name)
132 parsed = {}
133 for oid, sensor_type_nr, sensor_scale, sensor_reading, operstate in info[1]:
134 if pre_parsed.get(oid, ""):
135 sensor_name = pre_parsed[oid]
136 else:
137 sensor_name = "Sensor %s" % oid
139 sensor_type, sensor_unit = map_types[sensor_type_nr]
140 parsed.setdefault(sensor_type, {})
141 factor = float(map_scaling[sensor_scale])
142 parsed[sensor_type][sensor_name] = \
143 (map_operstate[operstate],
144 float(sensor_reading) * factor, sensor_unit)
146 return parsed
149 def inventory_entity_sensors(parsed, what):
150 for sensor, sensor_info in parsed.get(what, {}).items():
151 if sensor_info[0][1] == "OK":
152 yield (sensor, {})
155 # .--temperature---------------------------------------------------------.
156 # | _ _ |
157 # | | |_ ___ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
158 # | | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
159 # | | || __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
160 # | \__\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
161 # | |_| |
162 # +----------------------------------------------------------------------+
163 # | main check |
164 # '----------------------------------------------------------------------'
166 # Asked customer, oriented by other temperature sensor checks
167 factory_settings['entity_sensors_temp_default_variables'] = {
168 'levels': (35, 40),
172 def check_entity_sensors_temp(item, params, parsed):
173 if item in parsed.get("temp", {}):
174 operstate, reading, unit = parsed["temp"][item]
175 state, state_readable = operstate
176 return check_temperature(
177 reading,
178 params,
179 "palo_alto_temperature_%s" % item,
180 dev_unit=unit,
181 dev_status=state,
182 dev_status_name=state_readable)
185 check_info['entity_sensors'] = {
186 'parse_function': parse_entity_sensors,
187 'inventory_function': lambda parsed: inventory_entity_sensors(parsed, "temp"),
188 'check_function': check_entity_sensors_temp,
189 'service_description': 'Temperature %s',
190 'has_perfdata': True,
191 'snmp_info': [
193 ".1.3.6.1.2.1.47.1.1.1.1",
195 OID_END,
196 "7", # entPhysicalName
199 ".1.3.6.1.2.1.99.1.1.1",
201 OID_END,
202 "1", # entPhySensorType
203 "2", # entPhySensorScale
204 "4", # entPhySensorValue
205 "5", # entPhySensorOperStatus
208 'snmp_scan_function': lambda oid: "palo alto networks" in oid(".1.3.6.1.2.1.1.1.0").lower(),
209 'default_levels_variable': 'entity_sensors_temp_default_variables',
210 'group': 'temperature',
211 'includes': ['temperature.include'],
215 # .--fan-----------------------------------------------------------------.
216 # | __ |
217 # | / _| __ _ _ __ |
218 # | | |_ / _` | '_ \ |
219 # | | _| (_| | | | | |
220 # | |_| \__,_|_| |_| |
221 # | |
222 # '----------------------------------------------------------------------'
224 # Asked customer, oriented by other fan sensor checks
225 factory_settings['entity_sensors_fan_default_variables'] = {
226 'lower': (2000, 1000),
230 def check_entity_sensors_fan(item, params, parsed):
231 if item in parsed.get("fan", {}):
232 operstate, reading, _unit = parsed["fan"][item]
233 state, state_readable = operstate
234 yield state, "Operational status: %s" % state_readable
235 yield check_fan(reading, params)
238 check_info['entity_sensors.fan'] = {
239 'inventory_function': lambda parsed: inventory_entity_sensors(parsed, "fan"),
240 'check_function': check_entity_sensors_fan,
241 'service_description': 'Fan %s',
242 'has_perfdata': True,
243 'default_levels_variable': 'entity_sensors_fan_default_variables',
244 'group': 'hw_fans',
245 'includes': ['fan.include'],