Cleanup config.nodes_of
[check_mk.git] / checks / postfix_mailq
blob630ac0e0e2d4f9a5503dc4ba0c0b288070431d78
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 # Author: Lars Michelsen <lm@mathias-kettner.de>
29 # Example output from agent:
31 # <<<postfix_mailq>>>
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.
45 # **************
47 # <<<postfix_mailq>>>
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:)
56 # <<<postfix_mailq>>>
57 # 8BITMIME (Deferred: Connection refused by mail.gargl.com.)
58 # <franz@gargle.com>
59 # q1L4ovDO002485 3176 Tue Feb 21 05:50 MAILER-DAEMON
60 # (Deferred: 451 Try again later)
61 # <wrdlpfrmpft@karl-valentin.com>
62 # Total requests: 2
64 # **************
65 # new format
66 # <<<postfix_mailq>>>
67 # QUEUE_deferred 60 1
68 # QUEUE_active 4 0
70 # new format multi-instance
71 # <<<postfix_mailq>>>
72 # [[[/etc/postfix-external]]]
73 # QUEUE_deferred 0 0
74 # QUEUE_active 0 0
75 # <<<postfix_mailq>>>
76 # [[[/etc/postfix-internal]]]
77 # QUEUE_deferred 0 0
78 # QUEUE_active 0 0
80 factory_settings['postfix_mailq_default_levels'] = {
81 "deferred": (10, 20),
82 "active": (200, 300), # may become large for big mailservers
86 def postfix_mailq_to_bytes(value, uom):
87 uom = uom.lower()
88 if uom == 'kbytes':
89 return value * 1024
90 elif uom == 'mbytes':
91 return value * 1024 * 1024
92 elif uom == 'gbytes':
93 return value * 1024 * 1024 * 1024
96 def parse_postfix_mailq(info):
97 parsed = {}
98 instance_name = ""
99 for line in info:
100 if line[0].startswith("[[[") and line[0].endswith("]]]"):
101 instance_name = line[0][3:-3]
103 queueinfo = None
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
108 if len(line) == 2:
109 size = 0
110 length = int(line[1]) # number of mails
111 else:
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:']:
121 if line[0] == '--':
122 size = postfix_mailq_to_bytes(float(line[1]), line[2])
123 length = int(line[4])
124 else:
125 size = 0
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)
134 return parsed
137 def inventory_postfix_mailq(parsed):
138 for queue in parsed:
139 yield queue, {}
142 def check_postfix_mailq(item, params, parsed):
143 if item is None:
144 item = ""
146 if item not in parsed:
147 yield 3, "Item not found"
148 return
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"]:
157 state = 0
158 infotext = "%s queue length: %d" % (what.title(), length)
160 if what in ["deferred", "mail"]:
161 length_var = "length"
162 size_var = "size"
163 else:
164 length_var = "mail_queue_active_length"
165 size_var = "mail_queue_active_size"
167 if crit is not None and length >= crit:
168 state = 2
169 infotext += " (warn/crit at %d/%d)" % (warn, crit)
170 elif warn is not None and length >= warn:
171 state = 1
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,