Cleanup config.nodes_of
[check_mk.git] / checks / veritas_vcs
blob098c484713ecfa813b9aea1981986cdc469ee515
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # <<<veritas_vcs>>>
28 # ClusState RUNNING
29 # ClusterName minions
30 # #System Attribute Value
31 # dave SysState RUNNING
32 # stuart SysState RUNNING
33 # #Group Attribute System Value
34 # ClusterService State stuart |OFFLINE|
35 # nepharius State stuart |ONLINE|
36 # lan State stuart |ONLINE|
37 # omd State stuart |ONLINE|
38 # #Resource Attribute System Value
39 # nepharius_mrs State stuart ONLINE
40 # nepharius_dr State stuart ONLINE
41 # cs_ip State stuart OFFLINE
42 # cs_proxy State stuart ONLINE
43 # lan_nic State stuart ONLINE
44 # lan_phantom State stuart ONLINE
45 # omd_apache State stuart ONLINE
46 # omd_appl State stuart ONLINE
47 # omd_dg State stuart ONLINE
48 # omd_proxy State stuart ONLINE
49 # omd_srdf State stuart ONLINE
50 # omd_uc4ps1_agt State stuart ONLINE
51 # omdp_ip State stuart ONLINE
52 # omdp_mnt State stuart ONLINE
53 # #Group Attribute System Value
54 # ClusterService Frozen global 0
55 # ClusterService TFrozen global 0
56 # #
57 # nepharius Frozen global 0
58 # nepharius TFrozen global 1
59 # #
60 # lan Frozen global 0
61 # lan TFrozen global 0
62 # #
63 # omd Frozen global 1
64 # omd TFrozen global 0
66 # parsed in case above (single node):
67 # parsed = {
68 # 'cluster': {u'minions': [(None, u'ClusState', u'RUNNING', None)]},
69 # u'group': {u'ClusterService': [(None, u'State', u'OFFLINE', u'minions'),
70 # (None, u'Frozen', u'0', u'minions'),
71 # (None, u'TFrozen', u'0', u'minions')],
72 # u'lan': [(None, u'State', u'ONLINE', u'minions'),
73 # (None, u'Frozen', u'0', u'minions'),
74 # (None, u'TFrozen', u'0', u'minions')],
75 # u'nepharius': [(None, u'State', u'ONLINE', u'minions'),
76 # (None, u'Frozen', u'0', u'minions'),
77 # (None, u'TFrozen', u'1', u'minions')],
78 # u'omd': [(None, u'State', u'ONLINE', u'minions'),
79 # (None, u'Frozen', u'1', u'minions'),
80 # (None, u'TFrozen', u'0', u'minions')]},
81 # u'resource': {u'cs_ip': [(None, u'State', u'OFFLINE', u'minions')],
82 # u'cs_proxy': [(None, u'State', u'ONLINE', u'minions')],
83 # u'lan_nic': [(None, u'State', u'ONLINE', u'minions')],
84 # u'lan_phantom': [(None, u'State', u'ONLINE', u'minions')],
85 # u'nepharius_dr': [(None, u'State', u'ONLINE', u'minions')],
86 # u'nepharius_mrs': [(None, u'State', u'ONLINE', u'minions')],
87 # u'omd_apache': [(None, u'State', u'ONLINE', u'minions')],
88 # u'omd_appl': [(None, u'State', u'ONLINE', u'minions')],
89 # u'omd_dg': [(None, u'State', u'ONLINE', u'minions')],
90 # u'omd_proxy': [(None, u'State', u'ONLINE', u'minions')],
91 # u'omd_srdf': [(None, u'State', u'ONLINE', u'minions')],
92 # u'omd_uc4ps1_agt': [(None, u'State', u'ONLINE', u'minions')],
93 # u'omdp_ip': [(None, u'State', u'ONLINE', u'minions')],
94 # u'omdp_mnt': [(None, u'State', u'ONLINE', u'minions')]},
95 # u'system': {u'dave': [(None, u'SysState', u'RUNNING', u'minions')],
96 # u'stuart': [(None, u'SysState', u'RUNNING', u'minions')]}}
99 # parsed in case of Check_MK cluster definition:
100 # parsed = {
101 # "cluster" : {u'minions' : [('server-1', 'State', 'RUNNING', None),
102 # ('server-2', 'State', 'OFFLINE', None),]},
103 # "resource": {u'cs-ip': [('server-1', 'State', 'ONLINE', u'minions'),
104 # ('server-2', 'State', 'OFFLINE', u'minions'),]},
105 # "group": {...},
106 # "system": {...},
109 # Possible values for ClusState: RUNNING
110 # Possible values for SysState: RUNNING, FAULTED, EXITED
111 # Possible values for SG State: ONLINE, OFFLINE, FAULTED
112 # Possible values for resource State: ONLINE, OFFLINE, FAULTED, OFFLINE|STATE UNKNOWN, ONLINE|STATE UNKNOWN
113 # the STATE UNKNOWN is treated as UNKNOWN
115 # NOTE: It seems to me there are way more possible values.
116 # In the older version, all of these go to WARN(1).
117 # We keep it that way, but make it configurable.
119 factory_settings['veritas_vcs_defaults'] = {
120 'map_frozen': {
121 'tfrozen': 1,
122 'frozen': 2,
124 'map_states': {
125 "ONLINE": 0,
126 "RUNNING": 0,
127 "OK": 0,
128 "OFFLINE": 1,
129 "EXITED": 1,
130 "PARTIAL": 1,
131 "FAULTED": 2,
132 "UNKNOWN": 3,
133 "default": 1,
138 def parse_veritas_vcs(info):
139 parsed = {}
140 Vcs = collections.namedtuple("Vcs", ["node", "attr", "value", "cluster"])
142 for line in info:
143 if len(line) == 2 and line[1] == '#':
144 continue
145 node = line[0]
147 if line[1] == "ClusState":
148 section = parsed.setdefault('cluster', {})
149 attr = line[1]
150 value = line[2]
152 elif line[1] == "ClusterName":
153 cluster_name = line[2]
154 section.setdefault(cluster_name, []).append(Vcs(node, attr, value, None))
156 elif line[1].startswith('#'):
157 section = parsed.setdefault(line[1][1:].lower(), {})
158 attr_idx = line.index('Attribute')
159 value_idx = line.index('Value')
161 elif len(line) > 3:
162 item_name = line[1]
163 attr = line[attr_idx]
164 value = line[value_idx].replace("|", "")
165 if "UNKNOWN" in value:
166 value = "UNKNOWN"
167 section.setdefault(item_name, []).append(Vcs(node, attr, value, cluster_name))
169 return parsed
172 def veritas_vcs_boil_down_states_in_cluster(states):
173 _stat = set(states)
174 if len(_stat) == 1:
175 return _stat.pop()
176 for dominant in ("FAULTED", "UNKNOWN", "ONLINE", "RUNNING"):
177 if dominant in _stat:
178 return dominant
179 return "AGGREGATION: %s" % ', '.join(_stat)
182 def inventory_veritas_vcs(parsed, item_type):
183 for item_name in parsed[item_type]:
184 yield item_name, None
187 def check_veritas_vcs(item, params, parsed, item_type):
188 data = parsed.get(item_type, {}).get(item)
189 if data is None:
190 return # vanished
192 map_frozen = params['map_frozen']
193 map_states = params['map_states']
195 def fmt(node, string):
196 temp = "%s: %%s" % node if node else "%s"
197 txt = temp % string.lower()
198 return txt[0].upper() + txt[1:]
200 infotexts = []
201 for vcs in data:
202 if vcs.attr.endswith('State'):
203 infotexts.append(fmt(vcs.node, vcs.value))
205 if vcs.attr.endswith('Frozen') and vcs.value != '0':
206 frozen_txt = vcs.attr.lower().replace('t', 'temporarily ')
207 yield map_frozen.get(vcs.attr.lower(), 3), fmt(vcs.node, frozen_txt)
209 states = (vcs.value for vcs in data if vcs.attr.endswith('State'))
210 state_txt = veritas_vcs_boil_down_states_in_cluster(states)
211 state = map_states.get(state_txt, map_states['default'])
213 yield state, "%s" % ", ".join(infotexts)
215 # get last not None cluster name
216 cluster_name = reduce(lambda x, y: y if y.cluster else x, data).cluster
217 if cluster_name is not None:
218 yield 0, "Cluster: %s" % cluster_name
221 def veritas_vcs_get_check_function(item_type):
222 def check_function(item, params, parsed):
223 return check_veritas_vcs(item, params, parsed, item_type)
225 return check_function
228 # .--cluster - main check -----------------------------------------------.
229 # | _ _ |
230 # | ___| |_ _ ___| |_ ___ _ __ |
231 # | / __| | | | / __| __/ _ \ '__| |
232 # | | (__| | |_| \__ \ || __/ | |
233 # | \___|_|\__,_|___/\__\___|_| |
234 # | |
235 # +----------------------------------------------------------------------+
236 # | main check |
237 # '----------------------------------------------------------------------'
239 check_info['veritas_vcs'] = {
240 'group': 'veritas_vcs',
241 'parse_function': parse_veritas_vcs,
242 'inventory_function': lambda parsed: inventory_veritas_vcs(parsed, 'cluster'),
243 'check_function': veritas_vcs_get_check_function("cluster"),
244 'service_description': 'VCS Cluster %s',
245 'node_info': True,
246 'default_levels_variable': 'veritas_vcs_defaults',
250 # .--system--------------------------------------------------------------.
251 # | _ |
252 # | ___ _ _ ___| |_ ___ _ __ ___ |
253 # | / __| | | / __| __/ _ \ '_ ` _ \ |
254 # | \__ \ |_| \__ \ || __/ | | | | | |
255 # | |___/\__, |___/\__\___|_| |_| |_| |
256 # | |___/ |
257 # '----------------------------------------------------------------------'
259 check_info['veritas_vcs.system'] = {
260 'group': 'veritas_vcs',
261 'inventory_function': lambda parsed: inventory_veritas_vcs(parsed, "system"),
262 'check_function': veritas_vcs_get_check_function("system"),
263 'service_description': 'VCS System %s',
264 'node_info': True,
265 'default_levels_variable': 'veritas_vcs_defaults',
269 # .--service group-------------------------------------------------------.
270 # | _ |
271 # | ___ ___ _ ____ _(_) ___ ___ __ _ _ __ ___ _ _ _ __ |
272 # | / __|/ _ \ '__\ \ / / |/ __/ _ \ / _` | '__/ _ \| | | | '_ \ |
273 # | \__ \ __/ | \ V /| | (_| __/ | (_| | | | (_) | |_| | |_) | |
274 # | |___/\___|_| \_/ |_|\___\___| \__, |_| \___/ \__,_| .__/ |
275 # | |___/ |_| |
276 # '----------------------------------------------------------------------'
278 check_info['veritas_vcs.servicegroup'] = {
279 'group': 'veritas_vcs',
280 'inventory_function': lambda parsed: inventory_veritas_vcs(parsed, 'group'),
281 'check_function': veritas_vcs_get_check_function('group'),
282 'service_description': 'VCS Service Group %s',
283 'node_info': True,
284 'default_levels_variable': 'veritas_vcs_defaults',
288 # .--resource------------------------------------------------------------.
289 # | |
290 # | _ __ ___ ___ ___ _ _ _ __ ___ ___ |
291 # | | '__/ _ \/ __|/ _ \| | | | '__/ __/ _ \ |
292 # | | | | __/\__ \ (_) | |_| | | | (_| __/ |
293 # | |_| \___||___/\___/ \__,_|_| \___\___| |
294 # | |
295 # '----------------------------------------------------------------------'
297 check_info['veritas_vcs.resource'] = {
298 'group': 'veritas_vcs',
299 'inventory_function': lambda parsed: inventory_veritas_vcs(parsed, 'resource'),
300 'check_function': veritas_vcs_get_check_function('resource'),
301 'service_description': 'VCS Resource %s',
302 'node_info': True,
303 'default_levels_variable': 'veritas_vcs_defaults',