Cleanup config.nodes_of
[check_mk.git] / checks / postfix_mailq_status
blob4a74e709b9dc351fabbce07cbe61b1d9c02f5c7b
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2016 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 # single
28 # <<<postfix_mailq_status:sep(58)>>>
29 # postfix/postfix-script: the Postfix mail system is running: PID: 2839
30 # postfix: Postfix is running with backwards-compatible default settings^M postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details^M postfix: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"^M postfix/postfix-script: the Postfix mail system is running: PID: 3096
32 # multi instances
33 # <<<postfix_mailq_status:sep(58)>>>
34 # postfix/postfix-script: the Postfix mail system is running: PID: 12910
35 # postfix-external/postfix-script: the Postfix mail system is running: PID: 12982
36 # postfix-internal/postfix-script: the Postfix mail system is running: PID: 13051
37 # postfix-uat-cdi/postfix-script: the Postfix mail system is not running
40 def parse_postfix_mailq_status(info):
41 parsed = {}
42 for line in info:
43 stripped_line = [x.strip() for x in line]
44 queuename = stripped_line[0].split("/")[0]
45 if queuename == "postfix":
46 queuename = ""
47 parsed.setdefault(queuename, {})
49 state_index = -1
50 if len(stripped_line) > 2 and stripped_line[-2] == "PID":
51 state_index = -3
52 parsed[queuename]["pid"] = stripped_line[-1]
53 parsed[queuename]["state"] = stripped_line[state_index]
55 return parsed
58 def inventory_postfix_mailq_status(parsed):
59 return [(queuename, None) for queuename in parsed]
62 def check_postfix_mailq_status(item, params, parsed):
63 if item in parsed:
64 state_readable = parsed[item]["state"]
65 pid = parsed[item].get("pid")
66 if state_readable.endswith("is running"):
67 state = 0
68 else:
69 state = 2
70 yield state, 'Status: %s' % state_readable
72 if pid:
73 yield 0, 'PID: %s' % pid
76 check_info['postfix_mailq_status'] = {
77 'parse_function': parse_postfix_mailq_status,
78 'inventory_function': inventory_postfix_mailq_status,
79 'check_function': check_postfix_mailq_status,
80 'service_description': 'Postfix status %s',