GUI CSS: Deployed view styles for layouts (CMK-1171)
[check_mk.git] / checks / ucs_c_rack_server_health
blob05aa57b5959cada2ff3f02a60a3ce5fa4822dd91
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):
28 # storageControllerHealth<TAB>dn
29 # sys/rack-unit-1/board/storage-SAS-SLOT-HBA/vd-0 <TAB>id SLOT-HBA<TAB>health Good
30 # storageControllerHealth<TAB>dn
31 # sys/rack-unit-2/board/storage-SAS-SLOT-HBA/vd-0 <TAB>id SLOT-HBA<TAB>health Good
34 def parse_ucs_c_rack_server_health(info):
35 """
36 Input: list of lists containing storage controller health data on a per rack basis.
37 Output: Returns dict with indexed Rack Units mapped to keys and lowercase health string mapped to value
38 'health' if rack server has racks attached or empty dict if not.
39 """
40 parsed = {}
41 for _, dn, _id, health in info:
42 rack_storage_board = dn.replace("dn sys/", "").replace("rack-unit-", "Rack unit ").replace(
43 "/board/storage-", " Storage ").replace("-", " ").replace("/", " ")
44 parsed[rack_storage_board] = health.replace("health ", "").lower()
45 return parsed
48 def inventory_ucs_c_rack_server_health(parsed):
49 """
50 Input: dict containing items as keys or empty dict.
51 Output: Yields indexed racks and storage controllers as items (e.g. Rack Unit 1 Storage SAS SLOT HBA vd 0) in case parsed contains items.
52 """
53 for key in parsed.iterkeys():
54 yield key, {}
57 @get_parsed_item_data
58 def check_ucs_c_rack_server_health(item, params, health):
59 """
60 Check function is called only in case parsed is a dict and item exists as key in parsed[item].
61 All other potential bad case conditions are handled by @get_parsed_item_data.
62 """
63 # Dict keys are storage controller health strings provided via special agent -> XML
64 # API of servers. Dict values are corresponding check status.
65 # For information about the data provided by the special agent
66 # "storageControllerHealth" refer to Cisco C-Series Rack Server XML 2.0 Schema files:
67 # [https://community.cisco.com/t5/unified-computing-system/cisco-ucs-c-series-standalone-xml-schema/ta-p/3646798]
68 # Note: The possible string values are not defined/documented in the XML schema.
69 # "Good" is the only value known from exemplary data output. Pre-process the
70 # data to lowercase only chars.
71 health_to_status_mapping = {
72 'good': 0,
75 try:
76 status = health_to_status_mapping[health]
77 status_readable = health
78 except KeyError:
79 status = 3
80 status_readable = "unknown[%s]" % health
81 yield status, "Status: %s" % status_readable
84 check_info["ucs_c_rack_server_health"] = {
85 'parse_function': parse_ucs_c_rack_server_health,
86 'inventory_function': inventory_ucs_c_rack_server_health,
87 'check_function': check_ucs_c_rack_server_health,
88 'service_description': 'Health %s',