/usr/share/check_mk/checks/etherbox is in check-mk-server 1.2.6p12-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# The etherbox supports the following sensor types on each port
# sensor types
# 0 = no sensor
# 1 = temperature - implemented
# 2 = brightness
# 3 = humidity - implemented
# 4 = switch contact - implemented
# 5 = voltage detector
# 6 = smoke sensor - implemented
# Note: The short contact config option in the etherbox is of type switch contact
# The short contact status is set for 15 seconds after a button press
# TODO: insert missing snmp output
def etherbox_convert(info):
sensor_data = []
for i in range(0, len(info[1])):
sensor_data.append((info[1][i][1], info[2][i][1], info[3][i][1], info[4][i][1] ))
return sensor_data
def inventory_etherbox(info, req_sensor_type):
inventory = []
sensor_data = etherbox_convert(info)
for index, name, sensor_type, value in sensor_data:
# Ignore not connected Temperature Sensors
if sensor_type == '1' and value == '0':
continue
if sensor_type == req_sensor_type:
inventory.append( ("%s.%s" % (index, sensor_type), None) )
return inventory
def etherbox_get_sensor(item, item_type, info):
sensor_data = etherbox_convert(info)
item_index, item_type = item.split(".")
for index, name, sensor_type, value in sensor_data:
if index == item_index:
if sensor_type != item_type:
raise Exception("Sensor type changed %s" % item)
return name, value
raise Exception("Sensor not found")
def etherbox_scan(oid):
return oid(".1.3.6.1.4.1.14848.2.1.1.1.0").startswith("Version")
etherbox_info = [
( ".1.3.6.1.4.1.14848.2.1.1.3", [ '' ]), # temperature unit
( ".1.3.6.1.4.1.14848.2.1.2.1.1", [ OID_END, '' ]), # index
( ".1.3.6.1.4.1.14848.2.1.2.1.2", [ OID_END, '' ]), # name
( ".1.3.6.1.4.1.14848.2.1.2.1.3", [ OID_END, '' ]), # type
( ".1.3.6.1.4.1.14848.2.1.2.1.5", [ OID_END, '' ]), # value * 10
]
def check_etherbox_temp(item, params, info):
try:
name, value = etherbox_get_sensor(item, "1", info)
except Exception, error:
return 3, error.message
uom = { "0": "°C", "1": "°F", "2": "K" }[info[0][0][0]]
state = 0
temp = int(value) / 10.0
levels_text = ""
if params:
warn, crit = params
levels_text = " (warn/crit at %.1f/%.1f %s)" % (warn, crit, uom)
if temp > crit:
state = 2
elif temp > warn:
state = 1
else:
warn, crit = None, None
perfdata = [ ("temp", temp, warn, crit) ]
infotext = "%s: Temperature %.1f %s %s" % (name, temp, uom, levels_text)
return (state, infotext, perfdata)
check_info["etherbox.temp"] = {
"check_function" : check_etherbox_temp,
"inventory_function" : lambda x: inventory_etherbox(x, "1"),
"service_description" : "Sensor %s",
"has_perfdata" : True,
"group" : "room_temperature",
"snmp_scan_function" : etherbox_scan,
"snmp_info" : etherbox_info,
}
def check_etherbox_humidity(item, params, info):
try:
name, value = etherbox_get_sensor(item, "3", info)
except Exception, error:
return 3, error.message
state = 0
temp = int(value) / 10.0
levels_info = ""
if params:
crit_low, warn_low, warn_high, crit_high = params
levels_info = " (low levels at %.1f/%.1f %%RH / high levels at %.1f/%.1f %%RH )" %\
(crit_low, warn_low, warn_high, crit_high)
if temp <= crit_low:
state = 2
elif temp >= crit_high:
state = 2
elif temp <= warn_low:
state = 1
elif temp >= warn_high:
state = 1
else:
crit_low, warn_low, warn_high, crit_high = None, None, None, None
perfdata = [ ("humidity", temp, crit_low, warn_low, warn_high, crit_high) ]
infotext = "%s: Humidity %.1f %%RH %s" % (name, temp, levels_info)
return (state, infotext, perfdata)
check_info["etherbox.humidity"] = {
"check_function" : check_etherbox_humidity,
"inventory_function" : lambda x: inventory_etherbox(x, "3"),
"service_description" : "Sensor %s",
"has_perfdata" : True,
"group" : "humidity",
"snmp_scan_function" : etherbox_scan,
"snmp_info" : etherbox_info,
}
def check_etherbox_switch_contact(item, params, info):
try:
name, value = etherbox_get_sensor(item, "4", info)
except Exception, error:
return 3, error.message
state = 0
perfdata = [ ("switch_contact", value) ]
switch_state = value == "1000" and "open" or "closed"
state = 0
extra_info = ""
if params and params != "ignore":
if switch_state != params:
state = 2
extra_info = ", should be %s" % params
infotext = "%s: Switch contact %s%s" % (name, switch_state, extra_info)
return (state, infotext, perfdata)
check_info["etherbox.switch"] = {
"check_function" : check_etherbox_switch_contact,
"inventory_function" : lambda x: inventory_etherbox(x, "4"),
"service_description" : "Sensor %s",
"group" : "switch_contact",
"has_perfdata" : True,
"snmp_scan_function" : etherbox_scan,
"snmp_info" : etherbox_info,
}
def check_etherbox_smoke(item, no_params, info):
try:
name, value = etherbox_get_sensor(item, "6", info)
except Exception, error:
return 3, error.message
state = 0
perfdata = [ ("smoke", value) ]
extra_info = ""
if value != "0":
extra_info = " - Smoke alarm!"
state = 2
return (state, "%s: Smoke sensor%s" % (name, extra_info), perfdata)
check_info["etherbox.smoke"] = {
"check_function" : check_etherbox_smoke,
"inventory_function" : lambda x: inventory_etherbox(x, "6"),
"service_description" : "Sensor %s",
"has_perfdata" : True,
"snmp_scan_function" : etherbox_scan,
"snmp_info" : etherbox_info,
}
|