Cleanup config.nodes_of
[check_mk.git] / checks / ucs_c_rack_server_psu
blobd1dbd2c2f1d105da57511cc97e7014d0792aa345
1 #!/usr/bin/env python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2019 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 # exemplary output of special agent agent_ucs_bladecenter (<TAB> is tabulator):
29 # <<<ucs_c_rack_server_psu:sep(9)>>>
30 # equipmentPsu<TAB>dn sys/rack-unit-1/psu-1<TAB>id 1<TAB>model blabla<TAB>operability operable<TAB>voltage upper-critical
31 # equipmentPsu<TAB>dn sys/rack-unit-1/psu-2 <TAB>id 2<TAB>model blabla<TAB>operability inoperable<TAB>voltage ok
34 def parse_ucs_c_rack_server_psu(info):
35 """
36 Returns dict with indexed PSUs mapped to keys and operability, voltage values mapped to dicts.
37 """
38 parsed = {}
39 for psu in info:
40 try:
41 key_value_pairs = [kv.split(" ", 1) for kv in psu[1:]]
42 psu = key_value_pairs[0][1].replace("sys/", "").replace("rack-unit-",
43 "Rack Unit ").replace(
44 "/psu-", " PSU ")
45 parsed[psu] = {
46 'operability': key_value_pairs[3][1],
47 'voltage': key_value_pairs[4][1],
49 except IndexError:
50 continue # skip info line in case agent output is incomplete or invalid
51 return parsed
54 def inventory_ucs_c_rack_server_psu(parsed):
55 """
56 Yields indexed PSUs as items (e.g. Rack Unit 1 PSU 1).
57 """
58 for key in parsed.keys():
59 yield key, {}
62 #########################
63 # ucs_c_rack_server_psu #
64 #########################
67 @get_parsed_item_data
68 def check_ucs_c_rack_server_psu(item, _no_params, data):
69 # maps XML API v2.0 XML entity values to check function status values
70 operability_to_status_mapping = {
71 "unknown": 3,
72 "operable": 0,
73 "inoperable": 2,
74 "degraded": 2,
75 "powered-off": 1,
76 "power-problem": 2,
77 "removed": 1,
78 "voltage-problem": 2,
79 "thermal-problem": 2,
80 "performance-problem": 2,
81 "accessibility-problem": 2,
82 "identity-unestablishable": 1,
83 "bios-post-timeout": 1,
84 "disabled": 1,
85 "malformed-fru": 1,
86 "fabric-conn-problem": 2,
87 "fabric-unsupported-conn": 1,
88 "config": 1,
89 "equipment-problem": 2,
90 "decomissioning": 1,
91 "chassis-limit-exceeded": 1,
92 "not-supported": 1,
93 "discovery": 1,
94 "discovery-failed": 1,
95 "identify": 1,
96 "post-failure": 1,
97 "upgrade-problem": 1,
98 "peer-comm-problem": 2,
99 "auto-upgrade": 1,
101 operability = data["operability"]
102 try:
103 status = operability_to_status_mapping[operability]
104 status_readable = operability
105 except KeyError:
106 status = 3
107 status_readable = "unknown[%s]" % operability
108 yield status, "Status: %s" % status_readable
111 check_info["ucs_c_rack_server_psu"] = {
112 'parse_function': parse_ucs_c_rack_server_psu,
113 'inventory_function': inventory_ucs_c_rack_server_psu,
114 'check_function': check_ucs_c_rack_server_psu,
115 'service_description': 'Output Power %s',
118 #################################
119 # ucs_c_rack_server_psu.voltage #
120 #################################
123 @get_parsed_item_data
124 def check_ucs_c_rack_server_psu_voltage(item, _no_params, data):
125 # maps XML API v2.0 XML entity values to check function status values
126 voltage_to_status_mapping = {
127 "unknown": 3,
128 "ok": 0,
129 "upper-non-recoverable": 2,
130 "upper-critical": 2,
131 "upper-non-critical": 1,
132 "lower-non-critical": 1,
133 "lower-critical": 2,
134 "lower-non-recoverable": 2,
135 "not-supported": 1,
137 voltage_status = data["voltage"]
138 try:
139 status = voltage_to_status_mapping[voltage_status]
140 status_readable = voltage_status
141 except KeyError:
142 status = 3
143 status_readable = "unknown[%s]" % voltage_status
144 yield status, "Status: %s" % status_readable
147 check_info["ucs_c_rack_server_psu.voltage"] = {
148 'inventory_function': inventory_ucs_c_rack_server_psu,
149 'check_function': check_ucs_c_rack_server_psu_voltage,
150 'service_description': 'Output Voltage %s',