Cleanup config.nodes_of
[check_mk.git] / checks / hp_proliant_psu
blob2b59cb4a5260bf8827d853f66d65aa14079032de
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 condition_map = {
28 '1': ('other', 3), # the status could not be determined or not present.
29 '2': ('ok', 0), # operating normally
30 '3': ('degraded', 2), # component is outside of normal operating range.
31 '4': ('failed', 2), # component detects condition that could damage system
34 factory_settings["hp_proliant_psu_levels"] = {
35 "levels": (80, 90),
39 def parse_hp_proliant_psu(info):
40 parsed = {}
41 Psu = collections.namedtuple("Psu", ['chassis', 'bay', 'condition', 'used', 'max'])
42 for chassis, bay, present, cond, used, capacity_maximum in info:
43 if present != '3' or capacity_maximum == '0':
44 continue
45 item = "%s/%s" % (chassis, bay)
46 try:
47 parsed[item] = Psu(chassis, bay, cond, int(used), int(capacity_maximum))
48 except ValueError:
49 pass
50 if parsed:
51 PsuTotal = collections.namedtuple("Psu", ['used', 'max'])
52 parsed['Total'] = PsuTotal(
53 sum(v.used for v in parsed.values()), sum(v.max for v in parsed.values()))
54 return parsed
57 def inventory_hp_proliant_psu(parsed):
58 """Inventorizes all present PSUs, as well as the Sum over all PSUs"""
59 for item in parsed:
60 yield item, None
63 @get_parsed_item_data
64 def check_hp_proliant_psu(item, params, psu):
65 if item != 'Total':
66 yield 0, "Chassis %s/Bay %s" % (psu.chassis, psu.bay)
67 snmp_state, status = condition_map[psu.condition]
68 yield status, 'State: "%s"' % snmp_state
70 # usage info
71 info = 'Usage: %d Watts' % psu.used
72 cap_perc = psu.used * 100 / psu.max
73 perf_data = [
74 ('power_usage_percentage', cap_perc),
75 ('power_usage', psu.used),
78 # check for user defined thresholds here
79 warn, crit = params["levels"]
80 msg = " (warn/crit at %s/%s)" % (warn, crit)
81 if cap_perc > crit:
82 yield 2, info + msg, perf_data
83 elif cap_perc > warn:
84 yield 1, info + msg, perf_data
85 else:
86 yield 0, info, perf_data
89 check_info["hp_proliant_psu"] = {
90 'check_function': check_hp_proliant_psu,
91 'inventory_function': inventory_hp_proliant_psu,
92 'parse_function': parse_hp_proliant_psu,
93 'default_levels_variable': "hp_proliant_psu_levels",
94 'service_description': 'HW PSU %s',
95 'group': 'hw_psu',
96 'snmp_info': (
97 ".1.3.6.1.4.1.232.6.2.9.3.1",
99 "1", # cpqHeFltTolPowerSupplyChassis
100 "2", # cpqHeFltTolPowerSupplyBay
101 "3", # cpqHeFltTolPowerSupplyPresent
102 "4", # cpqHeFltTolPowerSupplyCondition
103 "7", # cpqHeFltTolPowerSupplyCapacityUsed
104 "8", # cpqHeFltTolPowerSupplyCapacityMaximum
106 'snmp_scan_function': lambda oid: "proliant" in oid(".1.3.6.1.4.1.232.2.2.4.2.0", "").lower(),
107 'has_perfdata': True,