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 # Example output from old agent until version 1.2.6
30 #root -- 62743228 0 0 0 137561 0 0 0
31 #proxy -- 288648 0 0 0 14370 0 0 0
32 #http -- 208 0 0 0 53 0 0 0
33 #mysql -- 7915856 0 0 0 173 0 0 0
35 # Example output from new agent since version 1.2.8
37 #root -- 62743228 0 0 0 137561 0 0 0
38 #proxy -- 288648 0 0 0 14370 0 0 0
39 #http -- 208 0 0 0 53 0 0 0
40 #mysql -- 7915856 0 0 0 173 0 0 0
42 #root -- 62743228 0 0 0 137561 0 0 0
43 #proxy -- 288648 0 0 0 14370 0 0 0
44 #http -- 208 0 0 0 53 0 0 0
45 #mysql -- 7915856 0 0 0 173 0 0 0
48 def parse_lnx_quota(info
):
54 if line
[0].startswith('[[['):
55 # new filesystem detected
56 parts
= line
[0][3:-3].split(':')
58 # compatible check for old format
59 # was changed in version 1.2.8
64 # new format for check data
67 # new filesystem for quota
68 parsed
.setdefault(fs
, {})
69 parsed
[fs
].setdefault(mode
, {})
71 elif fs
and mode
and len(line
) == 10:
72 # new table entry for quota
73 parsed
[fs
][mode
][line
[0]] = [int(x
) * 1024 for x
in line
[2:5]
74 ] + [int(x
) for x
in line
[5:]]
79 def lnx_quota_limit_check(mode
, what
, user
, used
, soft
, hard
, grace
):
80 fmt
= lambda value
, what
: what
== 'files' and '%d' % value \
81 or get_bytes_human_readable(value
)
84 txt
= 'User %s' % user
86 txt
= 'Group %s' % user
89 # check, if hard limit is exceeded
92 txt
+= ' exceeded space hard limit %s/%s' % (fmt(used
, what
), fmt(hard
, what
))
94 txt
+= ' exceeded file hard limit %s/%s' % (fmt(used
, what
), fmt(hard
, what
))
96 # check, if soft limit is exceeded
99 txt
+= ' exceeded space soft limit %s/%s' % (fmt(used
, what
), fmt(soft
, what
))
100 elif what
== 'files':
101 txt
+= ' exceeded file soft limit %s/%s' % (fmt(used
, what
), fmt(soft
, what
))
104 # check, if grace time is specified
105 if grace
<= time
.time():
106 # check, if it was in grace time
108 txt
+= ', grace time exceeded'
110 # check, if it is in grace time
112 txt
+= ', within grace time'
119 def inventory_lnx_quota(parsed
):
122 for item
in parsed
.keys():
123 inv
.append((item
, {'user': True}))
127 def check_lnx_quota(item
, params
, parsed
):
130 if item
not in parsed
:
131 yield 3, 'Quota info not found for this filesystem'
134 # old discovery until version 1.2.6
135 # params were empty dictionary and enabled by standard user checking
136 params
= {'user': True}
138 for param_key
, thing
, name
in [('user', 'usr', 'users'), ('group', 'grp', 'groups')]:
139 if params
.get(param_key
) is True:
140 at_least_one_problematic
= False
141 for user
, values
in parsed
[item
][thing
].items():
142 for what
, (used
, soft
, hard
, grace
) in [
143 ('blocks', values
[:4]),
144 ('files', values
[4:]),
147 if soft
== 0 and hard
== 0:
148 continue # skip entries without limits
150 state
, txt
= lnx_quota_limit_check(thing
, what
, user
, used
, soft
, hard
, grace
)
152 # Performance data was removed, because the graphing system is not
153 # able to handle such kind of dynamic performance data. Performance
154 # variables were named like group_USERNAME_blocks, group_USERNAME_files,
155 # USERNAME_blocks or USERNAME_files and can appear and disappear in the
157 # Additional the graphs show the performance data like filesystem usage
158 # in the standard logarithmic scale which is not a useful view for the user.
159 #perfdata.append(('%s%s_%s' % (perf_prefix, user, what),
160 # used, soft, hard, 0, hard))
163 at_least_one_problematic
= True
165 #yield state, (txt + ', '), perfdata
168 #yield state, None, perfdata
170 if not at_least_one_problematic
:
171 yield 0, 'All %s within quota limits' % name
173 if params
.get('user') is False and params
.get('group') is False:
174 yield 0, 'Disabled quota checking'
177 check_info
['lnx_quota'] = {
178 'parse_function': parse_lnx_quota
,
179 'check_function': check_lnx_quota
,
180 'inventory_function': inventory_lnx_quota
,
181 'service_description': 'Quota %s',
182 'has_perfdata': True,
183 'group': 'lnx_quota',