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 # Author: Lars Michelsen <lm@mathias-kettner.de>
29 # Example output from agent:
32 # -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
33 # CA29995448EB 4638 Fri Jul 2 14:39:01 nagios
34 # donatehosts@mathias-kettner.de
36 # E085095448EC 240 Fri Jul 2 14:40:01 root
37 # lm@mathias-kettner.de
39 # D9EBC95448EE 4804 Fri Jul 2 14:40:03 nagios
40 # donatehosts@mathias-kettner.de
42 # -- 9 Kbytes in 3 Requests.
48 # -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
49 # 748C8C3D4AB 1436 Fri Jul 2 16:39:10 lm@mathias-kettner.de
50 # (connect to mail.larsmichelsen.com[78.46.117.178]:25: Connection refused)
51 # lm@larsmichelsen.com
53 # -- 1 Kbytes in 1 Request.
55 # Yet another one (I believe, this is from sendmail, though:)
57 # 8BITMIME (Deferred: Connection refused by mail.gargl.com.)
59 # q1L4ovDO002485 3176 Tue Feb 21 05:50 MAILER-DAEMON
60 # (Deferred: 451 Try again later)
61 # <wrdlpfrmpft@karl-valentin.com>
70 # new format multi-instance
72 # [[[/etc/postfix-external]]]
76 # [[[/etc/postfix-internal]]]
80 factory_settings
['postfix_mailq_default_levels'] = {
82 "active": (200, 300), # may become large for big mailservers
86 def postfix_mailq_to_bytes(value
, uom
):
91 return value
* 1024 * 1024
93 return value
* 1024 * 1024 * 1024
96 def parse_postfix_mailq(info
):
100 if line
[0].startswith("[[[") and line
[0].endswith("]]]"):
101 instance_name
= line
[0][3:-3]
104 # single and old output formats
105 if line
[0].startswith("QUEUE_"):
106 # Deal with old agent (pre 1.2.8) which did not send size
107 # infos in case of different error cases
110 length
= int(line
[1]) # number of mails
112 size
= int(line
[1]) # in bytes
113 length
= int(line
[2]) # number of mails
115 queueinfo
= line
[0].split("_")[1], size
, length
117 elif " ".join(line
[-2:]) == 'is empty':
118 queueinfo
= "empty", 0, 0
120 elif line
[0] == '--' or line
[0:2] == ['Total', 'requests:']:
122 size
= postfix_mailq_to_bytes(float(line
[1]), line
[2])
123 length
= int(line
[4])
126 length
= int(line
[2])
128 queueinfo
= "mail", size
, length
130 if queueinfo
is not None:
131 parsed
.setdefault(instance_name
, [])
132 parsed
[instance_name
].append(queueinfo
)
137 def inventory_postfix_mailq(parsed
):
142 def check_postfix_mailq(item
, params
, parsed
):
146 if item
not in parsed
:
147 yield 3, "Item not found"
150 if not isinstance(params
, dict):
151 params
= {"deferred": params
}
153 for what
, size
, length
in parsed
[item
]:
154 # In previous check version mail and deferred had same params
155 warn
, crit
= params
.get({"mail": "deferred"}.get(what
, what
), (None, None))
156 if what
in ["active", "deferred", "mail"]:
158 infotext
= "%s queue length: %d" % (what
.title(), length
)
160 if what
in ["deferred", "mail"]:
161 length_var
= "length"
164 length_var
= "mail_queue_active_length"
165 size_var
= "mail_queue_active_size"
167 if crit
is not None and length
>= crit
:
169 infotext
+= " (warn/crit at %d/%d)" % (warn
, crit
)
170 elif warn
is not None and length
>= warn
:
172 infotext
+= " (warn/crit at %d/%d)" % (warn
, crit
)
174 yield state
, infotext
, [(length_var
, length
, warn
, crit
), (size_var
, size
)]
176 elif what
== "empty":
177 yield 0, 'The mailqueue is empty', [('length', 0, warn
, crit
), ('size', 0)]
180 check_info
["postfix_mailq"] = {
181 'parse_function': parse_postfix_mailq
,
182 'inventory_function': inventory_postfix_mailq
,
183 'check_function': check_postfix_mailq
,
184 'service_description': 'Postfix Queue %s',
185 'default_levels_variable': 'postfix_mailq_default_levels',
186 'group': "mail_queue_length",
187 'has_perfdata': True,