Cleanup config.nodes_of
[check_mk.git] / checks / openbsd_sensors
blobba39f8e2a0bd1f9c70eb9434aebe41d29badbdf3
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 # .--example output------------------------------------------------------.
28 # | _ |
29 # | _____ ____ _ _ __ ___ _ __ | | ___ |
30 # | / _ \ \/ / _` | '_ ` _ \| '_ \| |/ _ \ |
31 # | | __/> < (_| | | | | | | |_) | | __/ |
32 # | \___/_/\_\__,_|_| |_| |_| .__/|_|\___| |
33 # | |_| |
34 # | _ _ |
35 # | ___ _ _| |_ _ __ _ _| |_ |
36 # | / _ \| | | | __| '_ \| | | | __| |
37 # | | (_) | |_| | |_| |_) | |_| | |_ |
38 # | \___/ \__,_|\__| .__/ \__,_|\__| |
39 # | |_| |
40 # +----------------------------------------------------------------------+
41 # | |
42 # '----------------------------------------------------------------------'
43 # .1.3.6.1.4.1.30155.2.1.2.1.2.18 temp0
44 # .1.3.6.1.4.1.30155.2.1.2.1.2.20 temp2
45 # .1.3.6.1.4.1.30155.2.1.2.1.2.27 fan3
46 # .1.3.6.1.4.1.30155.2.1.2.1.2.31 fan7
47 # .1.3.6.1.4.1.30155.2.1.2.1.2.40 VTT
48 # .1.3.6.1.4.1.30155.2.1.2.1.2.47 volt9
50 # .1.3.6.1.4.1.30155.2.1.2.1.3.18 0
51 # .1.3.6.1.4.1.30155.2.1.2.1.3.20 0
52 # .1.3.6.1.4.1.30155.2.1.2.1.3.27 1
53 # .1.3.6.1.4.1.30155.2.1.2.1.3.31 1
54 # .1.3.6.1.4.1.30155.2.1.2.1.3.40 2
55 # .1.3.6.1.4.1.30155.2.1.2.1.3.47 2
57 # .1.3.6.1.4.1.30155.2.1.2.1.5.18 -273.15
58 # .1.3.6.1.4.1.30155.2.1.2.1.5.20 56.00
59 # .1.3.6.1.4.1.30155.2.1.2.1.5.27 4179
60 # .1.3.6.1.4.1.30155.2.1.2.1.5.31 329
61 # .1.3.6.1.4.1.30155.2.1.2.1.5.40 1.15
62 # .1.3.6.1.4.1.30155.2.1.2.1.5.47 0.00
64 # .1.3.6.1.4.1.30155.2.1.2.1.6.18 degC
65 # .1.3.6.1.4.1.30155.2.1.2.1.6.20 degC
66 # .1.3.6.1.4.1.30155.2.1.2.1.6.27 RPM
67 # .1.3.6.1.4.1.30155.2.1.2.1.6.31 RPM
68 # .1.3.6.1.4.1.30155.2.1.2.1.6.40 V DC
69 # .1.3.6.1.4.1.30155.2.1.2.1.6.47 V DC
71 # .1.3.6.1.4.1.30155.2.1.2.1.7.18 0
72 # .1.3.6.1.4.1.30155.2.1.2.1.7.20 0
73 # .1.3.6.1.4.1.30155.2.1.2.1.7.27 0
74 # .1.3.6.1.4.1.30155.2.1.2.1.7.31 0
75 # .1.3.6.1.4.1.30155.2.1.2.1.7.40 0
76 # .1.3.6.1.4.1.30155.2.1.2.1.7.47 0
79 # .--parse---------------------------------------------------------------.
80 # | |
81 # | _ __ __ _ _ __ ___ ___ |
82 # | | '_ \ / _` | '__/ __|/ _ \ |
83 # | | |_) | (_| | | \__ \ __/ |
84 # | | .__/ \__,_|_| |___/\___| |
85 # | |_| |
86 # +----------------------------------------------------------------------+
87 # | |
88 # '----------------------------------------------------------------------'
91 def parse_openbsd_sensors(info):
92 parsed = {}
93 used_descriptions = set()
95 def get_item_name(name):
96 idx = 0
97 new_name = name
98 while True:
99 if new_name in used_descriptions:
100 new_name = "%s/%d" % (name, idx)
101 idx += 1
102 else:
103 used_descriptions.add(new_name)
104 break
105 return new_name
107 openbsd_map_state = {
108 '0': 3,
109 '1': 0,
110 '2': 1,
111 '3': 2,
114 openbsd_map_type = {'0': 'temp', '1': 'fan', '2': 'voltage'}
116 for descr, sensortype, value, unit, state in info:
117 if sensortype not in openbsd_map_type:
118 continue
119 if (sensortype == '0' and value == '-273.15') or \
120 (sensortype in [ '1', '2'] and float(value) == 0):
121 continue
123 item_name = get_item_name(descr)
124 parsed[item_name] = {
125 'state': openbsd_map_state[state],
126 'value': float(value),
127 'unit': unit,
128 'type': openbsd_map_type[sensortype],
130 return parsed
134 # .--inventory-----------------------------------------------------------.
135 # | _ _ |
136 # | (_)_ ____ _____ _ __ | |_ ___ _ __ _ _ |
137 # | | | '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | |
138 # | | | | | \ V / __/ | | | || (_) | | | |_| | |
139 # | |_|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | |
140 # | |___/ |
141 # +----------------------------------------------------------------------+
142 # | |
143 # '----------------------------------------------------------------------'
146 def inventory_openbsd_sensors(parsed, sensortype):
147 inventory = []
148 for key, values in parsed.items():
149 if values['type'] == sensortype:
150 inventory.append((key, {}))
151 return inventory
155 # .--temperature---------------------------------------------------------.
156 # | _ _ |
157 # | | |_ ___ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
158 # | | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
159 # | | || __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
160 # | \__\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
161 # | |_| |
162 # +----------------------------------------------------------------------+
163 # | |
164 # '----------------------------------------------------------------------'
167 def check_openbsd_sensors(item, params, parsed):
168 if item in parsed:
169 return check_temperature(parsed[item]['value'], params, "openbsd_sensors_%s" % item)
172 check_info['openbsd_sensors'] = {
173 'parse_function': parse_openbsd_sensors,
174 'inventory_function': lambda parsed: inventory_openbsd_sensors(parsed, 'temp'),
175 'check_function': check_openbsd_sensors,
176 'service_description': 'Temperature %s',
177 'has_perfdata': True,
178 'snmp_info': (
179 '.1.3.6.1.4.1.30155.2.1.2.1',
181 "2", # sensorDescr
182 "3", # sensorType
183 "5", # sensorValue
184 "6", # sensorUnits
185 "7", # sensorStatus
187 'snmp_scan_function': lambda oid: oid(".1.3.6.1.4.1.30155.2.1.1.0"),
188 'group': 'temperature',
189 'includes': ['temperature.include'],
193 # .--fan-----------------------------------------------------------------.
194 # | __ |
195 # | / _| __ _ _ __ |
196 # | | |_ / _` | '_ \ |
197 # | | _| (_| | | | | |
198 # | |_| \__,_|_| |_| |
199 # | |
200 # +----------------------------------------------------------------------+
201 # | |
202 # '----------------------------------------------------------------------'
204 factory_settings['openbsd_sensors_fan_default_levels'] = {
205 'lower': (500, 300),
206 'upper': (8000, 8400),
210 def check_openbsd_sensors_fan(item, params, parsed):
211 if item in parsed:
212 return check_fan(parsed[item]['value'], params)
215 check_info['openbsd_sensors.fan'] = {
216 'inventory_function': lambda parsed: inventory_openbsd_sensors(parsed, 'fan'),
217 'check_function': check_openbsd_sensors_fan,
218 'service_description': 'Fan %s',
219 'has_perfdata': True,
220 'default_levels_variable': 'openbsd_sensors_fan_default_levels',
221 'group': 'hw_fans',
222 'includes': ['fan.include'],
226 # .--voltage-------------------------------------------------------------.
227 # | _ _ |
228 # | __ _____ | | |_ __ _ __ _ ___ |
229 # | \ \ / / _ \| | __/ _` |/ _` |/ _ \ |
230 # | \ V / (_) | | || (_| | (_| | __/ |
231 # | \_/ \___/|_|\__\__,_|\__, |\___| |
232 # | |___/ |
233 # +----------------------------------------------------------------------+
234 # | |
235 # '----------------------------------------------------------------------'
238 def check_openbsd_sensors_voltage(item, params, parsed):
239 if item in parsed:
240 item_elphase = {}
241 parsed_elphase = {}
242 item_elphase['voltage'] = parsed[item]['value']
243 parsed_elphase[item] = item_elphase
245 return check_elphase(item, params, parsed_elphase)
248 check_info['openbsd_sensors.voltage'] = {
249 'inventory_function': lambda parsed: inventory_openbsd_sensors(parsed, 'voltage'),
250 'check_function': check_openbsd_sensors_voltage,
251 'service_description': 'Voltage Type %s',
252 'has_perfdata': True,
253 'group': 'el_inphase',
254 'includes': ['elphase.include'],