2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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--
40 # --DISKS IN VOLUME: Vol1 --
44 # Disk Type: SATA Disk
50 # Serial Number: AB-CDEF123456
55 # Disk Type: SATA Disk
61 # Serial Number: AB-CDEF123457
65 # split output into the --xxx-- sections
66 def parse_rstcli_sections(info
):
67 current_section
= None
69 if line
[0].startswith("--"):
70 if current_section
is not None:
72 current_section
= (":".join(line
).strip("-").strip(), [])
74 # On some systems, there are lines that only consist of
75 # a contextless 0. Skip those to avoid parsing errors later.
78 if current_section
is None:
79 raise MKGeneralException("error: %s" % " ".join(line
))
80 current_section
[1].append(line
)
85 # interpret the volumes section
86 def parse_rstcli_volumes(rows
):
92 volumes
[row
[1].strip()] = current_volume
= {}
94 current_volume
[row
[0]] = row
[1].strip()
99 # interpret the disks section
100 def parse_rstcli_disks(rows
):
107 disks
.append(current_disk
)
109 current_disk
[row
[0]] = row
[1].strip()
114 def parse_rstcli(info
):
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])
124 raise MKGeneralException("invalid section in rstcli output: %s" % section
[0])
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?
139 def check_rstcli(item
, params
, 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
)
165 return 3, "unsupported item name"
167 volume
, disk_id
= match
.group(1), match
.group(2)
169 disks
= parsed
.get(volume
, {}).get('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',