Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / raritan_pdu_ocprot
blob18f7c2f5399eeb63ff6e561f0394d12ade6ed327
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 raritan_pdu_ocprot_current_default_levels = (14.0, 15.0)
29 # Example for info:
30 # [[[u'1.1.1', u'4', u'0'],
31 # [u'1.1.15', u'1', u'0'],
32 # [u'1.2.1', u'4', u'0'],
33 # [u'1.2.15', u'1', u'0'],
34 # [u'1.3.1', u'4', u'70'],
35 # [u'1.3.15', u'1', u'0'],
36 # [u'1.4.1', u'4', u'0'],
37 # [u'1.4.15', u'1', u'0'],
38 # [u'1.5.1', u'4', u'0'],
39 # [u'1.5.15', u'1', u'0'],
40 # [u'1.6.1', u'4', u'0'],
41 # [u'1.6.15', u'1', u'0']],
42 # [[u'1'],
43 # [u'0'],
44 # [u'1'],
45 # [u'0'],
46 # [u'1'],
47 # [u'0'],
48 # [u'1'],
49 # [u'0'],
50 # [u'1'],
51 # [u'0'],
52 # [u'1'],
53 # [u'0']]]
54 # Raritan implements a strange way of indexing here. The two last components
55 # of the OID should really be swapped!
58 def parse_raritan_pdu_ocprot(info):
59 flattened_info = [[end_oid, state, value, scale]
60 for (end_oid, state, value), (scale,) in zip(info[0], info[1])]
61 parsed = {}
62 for end_oid, state, value, scale in flattened_info:
63 protector_id = "C" + end_oid.split(".")[1] # 1.5.1 --> Item will be "C5"
65 if end_oid.endswith(".15"):
66 parsed.setdefault(protector_id, {})["state"] = state
67 elif end_oid.endswith(".1"):
68 parsed.setdefault(protector_id, {})["current"] = float(value) / pow(10, int(scale))
69 return parsed
72 def inventory_raritan_pdu_ocprot(parsed):
73 for protector_id in parsed:
74 yield protector_id, "raritan_pdu_ocprot_current_default_levels"
77 def check_raritan_pdu_ocprot(item, params, parsed):
78 states = {
79 "-1": (3, "Overcurrent protector information is unavailable"),
80 "0": (2, "Overcurrent protector is open"),
81 "1": (0, "Overcurrent protector is closed"),
84 if item in parsed:
85 yield states[parsed[item]["state"]]
87 current = parsed[item]["current"]
88 warn, crit = params
90 infotext = "Current: %.1f A" % current
91 levelstext = " (warn/crit at %.1f/%.1f A)" % (warn, crit)
93 if current >= crit:
94 status = 2
95 infotext += levelstext
96 elif current >= warn:
97 status = 1
98 infotext += levelstext
99 else:
100 status = 0
102 perfdata = [("current", current, warn, crit)]
103 yield status, infotext, perfdata
106 check_info["raritan_pdu_ocprot"] = {
107 "parse_function": parse_raritan_pdu_ocprot,
108 "inventory_function": inventory_raritan_pdu_ocprot,
109 "check_function": check_raritan_pdu_ocprot,
110 "has_perfdata": True,
111 "service_description": "Overcurrent Protector %s",
112 "group": "ocprot_current",
113 "snmp_info": [(".1.3.6.1.4.1.13742.6.5.3.3.1", [
114 OID_END,
115 "3",
116 "4",
117 ]), (".1.3.6.1.4.1.13742.6.3.4.4.1", ["7"])],
118 "snmp_scan_function": lambda oid: "13742" in oid(".1.3.6.1.2.1.1.2.0"),