Cleanup config.nodes_of
[check_mk.git] / checks / emcvnx.include
blobe2e8f37cb3666eef81b2532f331e032d20bf5292
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.
28 def preparse_emcvnx_info(info):
29 def convert(value):
30 try:
31 return int(value)
32 except ValueError:
33 try:
34 return float(value)
35 except ValueError:
36 pass
37 return value
39 preparsed, errors, skip_lines = [], set(), 0
40 for line in info:
41 line = [x.strip() for x in line]
42 if len(line) == 1:
43 key, value = line[0], None
44 else:
45 # the value can contain the separator ':'
46 key, value = line[0], ':'.join(line[1:])
48 # fix naviseccli error that does not output a colon for some values
49 if value is None and (key.startswith('SP Read Cache State') or
50 key.startswith('SP Write Cache State')):
51 tmp = key.split()
52 key, value = ' '.join(tmp[:-1]), tmp[-1]
54 if key.startswith('Error'):
55 skip_lines, error = 1, []
56 elif key.startswith('Unable to validate the identity of the server'):
57 # assumes that certificate errors are always 10 lines long
58 skip_lines, error = 10, []
60 if not skip_lines:
61 if key.startswith('---'): # remove headline
62 preparsed.pop()
63 continue
64 elif value is None: # append in case of a line continuation
65 value = key
66 old_key, old_value = preparsed[-1]
67 preparsed[-1] = (old_key, ', '.join([old_value, value]))
68 elif not value: # remove subheader
69 continue
70 else:
71 preparsed.append((key, convert(value)))
72 else:
73 error.append(': '.join(line))
75 if skip_lines == 1:
76 errors.add(' '.join(error))
77 skip_lines -= 1
79 return preparsed, list(errors)