Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / check_smtp
blob425ff8c0e559be53572c8a90e397f16d9bcd55d7
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.
28 def check_smtp_arguments(params):
29 _description, settings = params
30 args = ''
32 if "expect" in settings:
33 args += ' -e %s' % quote_shell_string(settings["expect"])
35 if "port" in settings:
36 port = int(settings["port"]) # ValueSpec was broken, convert to int
37 args += ' -p %d' % port
39 # Be compatible to legacy option
40 if "ip_version" in settings:
41 settings["address_family"] = settings.pop("ip_version")
43 # Use the address family of the monitored host by default
44 address_family = settings.get("address_family")
45 if address_family is None:
46 address_family = "ipv6" if is_ipv6_primary(host_name()) else "ipv4"
48 if address_family == "ipv6":
49 args += " -6"
50 address = "$_HOSTADDRESS_6$"
51 else:
52 args += " -4"
53 address = "$_HOSTADDRESS_4$"
55 for s in settings.get("commands", []):
56 args += ' -C %s' % quote_shell_string(s)
58 for s in settings.get("command_responses", []):
59 args += ' -R %s' % quote_shell_string(s)
61 if settings.get('from'):
62 args += ' -f %s' % quote_shell_string(settings["from"])
64 if "response_time" in settings:
65 args += ' -w %d -c %d' % (settings["response_time"][0], settings["response_time"][1])
67 if "timeout" in settings:
68 args += ' -t %d' % settings["timeout"]
70 if "auth" in settings:
71 auth = settings["auth"]
72 args += ' -A LOGIN -U %s -P %s' % (quote_shell_string(auth[0]), quote_shell_string(auth[1]))
74 if settings.get('starttls', False):
75 args += ' -S'
77 if 'fqdn' in settings:
78 args += ' -F %s' % quote_shell_string(settings['fqdn'])
80 if "cert_days" in settings:
81 # legacy behavior
82 if isinstance(settings["cert_days"], int):
83 args += ' -D %d' % settings["cert_days"]
84 else:
85 warn, crit = settings["cert_days"]
86 args += ' -D %d,%d' % (warn, crit)
88 if 'hostname' in settings:
89 args += ' -H %s' % settings['hostname']
90 else:
91 args += ' -H ' + address
92 return args
95 def check_smtp_desc(params):
96 if params[0].startswith("^"):
97 return params[0][1:]
98 return "SMTP %s" % params[0]
101 active_check_info['smtp'] = {
102 "command_line": '$USER1$/check_smtp $ARG1$',
103 "argument_function": check_smtp_arguments,
104 "service_description": check_smtp_desc,
105 "has_perfdata": True,