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 # Based on check from Darin Perusich <darin@darins.net>
29 # /usr/sbin/zpool status -x
31 # Example output of a healthy spool
32 # ---------------------------------
33 # all pools are healthy
34 # ---------------------------------
36 # Example output with no poole
37 # ---------------------------------
39 # ---------------------------------
41 # Example output of a pool with a error
42 # ---------------------------------
45 # status: One or more devices has experienced an unrecoverable error. An
46 # attempt was made to correct the error. Applications are unaffected.
47 # action: Determine if the device needs to be replaced, and clear the errors
48 # using 'zpool clear' or replace the device with 'zpool replace'.
49 # see: http://www.sun.com/msg/ZFS-8000-9P
50 # scrub: none requested
53 # NAME STATE READ WRITE CKSUM
54 # snapshots ONLINE 0 0 0
61 # errors: No known data errors
62 # ---------------------------------
65 def inventory_zpool_status(info
):
66 if not info
or " ".join(info
[0]) == "no pools available":
71 def check_zpool_status(_no_item
, _no_params
, info
):
72 if " ".join(info
[0]) == "all pools are healthy":
73 return 0, "All pools are healthy"
74 elif " ".join(info
[0]) == "no pools available":
75 return 3, "No pools available"
87 if line
[0] == "pool:":
89 pool_messages
.setdefault(last_pool
, [])
92 if line
[0] == "state:":
93 if line
[1] == "ONLINE":
95 elif line
[1] == "DEGRADED":
97 message
.append("DEGRADED State")
98 elif line
[1] == "FAULTED":
100 message
.append("FAULTED State")
101 elif line
[1] == "UNAVIL":
103 message
.append("UNAVIL State")
104 elif line
[1] == "REMOVED":
106 message
.append("REMOVED State")
107 elif line
[1] == "OFFLINE":
110 message
.append("Unknown State")
114 if line
[0] in ["status:", "action:"]:
115 pool_messages
[last_pool
].append(" ".join(line
[1:]))
119 if line
[0] in ["scrub:", "see:", "scan:", "config:"]:
123 if line
[0] == "NAME":
128 if line
[0] == "errors:":
131 msg
= " ".join(line
[1:])
132 if msg
!= 'No known data errors':
133 pool_messages
[last_pool
].append(msg
)
136 if line
[0] in ["spares", "logs", "cache"]:
140 if start_pool
is True:
141 if line
[1] != "ONLINE":
142 error_pools
[line
[0]] = tuple(line
[1:])
145 if saveint(line
[4]) != 0:
146 warning_pools
[line
[0]] = tuple(line
[1:])
150 pool_messages
[last_pool
].append(" ".join(line
))
153 for pool
, msg
in pool_messages
.iteritems():
155 message
.append("%s: %s" % (pool
, " ".join(msg
)))
157 for pool
, msg
in warning_pools
.iteritems():
159 message
.append("%s CKSUM: %d" % (pool
, saveint(msg
[3])))
161 for pool
, msg
in error_pools
.iteritems():
163 message
.append("%s state: %s" % (pool
, msg
[0]))
165 if len(message
) == 0:
166 message
= ['No critical errors']
168 return state
, ", ".join(message
)
171 check_info
["zpool_status"] = {
172 'check_function' : check_zpool_status
,
173 'inventory_function' : inventory_zpool_status
,
174 'service_description' : 'zpool status',
175 'group' : 'zpool_status',