Refactoring: Moved rules from unsorted.py to matching modules (CMK-1393)
[check_mk.git] / cmk / gui / plugins / wato / check_parameters / fileinfo-groups.py
blobf27de26f6bc92d4cc684dccf7ef0092a3bebd793
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 from cmk.gui.i18n import _
28 from cmk.gui.valuespec import (
29 Age,
30 CascadingDropdown,
31 Dictionary,
32 Filesize,
33 Integer,
34 ListOf,
35 ListOfTimeRanges,
36 MonitoringState,
37 TextAscii,
38 Transform,
39 Tuple,
41 from cmk.gui.plugins.wato import (
42 RulespecGroupCheckParametersStorage,
43 register_check_parameters,
44 register_rule,
47 register_rule(
48 RulespecGroupCheckParametersStorage,
49 varname="fileinfo_groups",
50 title=_('File Grouping Patterns'),
51 help=_('The check <tt>fileinfo</tt> monitors the age and size of '
52 'a single file. Each file information that is sent '
53 'by the agent will create one service. By defining grouping '
54 'patterns you can switch to the check <tt>fileinfo.groups</tt>. '
55 'That check monitors a list of files at once. You can set levels '
56 'not only for the total size and the age of the oldest/youngest '
57 'file but also on the count. You can define one or several '
58 'patterns for a group containing <tt>*</tt> and <tt>?</tt>, for example '
59 '<tt>/var/log/apache/*.log</tt>. Please see Python\'s fnmatch for more '
60 'information regarding globbing patterns and special characters. '
61 'If the pattern begins with a tilde then this pattern is interpreted as '
62 'a regular expression instead of as a filename globbing pattern and '
63 '<tt>*</tt> and <tt>?</tt> are treated differently. '
64 'For files contained in a group '
65 'the discovery will automatically create a group service instead '
66 'of single services for each file. This rule also applies when '
67 'you use manually configured checks instead of inventorized ones. '
68 'Furthermore, the current time/date in a configurable format '
69 'may be included in the include pattern. The syntax is as follows: '
70 '$DATE:format-spec$ or $YESTERDAY:format-spec$, where format-spec '
71 'is a list of time format directives of the unix date command. '
72 'Example: $DATE:%Y%m%d$ is todays date, e.g. 20140127. A pattern '
73 'of /var/tmp/backups/$DATE:%Y%m%d$.txt would search for .txt files '
74 'with todays date as name in the directory /var/tmp/backups. '
75 'The YESTERDAY syntax simply subtracts one day from the reference time.'),
76 valuespec=ListOf(
77 Tuple(
78 help=_("This defines one file grouping pattern."),
79 show_titles=True,
80 orientation="horizontal",
81 elements=[
82 TextAscii(
83 title=_("Name of group"),
84 size=10,
86 Transform(
87 Tuple(
88 show_titles=True,
89 orientation="vertical",
90 elements=[
91 TextAscii(title=_("Include Pattern"), size=40),
92 TextAscii(title=_("Exclude Pattern"), size=40),
95 forth=lambda params: isinstance(params, str) and (params, '') or params),
98 add_label=_("Add pattern group"),
100 match='all',
103 register_check_parameters(
104 RulespecGroupCheckParametersStorage,
105 "fileinfo-groups",
106 _("Size, age and count of file groups"),
107 Dictionary(
108 elements=[
109 ("minage_oldest",
110 Tuple(
111 title=_("Minimal age of oldest file"),
112 elements=[
113 Age(title=_("Warning if younger than")),
114 Age(title=_("Critical if younger than")),
115 ])),
116 ("maxage_oldest",
117 Tuple(
118 title=_("Maximal age of oldest file"),
119 elements=[
120 Age(title=_("Warning if older than")),
121 Age(title=_("Critical if older than")),
122 ])),
123 ("minage_newest",
124 Tuple(
125 title=_("Minimal age of newest file"),
126 elements=[
127 Age(title=_("Warning if younger than")),
128 Age(title=_("Critical if younger than")),
129 ])),
130 ("maxage_newest",
131 Tuple(
132 title=_("Maximal age of newest file"),
133 elements=[
134 Age(title=_("Warning if older than")),
135 Age(title=_("Critical if older than")),
136 ])),
137 ("minsize_smallest",
138 Tuple(
139 title=_("Minimal size of smallest file"),
140 elements=[
141 Filesize(title=_("Warning if below")),
142 Filesize(title=_("Critical if below")),
143 ])),
144 ("maxsize_smallest",
145 Tuple(
146 title=_("Maximal size of smallest file"),
147 elements=[
148 Filesize(title=_("Warning if above")),
149 Filesize(title=_("Critical if above")),
150 ])),
151 ("minsize_largest",
152 Tuple(
153 title=_("Minimal size of largest file"),
154 elements=[
155 Filesize(title=_("Warning if below")),
156 Filesize(title=_("Critical if below")),
157 ])),
158 ("maxsize_largest",
159 Tuple(
160 title=_("Maximal size of largest file"),
161 elements=[
162 Filesize(title=_("Warning if above")),
163 Filesize(title=_("Critical if above")),
164 ])),
165 ("minsize",
166 Tuple(
167 title=_("Minimal size"),
168 elements=[
169 Filesize(title=_("Warning if below")),
170 Filesize(title=_("Critical if below")),
171 ])),
172 ("maxsize",
173 Tuple(
174 title=_("Maximal size"),
175 elements=[
176 Filesize(title=_("Warning if above")),
177 Filesize(title=_("Critical if above")),
178 ])),
179 ("mincount",
180 Tuple(
181 title=_("Minimal file count"),
182 elements=[
183 Integer(title=_("Warning if below")),
184 Integer(title=_("Critical if below")),
185 ])),
186 ("maxcount",
187 Tuple(
188 title=_("Maximal file count"),
189 elements=[
190 Integer(title=_("Warning if above")),
191 Integer(title=_("Critical if above")),
192 ])),
193 ("timeofday",
194 ListOfTimeRanges(
195 title=_("Only check during the following times of the day"),
196 help=_("Outside these ranges the check will always be OK"),
198 ("conjunctions",
199 ListOf(
200 Tuple(elements=[
201 MonitoringState(title=_("Monitoring state"), default_value=2),
202 ListOf(
203 CascadingDropdown(
204 orientation="hroizontal",
205 choices=[
206 ("count", _("File count at"), Integer()),
207 ("count_lower", _("File count below"), Integer()),
208 ("size", _("File size at"), Filesize()),
209 ("size_lower", _("File size below"), Filesize()),
210 ("largest_size", _("Largest file size at"), Filesize()),
211 ("largest_size_lower", _("Largest file size below"), Filesize()),
212 ("smallest_size", _("Smallest file size at"), Filesize()),
213 ("smallest_size_lower", _("Smallest file size below"), Filesize()),
214 ("oldest_age", _("Oldest file age at"), Age()),
215 ("oldest_age_lower", _("Oldest file age below"), Age()),
216 ("newest_age", _("Newest file age at"), Age()),
217 ("newest_age_lower", _("Newest file age below"), Age()),
219 magic="@#@#",
222 title=_("Level conjunctions"),
223 help=
224 _("In order to check dependent file group statistics you can configure "
225 "conjunctions of single levels now. A conjunction consists of a monitoring state "
226 "and any number of upper or lower levels. If all of the configured levels within "
227 "a conjunction are reached then the related state is reported."),
230 ignored_keys=["precompiled_patterns"]),
231 TextAscii(
232 title=_("File Group Name"),
233 help=_(
234 "This name must match the name of the group defined "
235 "in the <a href=\"wato.py?mode=edit_ruleset&varname=fileinfo_groups\">%s</a> ruleset.")
236 % (_('File Grouping Patterns')),
237 allow_empty=True),
238 match_type="dict",