Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / apc_rackpdu_power
blobfdea6742c76dd43a25faf1e99e054e9eaaf3759a
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 # .1.3.6.1.4.1.318.1.1.12.1.1.0 "sf9pdu1" --> PowerNet-MIB::rPDUIdentName.0
28 # .1.3.6.1.4.1.318.1.1.12.1.9.0 1 --> PowerNet-MIB::rPDUIdentDeviceNumPhases.0
29 # .1.3.6.1.4.1.318.1.1.12.1.16.0 0 --> PowerNet-MIB::rPDUIdentDevicePowerWatts.0
30 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 160 --> PowerNet-MIB::rPDULoadStatusLoad.1 (measured in tenths of Amps)
31 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.3.1 1 --> PowerNet-MIB::rPDULoadStatusLoadState.1
33 # .1.3.6.1.4.1.318.1.1.12.1.1.0 FOOBAR --> PowerNet-MIB::rPDUIdentName.0
34 # .1.3.6.1.4.1.318.1.1.12.1.9.0 1 --> PowerNet-MIB::rPDUIdentDeviceNumPhases.0$
35 # .1.3.6.1.4.1.318.1.1.12.1.16.0 1587 --> PowerNet-MIB::rPDUIdentDevicePowerWatts.0
36 # .1.3.6.1.4.1.318.1.1.12.2.1.4.0 2 --> PowerNet-MIB::rPDULoadDevNumBanks.0
37 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 0 --> PowerNet-MIB::rPDULoadStatusLoad.1
38 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.2 0 --> PowerNet-MIB::rPDULoadStatusLoad.2
39 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.3 0 --> PowerNet-MIB::rPDULoadStatusLoad.3
40 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.3.1 1 --> PowerNet-MIB::rPDULoadStatusLoadStates.1
41 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.3.2 1 --> PowerNet-MIB::rPDULoadStatusLoadStates.2
42 # .1.3.6.1.4.1.318.1.1.12.2.3.1.1.3.3 1 --> PowerNet-MIB::rPDULoadStatusLoadStates.3
44 # examples num phase/banks: 1/0, => parsed = device phase
45 # 1/2, => parsed = device phase + 2 banks
46 # 3/0 => parsed = device phase + 3 phases
49 def parse_apc_rackpdu_power(info):
50 def get_status_info(amperage_str, device_state):
51 return float(amperage_str) / 10, {
52 "1": (0, "load normal"),
53 "2": (2, "load low"),
54 "3": (1, "load near over load"),
55 "4": (2, "load over load"),
56 }[device_state]
58 parsed = {}
59 device_info, bank_info, phase_info = info
60 pdu_ident_name, power_str = device_info[0]
61 device_name = "Device %s" % pdu_ident_name
63 parsed.setdefault(device_name, {"power": float(power_str)})
65 if len(device_info) == len(phase_info):
66 parsed[device_name]["current"] = get_status_info(*phase_info[0][1:])
67 return parsed
69 if int(bank_info[0][0]):
70 parsed[device_name]["current"] = get_status_info(*phase_info[0][1:])
71 phase_info = phase_info[1:]
72 name_part = "Bank"
73 else:
74 name_part = "Phase"
76 for oid_end, amperage_str, device_state in phase_info:
77 parsed.setdefault("%s %s" % (name_part, oid_end),
78 {"current": get_status_info(amperage_str, device_state)})
80 return parsed
83 check_info["apc_rackpdu_power"] = {
84 'parse_function' : parse_apc_rackpdu_power,
85 'inventory_function' : inventory_elphase,
86 'check_function' : check_elphase,
87 'service_description' : 'PDU %s',
88 'has_perfdata' : True,
89 'snmp_info' : [('.1.3.6.1.4.1.318.1.1.12.1', [
90 '1', # PowerNet-MIB::rPDUIdentName
91 '16', # PowerNet-MIB::rPDUIdentDevicePowerWatts
92 ]),
93 ('.1.3.6.1.4.1.318.1.1.12.2.1', [
94 '4', # PowerNet-MIB::rPDULoadDevNumBanks
95 ]),
96 ('.1.3.6.1.4.1.318.1.1.12.2.3.1.1', [
97 OID_END,
98 '2', # PowerNet-MIB::rPDULoadStatusLoad
99 '3', # PowerNet-MIB::rPDULoadStatusLoadState
100 ])],
101 'snmp_scan_function' : lambda oid: oid(".1.3.6.1.2.1.1.1.0").lower().startswith("apc web/snmp")\
102 and oid(".1.3.6.1.4.1.318.1.1.12.1.*"),
103 'group' : 'el_inphase',
104 'includes' : [ 'elphase.include' ],