2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 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 # The etherbox supports the following sensor types on each port
30 # 1 = temperature - implemented
32 # 3 = humidity - implemented
33 # 4 = switch contact - implemented
34 # 5 = voltage detector
35 # 6 = smoke sensor - implemented
37 # Note: The short contact config option in the etherbox is of type switch contact
38 # The short contact status is set for 15 seconds after a button press
40 # TODO: insert missing snmp output
43 def etherbox_convert(info
):
45 for i
in range(0, len(info
[1])):
46 sensor_data
.append((info
[1][i
][1], info
[2][i
][1], info
[3][i
][1], info
[4][i
][1]))
50 def inventory_etherbox(info
, req_sensor_type
):
51 sensor_data
= etherbox_convert(info
)
52 for index
, _name
, sensor_type
, value
in sensor_data
:
53 # Ignore not connected Temperature Sensors
54 if sensor_type
== '1' and value
== '0':
56 if sensor_type
== req_sensor_type
:
57 yield "%s.%s" % (index
, sensor_type
), None
60 def etherbox_get_sensor(item
, item_type
, info
):
61 sensor_data
= etherbox_convert(info
)
62 item_index
, item_type
= item
.split(".")
63 for index
, name
, sensor_type
, value
in sensor_data
:
64 if index
== item_index
:
65 if sensor_type
!= item_type
:
66 raise Exception("Sensor type changed %s" % item
)
68 raise Exception("Sensor not found")
71 def etherbox_scan(oid
):
72 # Older firmware version of Etherbox do not answer on
73 # .1.3.6.1.2.1. (sysDescr). Yurks. We need to fetch
74 # a vendor specific OID here and wait until all old devices
76 return oid(".1.3.6.1.4.1.14848.2.1.1.1.0", "").startswith("Version")
80 (".1.3.6.1.4.1.14848.2.1.1.3", ['']), # temperature unit
81 (".1.3.6.1.4.1.14848.2.1.2.1.1", [OID_END
, '']), # index
82 (".1.3.6.1.4.1.14848.2.1.2.1.2", [OID_END
, '']), # name
83 (".1.3.6.1.4.1.14848.2.1.2.1.3", [OID_END
, '']), # type
84 (".1.3.6.1.4.1.14848.2.1.2.1.5", [OID_END
, '']), # value * 10
87 # .--temperature---------------------------------------------------------.
89 # | | |_ ___ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
90 # | | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
91 # | | || __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
92 # | \__\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
94 # '----------------------------------------------------------------------'
97 def check_etherbox_temp(item
, params
, info
):
99 name
, value
= etherbox_get_sensor(item
, "1", info
)
100 except Exception, error
:
101 return 3, error
.message
103 uom
= {"0": "c", "1": "f", "2": "k"}[info
[0][0][0]]
104 temp
= int(value
) / 10.0
105 state
, infotext
, perfdata
= check_temperature(temp
, params
, "etherbox_temp_%s" % item
, uom
)
106 return state
, "[%s] %s" % (name
, infotext
), perfdata
109 check_info
["etherbox.temp"] = {
110 "check_function": check_etherbox_temp
,
111 "inventory_function": lambda info
: inventory_etherbox(info
, "1"),
112 "service_description": "Temperature %s",
113 "has_perfdata": True,
114 "group": "temperature",
115 "snmp_scan_function": etherbox_scan
,
116 "snmp_info": etherbox_info
,
117 "includes": ["temperature.include"],
121 # .--humidity------------------------------------------------------------.
123 # | | |__ _ _ _ __ ___ (_) __| (_) |_ _ _ |
124 # | | '_ \| | | | '_ ` _ \| |/ _` | | __| | | | |
125 # | | | | | |_| | | | | | | | (_| | | |_| |_| | |
126 # | |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, | |
128 # '----------------------------------------------------------------------'
131 def check_etherbox_humidity(item
, params
, info
):
133 name
, value
= etherbox_get_sensor(item
, "3", info
)
134 except Exception, error
:
135 return 3, error
.message
137 state
, infotext
, perfdata
= check_humidity(int(value
) / 10.0, params
)
138 return state
, "[%s] %s" % (name
, infotext
), perfdata
141 check_info
["etherbox.humidity"] = {
142 "check_function": check_etherbox_humidity
,
143 "inventory_function": lambda x
: inventory_etherbox(x
, "3"),
144 "service_description": "Sensor %s",
145 "has_perfdata": True,
147 "snmp_scan_function": etherbox_scan
,
148 "snmp_info": etherbox_info
,
149 "includes": ["humidity.include"],
153 # .--switch contact------------------------------------------------------.
155 # | _____ _(_) |_ ___| |__ ___ ___ _ __ | |_ __ _ ___| |_ |
156 # | / __\ \ /\ / / | __/ __| '_ \ / __/ _ \| '_ \| __/ _` |/ __| __| |
157 # | \__ \\ V V /| | || (__| | | | | (_| (_) | | | | || (_| | (__| |_ |
158 # | |___/ \_/\_/ |_|\__\___|_| |_| \___\___/|_| |_|\__\__,_|\___|\__| |
160 # '----------------------------------------------------------------------'
163 def check_etherbox_switch_contact(item
, params
, info
):
165 name
, value
= etherbox_get_sensor(item
, "4", info
)
166 except Exception, error
:
167 return 3, error
.message
170 perfdata
= [("switch_contact", value
)]
171 switch_state
= "open" if value
== "1000" else "closed"
175 if params
and params
!= "ignore":
176 if switch_state
!= params
:
178 extra_info
= ", should be %s" % params
180 infotext
= "[%s] Switch contact %s%s" % (name
, switch_state
, extra_info
)
181 return (state
, infotext
, perfdata
)
184 check_info
["etherbox.switch"] = {
185 "check_function": check_etherbox_switch_contact
,
186 "inventory_function": lambda x
: inventory_etherbox(x
, "4"),
187 "service_description": "Sensor %s",
188 "group": "switch_contact",
189 "has_perfdata": True,
190 "snmp_scan_function": etherbox_scan
,
191 "snmp_info": etherbox_info
,
195 # .--smoke---------------------------------------------------------------.
197 # | ___ _ __ ___ ___ | | _____ |
198 # | / __| '_ ` _ \ / _ \| |/ / _ \ |
199 # | \__ \ | | | | | (_) | < __/ |
200 # | |___/_| |_| |_|\___/|_|\_\___| |
202 # '----------------------------------------------------------------------'
205 def check_etherbox_smoke(item
, no_params
, info
):
207 name
, value
= etherbox_get_sensor(item
, "6", info
)
208 except Exception, error
:
209 return 3, error
.message
212 perfdata
= [("smoke", value
)]
213 infotext
= "Status: OK"
215 infotext
= "Status: smoke alarm"
217 return state
, "[%s] %s" % (name
, infotext
), perfdata
220 check_info
["etherbox.smoke"] = {
221 "check_function": check_etherbox_smoke
,
222 "inventory_function": lambda x
: inventory_etherbox(x
, "6"),
223 "service_description": "Sensor %s",
224 "has_perfdata": True,
225 "snmp_scan_function": etherbox_scan
,
226 "snmp_info": etherbox_info
,