Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / janitza_umg
blob3f4764f219836b0741ddee9327952d76af554cf6
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # 508 and 604 have the same mib
28 janitza_umg_device_map = {
29 ".1.3.6.1.4.1.34278.8.6": "96",
30 ".1.3.6.1.4.1.34278.10.1": "604",
31 ".1.3.6.1.4.1.34278.10.4": "508",
35 def parse_janitza_umg_inphase(info):
36 def flatten(line):
37 return [x[0] for x in line]
39 dev_type = janitza_umg_device_map[info[0][0][0]]
41 info_offsets = {
42 "508": {
43 "energy": 4,
44 "sumenergy": 5,
45 "misc": 8,
47 "604": {
48 "energy": 4,
49 "sumenergy": 5,
50 "misc": 8,
52 "96": {
53 "energy": 3,
54 "sumenergy": 4,
55 "misc": 6,
57 }[dev_type]
59 rmsphase = flatten(info[1])
60 sumphase = flatten(info[2])
61 energy = flatten(info[info_offsets["energy"]])
62 sumenergy = flatten(info[info_offsets["sumenergy"]])
64 if dev_type in ["508", "604"]:
65 num_phases = 4
66 num_currents = 4
67 elif dev_type == "96":
68 num_phases = 3
69 num_currents = 6
71 # the number of elements in each "block" within the snmp. This differs between
72 # devices
73 counts = [
74 num_phases, # voltages
75 3, # L1-L2, L2-L3, L3-L1
76 num_currents, # umg96 reports voltage for 3 phases and current for 6
77 num_phases, # real power
78 num_phases, # reactive power
79 num_phases, # Power in VA
80 num_phases, # Cos(Phi)
83 def offset(block_id, phase):
84 return sum(counts[:block_id], phase)
86 # voltages are in 100mv, currents in 1mA, power in Watts / VA
87 result = {}
89 for phase in range(num_phases):
90 result["Phase %d" % (phase + 1)] = {
91 "voltage": int(rmsphase[offset(0, phase)]) / 10.0,
92 "current": int(rmsphase[offset(2, phase)]) / 1000.0,
93 "power": int(rmsphase[offset(3, phase)]),
94 "appower": int(rmsphase[offset(5, phase)]),
95 "energy": int(energy[phase]) / 10,
98 result["Total"] = {"power": int(sumphase[0]), "energy": int(sumenergy[0])}
100 misc = flatten(info[info_offsets["misc"]])
101 result["Frequency"] = int(misc[0])
102 # temperature not present in UMG508 and UMG604
103 if len(misc) > 1:
104 result["Temperature"] = map(int, misc[1:])
105 else:
106 result["Temperature"] = []
107 return result
110 def inventory_janitza_umg_inphase(parsed):
111 for item in parsed.keys():
112 if item.startswith("Phase"):
113 yield item, {}
116 check_info['janitza_umg'] = {
117 'parse_function': parse_janitza_umg_inphase,
118 'inventory_function': inventory_janitza_umg_inphase,
119 'check_function': check_elphase,
120 'service_description': 'Input %s',
121 'has_perfdata': True,
122 'default_levels_variable': 'janitza_umg_inphase_default_levels',
123 'includes': ["elphase.include",],
124 'group': 'el_inphase',
125 'snmp_info': [
126 (".1.3.6.1.2.1.1.2", ["0"]), # device id
127 (".1.3.6.1.4.1.34278", ["1"]), # rmsPhase
128 (".1.3.6.1.4.1.34278", ["2"]), # rmsSum
129 (".1.3.6.1.4.1.34278", ["3"]), # device dependent
130 (".1.3.6.1.4.1.34278", ["4"]), # "
131 (".1.3.6.1.4.1.34278", ["5"]), # "
132 (".1.3.6.1.4.1.34278", ["6"]), # "
133 (".1.3.6.1.4.1.34278", ["7"]), # "
134 (".1.3.6.1.4.1.34278", ["8"]), # "
136 'snmp_scan_function': lambda oid: oid(".1.3.6.1.2.1.1.2.0") in janitza_umg_device_map.keys()
140 def inventory_janitza_umg_freq(parsed):
141 # info[0] is frequency, info[1] is first temperature reading, info[2] is second.
142 if "Frequency" in parsed:
143 yield "1", {}
146 def check_janitza_umg_freq(item, params, parsed):
147 warn, crit = params.get("levels", (0, 0))
149 if "Frequency" in parsed:
150 reading = float(parsed["Frequency"]) / 100.0
151 perfdata = [("in_freq", reading, warn, crit)]
153 infotext = "Frequency: %.2f Hz" % reading
154 levelstext = "(warn/crit at %d/%d Hz)" % (warn, crit)
156 if reading <= crit:
157 return 2, infotext + " " + levelstext, perfdata
158 elif reading <= warn:
159 return 1, infotext + " " + levelstext, perfdata
160 return 0, infotext, perfdata
163 check_info['janitza_umg.freq'] = {
164 'inventory_function': inventory_janitza_umg_freq,
165 'check_function': check_janitza_umg_freq,
166 'service_description': 'Frequency %s',
167 'has_perfdata': True,
168 'default_levels_variable': 'janitza_umg_freq_default_levels',
169 'group': 'efreq',
173 def inventory_janitza_umg_temp(parsed):
174 ctr = 1
175 for temp in parsed["Temperature"]:
176 if temp != -1000:
177 yield str(ctr), {}
178 ctr += 1
181 def check_janitza_umg_temp(item, params, parsed):
182 idx = int(item) - 1
183 if len(parsed["Temperature"]) > idx:
184 return check_temperature(
185 float(parsed["Temperature"][idx]) / 10.0, params, "janitza_umg_%s" % item)
188 check_info['janitza_umg.temp'] = {
189 'inventory_function': inventory_janitza_umg_temp,
190 'check_function': check_janitza_umg_temp,
191 'service_description': 'Temperature External %s',
192 'has_perfdata': True,
193 'default_levels_variable': 'janitza_umg_temp_default_levels',
194 'includes': ["temperature.include",],
195 'group': 'temperature',