GUI CSS: Removed snapin styles from py modules and added a _snapins.scss for the...
[check_mk.git] / checks / scaleio_mdm
blob1e3447da193b7612a176dba7ead327c9e0f5564a
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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 #<<<scaleio_mdm:sep(44)>>>
28 #Cluster:
29 # Mode: 3_node, State: Normal, Active: 3/3, Replicas: 2/2
30 # Virtual IPs: N/A
31 #Master MDM:
32 # Name: MDM02, ID: 0x028f4e581a749941
33 # IPs: 10.75.9.52, 10.75.10.52, Management IPs: 10.75.0.52, Port: 9011, Virtual IP interfaces: N/A
34 # Version: 2.0.13000
35 #Slave MDMs:
36 # Name: MDM01, ID: 0x1402b04f3ad359c0
37 # IPs: 10.75.10.51, 10.75.9.51, Management IPs: 10.75.0.51, Port: 9011, Virtual IP interfaces: N/A
38 # Status: Normal, Version: 2.0.13000
39 #Tie-Breakers:
40 # Name: TB01, ID: 0x69dd57a10fa1c7b2
41 # IPs: 10.75.10.53, 10.75.9.53, Port: 9011
42 # Status: Normal, Version: 2.0.13000
45 def parse_scaleio_mdm(info):
46 # parsing this section is horrible. But I will guide you...
47 parsed, id_, node = {}, "", ""
48 for line in info:
49 # A subsection starts with one of the following:
50 if line[0].lower() in [ "cluster:", "master mdm:", "slave mdms:", \
51 "tie-breakers:", "standby mdms:"]:
52 id_ = line[0].strip(":")
53 parsed[id_] = {}
54 # The first subsection is different and entries can be parsed
55 # directly. Hooray!
56 elif id_ == "Cluster" and id_ in parsed:
57 nl = [entry.split(': ') for entry in line]
58 for l in nl:
59 parsed[id_][l[0].strip()] = l[1].strip()
60 # The other subsections can have several nodes. Each node
61 # starts with his name and has already some more information.
62 # Sometimes there is information about a role inside of the
63 # cluster. This is handled by the entry "Role"!
64 elif id_ in parsed and "name" in line[0].lower():
65 node = line[0].split(": ")[1]
66 node_id = line[1].split(": ")
68 parsed[id_][node] = {node_id[0].strip(): node_id[1].strip()}
69 if len(line) == 3:
70 parsed[id_][node][u'Role'] = line[2].strip()
71 # Finally we can add the rest of information to a node in a
72 # subsection. When splitting the lines we sometimes get lines
73 # belonging to the last entry. These information is then added
74 # to the last known entry.
75 elif id_ in parsed and node in parsed[id_] and id_ != "Cluster":
76 nl = [entry.split(': ') for entry in line]
77 for l in nl:
78 if len(l) > 1:
79 name = l[0].strip()
80 parsed[id_][node][name] = l[1].strip()
81 else:
82 if not isinstance(parsed[id_][node][name], list):
83 parsed[id_][node][name] = [parsed[id_][node][name]]
84 parsed[id_][node][name].append(l[0].replace(" ", ""))
86 return parsed
89 def inventory_scaleio_mdm(parsed):
90 if parsed.get('Cluster'):
91 yield None, {}
94 def check_scaleio_mdm(item, params, parsed):
95 translate_status = {
96 "Normal": 0,
97 "Degraded": 1,
98 "Error": 2,
99 "Disconnected": 2,
100 "Not synchronized": 1,
103 data = get_scaleio_data("Cluster", parsed)
104 if data:
105 state = 0
106 status = data["State"]
107 active = data["Active"].split("/")
108 replicas = data["Replicas"].split("/")
110 yield translate_status[status], "Mode: %s, State: %s" % (data["Mode"], status)
112 if not active[0] == active[1] or \
113 not replicas[0] == replicas[1]:
114 state = 2
116 yield state, "Active: %s, Replicas: %s" % ("/".join(active), "/".join(replicas))
118 for role in ["Master MDM", "Slave MDMs", "Tie-Breakers", "Standby MDMs"]:
119 state, nodes = 0, []
120 for node in parsed.get(role, {}):
121 nodes.append(node)
122 status = parsed[role][node].get("Status", "Normal")
123 if status != "Normal":
124 state = max(state, translate_status[status])
126 if nodes:
127 infotext = "%s: %s" % (role, ", ".join(nodes))
128 else:
129 if role != "Standby MDMs":
130 state, infotext = 2, "%s not found in agent output" % role
131 else:
132 infotext = "%s: no" % role
134 yield state, infotext
137 check_info['scaleio_mdm'] = {
138 'parse_function': parse_scaleio_mdm,
139 'inventory_function': inventory_scaleio_mdm,
140 'check_function': check_scaleio_mdm,
141 'service_description': 'ScaleIO cluster status',
142 'includes': ['scaleio.include'],