Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / security_master
blobebd867f496a37865ee78a8590a1aa315e96b0568
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.
27 # SNMP Infos
28 # .1.3.6.1.2.1.1 System description
29 # .1.3.6.1.4.1.35491.30.2.0 No of Sensors - max. 100
30 # .1.3.6.1.4.1.35491.30.3 Sensor Group1
32 # 11 values per sensor
33 # .1.3.6.1.4.1.35491.30.3.1.1.0 Sensor 1 ID
34 # .1.3.6.1.4.1.35491.30.3.1.2.0 Sensor 1 value
35 # .1.3.6.1.4.1.35491.30.3.1.3.0 Sensor 1 unit
36 # .1.3.6.1.4.1.35491.30.3.1.4.0 Sensor 1 valueint -> value *1000, without comma
37 # .1.3.6.1.4.1.35491.30.3.1.5.0 Sensor 1 name
38 # .1.3.6.1.4.1.35491.30.3.1.6.0 Sensor 1 alarmint
39 # -1 = no value (also digi-input and output)
40 # 1 = lower critical alarm or green area (on digi-input)
41 # 2 = lower warning
42 # 3 = normal
43 # 4 = upper warning
44 # 5 = upper critical or red area (on digi-input)
45 # .1.3.6.1.4.1.35491.30.3.1.7.0 Sensor 1 LoLimitAlarmInt
46 # .1.3.6.1.4.1.35491.30.3.1.8.0 Sensor 1 LoLimitWarnInt
47 # .1.3.6.1.4.1.35491.30.3.1.9.0 Sensor 1 HiLimitWarnInt
48 # .1.3.6.1.4.1.35491.30.3.1.10.0 Sensor 1 HiLimitAlarmInt
49 # .1.3.6.1.4.1.35491.30.3.1.11.0 Sensor 1 HysterInt
51 # .1.3.6.1.4.1.35491.30.3.2.1.0 Sensor 2 ID
52 # .
53 # .
54 # .
55 # Here a List of known sensors
56 # sensors_ids = {
57 # 20: ("digital", "Schloss"),
58 # 22: ("digital", "Relaisadapter AC"),
59 # 23: ("digital", "Digitalausgang"),
60 # 24: ("digital", "Steckdosenleiste"),
61 # 38: ("digital", "Transponderleser"),
62 # 39: ("digital", "Tastatur"),
63 # 50: ("analog", "Temperatursensor"),
64 # 51: ("digital", "Digitaleingang"),
65 # 60: ("analog", "Feuchtesensor"),
66 # 61: ("digital", "Netzspannungs Messadapter"),
67 # 62: ("digital", "Sauerstoffsensor"),
68 # 63: ("analog", "Analogsensor"),
69 # 64: ("digital", "Wechselstromzaehler"),
70 # 70: ("digital", "Zugangssensor (Tuerkontakt)"),
71 # 71: ("digital", "Erschuetterungssensor"),
72 # 72: ("digital", "Rauchmelder"),
73 # 80: ("digital", "LHX 20 RS232"),
74 # }
75 # also only one sensor group is supported with this plugin!
78 def parse_security_master(info):
79 supported_sensors = {
80 50: "temp",
81 60: "humidity",
82 72: "smoke",
85 parsed = {}
86 for value in supported_sensors.itervalues():
87 parsed[value] = {}
89 for oid, sensor in info[0]:
90 if ".5.0" not in str(oid):
91 continue
93 sensor_num = saveint(oid.split(".")[0])
94 service_name = "%d %s" % (sensor_num, sensor)
95 num = oid.split(".")[0]
96 value, sensor_id, warn_low, warn_high, crit_low, crit_high, alarm = (None,) * 7
98 for oid_second, sensor_second in info[0]:
99 if num + ".1.0" == oid_second:
100 sensor_id = saveint(sensor_second[0].encode('hex'))
101 elif num + ".2.0" == oid_second:
102 try:
103 value = float(sensor_second)
104 except ValueError:
105 pass
106 elif num + ".6.0" == oid_second:
107 try:
108 alarm = int(sensor_second)
109 except ValueError:
110 alarm = -1
111 elif num + ".7.0" == oid_second:
112 crit_low = savefloat(saveint(sensor_second) / 1000.)
113 elif num + ".8.0" == oid_second:
114 warn_low = savefloat(saveint(sensor_second) / 1000.)
115 elif num + ".9.0" == oid_second:
116 warn_high = savefloat(saveint(sensor_second) / 1000.)
117 elif num + ".10.0" == oid_second:
118 crit_high = savefloat(saveint(sensor_second) / 1000.)
120 if sensor_id in supported_sensors.keys():
121 parsed[supported_sensors[sensor_id]][service_name] = {
122 'name': sensor,
123 'value': value,
124 'id': sensor_id,
125 'levels_low': (warn_low, crit_low),
126 'levels': (warn_high, crit_high),
127 'alarm': alarm,
130 return parsed
133 def inventory_security_master_sensors(parsed, sensor_type):
134 for sensor in parsed[sensor_type]:
135 yield sensor, {}
138 def check_security_master(item, _no_params, parsed):
139 sensor = parsed['smoke'].get(item)
140 if not sensor:
141 return 3, "Sensor no found in SNMP output"
143 if sensor['alarm'] == 99:
144 return 3, "Smoke Sensor is not ready or bus element removed"
146 value = sensor['value']
147 if value == 0:
148 status, msg = 0, "No Smoke"
149 elif value == 1:
150 status, msg = 2, "Smoke detected"
151 else:
152 status, msg = 3, "No Value for Sensor"
154 return status, msg
157 check_info["security_master"] = {
158 'parse_function': parse_security_master,
159 'check_function': check_security_master,
160 'inventory_function': lambda parsed: inventory_security_master_sensors(parsed, "smoke"),
161 'service_description': 'Sensor %s',
162 'snmp_info': [('.1.3.6.1.4.1.35491.30', [OID_END, '3']),],
163 'snmp_scan_function': lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith("1.3.6.1.4.1.35491"),
164 'has_perfdata': False,
167 # .--humidity------------------------------------------------------------.
168 # | _ _ _ _ _ |
169 # | | |__ _ _ _ __ ___ (_) __| (_) |_ _ _ |
170 # | | '_ \| | | | '_ ` _ \| |/ _` | | __| | | | |
171 # | | | | | |_| | | | | | | | (_| | | |_| |_| | |
172 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
173 # | |___/ |
174 # '----------------------------------------------------------------------'
177 def check_security_master_humidity(item, params, parsed):
178 sensor = parsed['humidity'].get(item)
179 if not sensor:
180 return 3, "Sensor not found in SNMP output"
182 if sensor['alarm'] is not None and sensor['alarm'] > -1:
183 if not params.get("levels"):
184 params['levels'] = sensor.get('levels')
186 if not params.get("levels_lower"):
187 params['levels_lower'] = sensor.get('levels_low')
189 return check_humidity(sensor['value'], params)
192 check_info["security_master.humidity"] = {
193 'inventory_function': lambda parsed: inventory_security_master_sensors(parsed, "humidity"),
194 'check_function': check_security_master_humidity,
195 'service_description': 'Sensor %s',
196 'has_perfdata': True,
197 'group': 'humidity',
198 'includes': ['humidity.include'],
201 # .--temp----------------------------------------------------------------.
202 # | _ |
203 # | | |_ ___ _ __ ___ _ __ |
204 # | | __/ _ \ '_ ` _ \| '_ \ |
205 # | | || __/ | | | | | |_) | |
206 # | \__\___|_| |_| |_| .__/ |
207 # | |_| |
208 # '----------------------------------------------------------------------'
210 factory_settings['security_master_temp_default_levels'] = {
211 "device_levels_handling": "worst", # this variable is required, in order to define,
212 # which status limits are used, also 'levels' are
213 # added via WATO, if needed
217 def check_security_master_temperature(item, params, parsed):
218 sensor = parsed['temp'].get(item)
219 if not sensor:
220 return 3, "Sensor not found in SNMP output"
222 sensor_value = sensor['value']
223 if sensor_value is None:
224 return 3, "Sensor value is not in SNMP-WALK"
226 return check_temperature(
227 reading=sensor_value,
228 unique_name=item,
229 params=params,
230 dev_unit="c",
231 dev_levels=sensor['levels'],
232 dev_levels_lower=sensor['levels_low'])
235 check_info['security_master.temp'] = {
236 'inventory_function': lambda parsed: inventory_security_master_sensors(parsed, "temp"),
237 'check_function': check_security_master_temperature,
238 'service_description': 'Sensor %s',
239 'has_perfdata': True,
240 'group': 'temperature',
241 'includes': ['temperature.include'],
242 'default_levels_variable': 'security_master_temp_default_levels',