Cleanup config.nodes_of
[check_mk.git] / checks / check_tcp
blob07b03749ffd7aabd426a1b313ff536b0f1d94b7d
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_tcp_arguments(params):
29 port, settings = params
30 args = ' -p %d' % port
32 if "response_time" in settings:
33 args += ' -w %f -c %f' % (settings["response_time"][0] / 1000.0,
34 settings["response_time"][1] / 1000.0)
36 if "timeout" in settings:
37 args += ' -t %d' % settings["timeout"]
39 if "refuse_state" in settings:
40 args += ' -r %s' % settings["refuse_state"]
42 if settings.get("escape_send_string"):
43 args += ' --escape'
45 if "send_string" in settings:
46 args += ' -s %s' % quote_shell_string(settings["send_string"])
48 if "expect" in settings:
49 for s in settings["expect"]:
50 args += ' -e %s' % quote_shell_string(s)
52 if settings.get("expect_all"):
53 args += ' -A'
55 if settings.get("jail"):
56 args += ' --jail'
58 if "mismatch_state" in settings:
59 args += ' -M %s' % settings["mismatch_state"]
61 if "delay" in settings:
62 args += ' -d %d' % settings["delay"]
64 if "maxbytes" in settings:
65 args += ' -m %d' % settings["maxbytes"]
67 if settings.get("ssl"):
68 args += ' --ssl'
70 if "cert_days" in settings:
71 # legacy behavior
72 if isinstance(settings["cert_days"], int):
73 args += ' -D %d' % settings["cert_days"]
74 else:
75 warn, crit = settings["cert_days"]
76 args += ' -D %d,%d' % (warn, crit)
78 if "quit_string" in settings:
79 args += ' -q %s' % quote_shell_string(settings["quit_string"])
81 if "hostname" in settings:
82 args += ' -H %s' % quote_shell_string(settings["hostname"])
83 else:
84 args += " -H '$HOSTADDRESS$'"
85 return args
88 active_check_info['tcp'] = {
89 "command_line": '$USER1$/check_tcp $ARG1$',
90 "argument_function": check_tcp_arguments,
91 "service_description": lambda args: args[1].get("svc_description", "TCP Port %d" % args[0]),
92 "has_perfdata": True,