GUI CSS: Deployed view styles for layouts (CMK-1171)
[check_mk.git] / checks / ucs_c_rack_server_power
blob9d3fd4ce7e5bbc96131b8a5b87265a99c7a664c8
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 (separator is <TAB> and means tabulator):
29 # <<<ucs_c_rack_server_motherboard_power:sep(9)>>>
30 # computeMbPowerStats<TAB>dn sys/rack-unit-1/board/power-stats<TAB>consumedPower 88<TAB>inputCurrent 6.00<TAB>inputVoltage 12.100
31 # computeMbPowerStats<TAB>dn sys/rack-unit-2/board/power-stats<TAB>consumedPower 88<TAB>inputCurrent 6.00<TAB>inputVoltage 12.100
33 # Default values for consumed power selected according to exemplary monitored real world values
34 # of a rack servers motherboards. Reasonable values for the actual use case depend on the rack
35 # servers configuration (racks used in rack server) and require customization via WATO rule.
36 factory_settings["ucs_c_rack_server_util_power_default_levels"] = {
37 "power_upper_levels": (90, 100),
41 def parse_ucs_c_rack_server_power(info):
42 """
43 Returns dict with indexed rack motherboards mapped to keys and consumed power,
44 input current status and input voltage status as value.
45 """
46 parsed = {}
47 # The element count of info lines is under our control (agent output) and
48 # ensured to have expected length. It is ensured that elements contain a
49 # string. Handles invalid values provided by the XML API which cannot be
50 # casted by setting corresponding values to None.
51 for _, dn, power, current, voltage in info:
52 motherboard = dn.replace("dn ", "").replace("sys/",
53 "").replace("rack-unit-", "Rack Unit ").replace(
54 "/board", "").replace("/power-stats", "")
55 parsed.setdefault(motherboard, {})
56 for ds_key, ds, cast_function in (
57 ('consumedPower', power, int),
58 ('inputCurrent', current, float),
59 ('inputVoltage', voltage, float),
61 try:
62 # Power values are of type int. Current and voltage values are of type float but
63 # converted to int. Hogher accuracy of float is not required.
64 parsed[motherboard][ds_key] = cast_function(ds.replace(ds_key + " ", ""))
65 except ValueError:
66 # The default value set by setdefault is None. These values are handled in the
67 # check function appropriatelly.
68 pass
69 return parsed
72 @get_parsed_item_data
73 def check_ucs_c_rack_server_power(item, params, data):
74 yield check_levels(
75 data["consumedPower"], 'power', params['power_upper_levels'], unit='W', infoname='Power')
76 yield 0, "Current: %s A" % data["inputCurrent"]
77 yield 0, "Voltage: %s V" % data["inputVoltage"]
80 check_info["ucs_c_rack_server_power"] = {
81 'parse_function': parse_ucs_c_rack_server_power,
82 'inventory_function': discover(),
83 'check_function': check_ucs_c_rack_server_power,
84 'group': 'power_multiitem',
85 'service_description': 'Motherboard Power Statistics %s',
86 'default_levels_variable': 'ucs_c_rack_server_util_power_default_levels',
87 'has_perfdata': True,