Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / elphase.include
blobbae1813324e1c7ca5465888f37687d5d672f40e6
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.
28 def inventory_elphase(parsed):
29 for item in parsed.keys():
30 yield item, {}
33 # Parsed has the following form:
34 # parsed = {
35 # "Phase 1" : {
36 # "device_state" : (1, "warning"), # overall device state: state, state readable
37 # "voltage" : (220.17, (1, "Voltage is too low")), # with device state
38 # "current" : 12.0, # without device state
39 # }
40 # }
41 def check_elphase(item, params, parsed):
42 if item not in parsed:
43 return # Item not found in SNMP data
45 def tostring(value):
46 if isinstance(value, int):
47 return "%d" % value
48 return "%.1f" % value
50 class Bounds(object):
51 Lower, Upper, Both = range(3)
53 if params is None:
54 params = {}
56 if "device_state" in parsed[item]:
57 device_state, device_state_readable = parsed[item]["device_state"]
58 if params.get("map_device_states", []):
59 device_state_params = dict(params["map_device_states"])
60 if device_state in device_state_params:
61 state = device_state_params[device_state]
62 elif device_state_readable in device_state_params:
63 state = device_state_params[device_state_readable]
64 else:
65 state = 0
66 else:
67 state = device_state
68 yield state, "Device status: %s(%s)" % (device_state_readable, device_state)
70 for what, title, unit, bound, factor in [
71 ("voltage", "Voltage", " V", Bounds.Lower, 1),
72 ("current", "Current", " A", Bounds.Upper, 1),
73 ("output_load", "Load", "%", Bounds.Upper, 1),
74 ("power", "Power", " W", Bounds.Upper, 1),
75 ("appower", "Apparent Power", " VA", Bounds.Upper, 1),
76 ("energy", "Energy", " Wh", Bounds.Upper, 1),
77 ("frequency", "Frequency", " hz", Bounds.Both, 1),
78 ("differential_current_ac", "Differential current AC", " mA", Bounds.Upper, 0.001),
79 ("differential_current_dc", "Differential current DC", " mA", Bounds.Upper, 0.001),
82 if what in parsed[item]:
83 entry = parsed[item][what]
84 if isinstance(entry, tuple):
85 value, state_info = entry # (220.17, (1, "Voltage is too low"))
86 else:
87 value = entry # 12.0
88 state_info = None
90 infotext = "%s: %s%s" % (title, tostring(value), unit)
91 status = 0
92 perfdata = [(what, value * factor)]
94 if what in params:
95 warn_lower = crit_lower = warn = crit = None
96 if bound == Bounds.Both:
97 warn_lower, crit_lower, warn, crit = params[what]
98 elif bound == Bounds.Upper:
99 warn, crit = params[what]
100 else: # Bounds.Lower
101 warn_lower, crit_lower = params[what]
103 if warn_lower:
104 levelstext = " (warn/crit below %s/%s%s)" %\
105 (tostring(warn_lower), tostring(crit_lower), unit)
106 if value < crit_lower:
107 status = 2
108 infotext += levelstext
109 elif value < warn_lower:
110 status = max(status, 1)
111 infotext += levelstext
113 if warn:
114 levelstext = " (warn/crit at %s/%s%s)" %\
115 (tostring(warn), tostring(crit), unit)
116 if value > crit:
117 status = 2
118 infotext += levelstext
119 elif value > warn:
120 status = max(status, 1)
121 infotext += levelstext
123 perfdata = [(what, value * factor, warn * factor, crit * factor)]
125 yield status, infotext, perfdata
127 if state_info:
128 yield state_info