Refactored snapin server_time to new snapin API
[check_mk.git] / checks / zpool_status
blob32c0b16707b4011ad8157fb3223be62b53588ef6
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 # 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 # ---------------------------------
38 # no pools available
39 # ---------------------------------
41 # Example output of a pool with a error
42 # ---------------------------------
43 # pool: snapshots
44 # state: ONLINE
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
51 # config:
53 # NAME STATE READ WRITE CKSUM
54 # snapshots ONLINE 0 0 0
55 # raidz1 ONLINE 0 0 0
56 # c0d0s7 ONLINE 0 0 0
57 # c0d1s7 ONLINE 0 0 0
58 # c1d0s7 ONLINE 0 0 0
59 # c1d1s7 ONLINE 0 0 1
61 # errors: No known data errors
62 # ---------------------------------
65 def inventory_zpool_status(info):
66 if not info or " ".join(info[0]) == "no pools available":
67 return []
68 return [(None, None)]
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"
77 start_pool = False
78 multiline = False
79 last_pool = None
80 error_pools = {}
81 warning_pools = {}
82 pool_messages = {}
83 message = []
84 state = 0
86 for line in info:
87 if line[0] == "pool:":
88 last_pool = line[1]
89 pool_messages.setdefault(last_pool, [])
90 continue
92 if line[0] == "state:":
93 if line[1] == "ONLINE":
94 state = 0
95 elif line[1] == "DEGRADED":
96 state = 1
97 message.append("DEGRADED State")
98 elif line[1] == "FAULTED":
99 state = 2
100 message.append("FAULTED State")
101 elif line[1] == "UNAVIL":
102 state = 2
103 message.append("UNAVIL State")
104 elif line[1] == "REMOVED":
105 state = 2
106 message.append("REMOVED State")
107 elif line[1] == "OFFLINE":
108 state = 0
109 else:
110 message.append("Unknown State")
111 state = 1
112 continue
114 if line[0] in ["status:", "action:"]:
115 pool_messages[last_pool].append(" ".join(line[1:]))
116 multiline = True
117 continue
119 if line[0] in ["scrub:", "see:", "scan:", "config:"]:
120 multiline = False
121 continue
123 if line[0] == "NAME":
124 multiline = False
125 start_pool = True
126 continue
128 if line[0] == "errors:":
129 multiline = False
130 start_pool = False
131 msg = " ".join(line[1:])
132 if msg != 'No known data errors':
133 pool_messages[last_pool].append(msg)
134 continue
136 if line[0] in ["spares", "logs", "cache"]:
137 start_pool = False
138 continue
140 if start_pool is True:
141 if line[1] != "ONLINE":
142 error_pools[line[0]] = tuple(line[1:])
143 continue
145 if saveint(line[4]) != 0:
146 warning_pools[line[0]] = tuple(line[1:])
147 continue
149 if multiline:
150 pool_messages[last_pool].append(" ".join(line))
151 continue
153 for pool, msg in pool_messages.iteritems():
154 state = 1
155 message.append("%s: %s" % (pool, " ".join(msg)))
157 for pool, msg in warning_pools.iteritems():
158 state = 1
159 message.append("%s CKSUM: %d" % (pool, saveint(msg[3])))
161 for pool, msg in error_pools.iteritems():
162 state = 2
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',