GUI CSS: Deployed view styles for layouts (CMK-1171)
[check_mk.git] / checks / wut_webio_io
blob34af630185bd75dee1fe5dcbe6c786332675ad1b
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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 #SNMP Data for the port that is labeled as "0" on the device and
28 # in the web interface, but "1" in the tables.
29 # .1.3.6.1.4.1.5040.1.2.4.1.3.1.4.1 1 << this is the index
30 # .1.3.6.1.4.1.5040.1.2.4.3.1.5.2.1.1.1 1 << this is the state
31 # .1.3.6.1.4.1.5040.1.2.4.3.2.1.1.1.1 "Stoerung USV" << this is the user descr.
33 webio_state_names = {
34 0: "Off",
35 1: "On",
39 # Parser for the snmp data, hands back a dict with fugded
40 # item name and the state of all ports.
41 # fix the port index. it is off by one. alternatively you could just
42 # fix the nagios state text at check time.
43 # Also do padding with 0, this means we need to handle it as "str"
44 # tbh, there is a way in if.include but it is beyond me how that works.
45 # The max model has 24 ports, so this will work for the current product
46 # range.
47 def parse_webio_io_inputs(info):
48 wut_info = {}
49 for line in info:
50 input_index, input_desc, state = line
51 state = int(state)
52 input_index = str(int(input_index) - 1)
53 if len(input_index) < 2:
54 input_index = "0" + input_index
56 if input_desc.startswith("Input"):
57 input_desc = input_index
58 else:
59 input_desc = input_index + " " + input_desc
60 wut_info.update({input_index: (input_desc, state)})
62 return wut_info
65 def inventory_wut_webio_io_inputs(info):
66 # inventorize the err, things as the parser returned them.
67 return [(val[0], val[1]) for val in parse_webio_io_inputs(info).values()]
70 def check_wut_webio_io_inputs(item, params, info):
71 for val in parse_webio_io_inputs(info).values():
72 if val[0] == item:
73 state = val[1]
75 # Compare to the state of the IO port at inventory.
76 if state != params:
77 return (2, "state should be %s but is %s (!!)" % (webio_state_names[params],
78 webio_state_names[state]))
79 return (0, "state is %s" % webio_state_names[state])
81 return (3, "Item not found in agent output")
84 check_info['wut_webio_io.inputs'] = {
85 "check_function" : check_wut_webio_io_inputs,
86 "inventory_function" : inventory_wut_webio_io_inputs,
87 "service_description": "INPUT %s",
88 "snmp_info" : (".1.3.6.1.4.1.5040.1.2.4", [
89 "3.1.5.2.1.1", # io port index. (bugged)
90 "3.2.1.1.1", # user defined description.
91 "1.3.1.4", # the low/high state.
92 ]),
93 # first check we have a vendor mib from W&T, then check for the model in their MIB.
94 "snmp_scan_function" : lambda oid: \
95 ".1.3.6.1.4.1.5040" in oid(".1.3.6.1.2.1.1.2.0") and \
96 oid(".1.3.6.1.4.1.5040.1.2.4.3.3.5.0") and \
97 oid(".1.3.6.1.4.1.5040.1.2.4.3.3.5.0").lower().startswith("web-io"),