Cleanup config.nodes_of
[check_mk.git] / checks / rstcli
blob244fdbb648bd53cb68b9a0d034872465358b1183
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 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 # --VOLUME INFORMATION--
29 # Name: Vol1
30 # Raid Level: 1
31 # Size: 932 GB
32 # StripeSize: 64 KB
33 # Num Disks: 2
34 # State: Normal
35 # System: True
36 # Initialized: True
37 # Cache Policy: Off
40 # --DISKS IN VOLUME: Vol1 --
42 # ID: 0-0-0-0
43 # Type: Disk
44 # Disk Type: SATA Disk
45 # State: Normal
46 # Size: 932 GB
47 # Free Size: 0 GB
48 # System Disk: False
49 # Usage: Array member
50 # Serial Number: AB-CDEF123456
51 # Model: AB CD EF
53 # ID: 0-1-0-0
54 # Type: Disk
55 # Disk Type: SATA Disk
56 # State: Normal
57 # Size: 932 GB
58 # Free Size: 0 GB
59 # System Disk: False
60 # Usage: Array member
61 # Serial Number: AB-CDEF123457
62 # Model: AB CD EF
65 # split output into the --xxx-- sections
66 def parse_rstcli_sections(info):
67 current_section = None
68 for line in info:
69 if line[0].startswith("--"):
70 if current_section is not None:
71 yield current_section
72 current_section = (":".join(line).strip("-").strip(), [])
73 elif len(line) < 2:
74 # On some systems, there are lines that only consist of
75 # a contextless 0. Skip those to avoid parsing errors later.
76 continue
77 else:
78 if current_section is None:
79 raise MKGeneralException("error: %s" % " ".join(line))
80 current_section[1].append(line)
82 yield current_section
85 # interpret the volumes section
86 def parse_rstcli_volumes(rows):
87 volumes = {}
88 current_volume = None
90 for row in rows:
91 if row[0] == "Name":
92 volumes[row[1].strip()] = current_volume = {}
93 else:
94 current_volume[row[0]] = row[1].strip()
96 return volumes
99 # interpret the disks section
100 def parse_rstcli_disks(rows):
101 disks = []
102 current_disk = None
104 for row in rows:
105 if row[0] == "ID":
106 current_disk = {}
107 disks.append(current_disk)
109 current_disk[row[0]] = row[1].strip()
111 return disks
114 def parse_rstcli(info):
115 volumes = {}
117 for section in parse_rstcli_sections(info):
118 if section[0] == "VOLUME INFORMATION":
119 volumes = parse_rstcli_volumes(section[1])
120 elif section[0].startswith("DISKS IN VOLUME"):
121 volume = section[0].split(":")[1].strip()
122 volumes[volume]['Disks'] = parse_rstcli_disks(section[1])
123 else:
124 raise MKGeneralException("invalid section in rstcli output: %s" % section[0])
126 return volumes
129 def inventory_rstcli(parsed):
130 return [(name, None) for name in parsed.keys()]
133 # Help! There is no documentation, what are the possible values?
134 rstcli_states = {
135 'Normal': 0,
139 def check_rstcli(item, params, parsed):
140 if item in parsed:
141 volume = parsed[item]
142 return rstcli_states.get(volume['State']), "RAID %s, %d disks (%s), state %s" % \
143 (volume['Raid Level'], int(volume['Num Disks']),
144 volume['Size'], volume['State'])
147 check_info["rstcli"] = {
148 'check_function': check_rstcli,
149 'inventory_function': inventory_rstcli,
150 'parse_function': parse_rstcli,
151 'service_description': 'RAID Volume %s',
155 def inventory_rstcli_pdisks(parsed):
156 for key, volume in parsed.iteritems():
157 for disk in volume['Disks']:
158 yield "%s/%s" % (key, disk['ID']), None
161 def check_rstcli_pdisks(item, params, parsed):
162 reg = regex(r"(.*)/([0-9\-]*)")
163 match = reg.match(item)
164 if not match:
165 return 3, "unsupported item name"
167 volume, disk_id = match.group(1), match.group(2)
169 disks = parsed.get(volume, {}).get('Disks', [])
170 for disk in disks:
171 if disk['ID'] == disk_id:
172 infotext = "%s (unit: %s, size: %s, type: %s, model: %s, serial: %s)" % \
173 (disk['State'], volume, disk['Size'], disk['Disk Type'],
174 disk['Model'], disk['Serial Number'])
175 return rstcli_states.get(disk['State'], 2), infotext
178 check_info["rstcli.pdisks"] = {
179 'check_function': check_rstcli_pdisks,
180 'inventory_function': inventory_rstcli_pdisks,
181 'service_description': 'RAID Disk %s',