GUI CSS: Removed snapin styles from py modules and added a _snapins.scss for the...
[check_mk.git] / checks / check_icmp
blob6674794d0697cba0cedf2a85f532ecb650d5b201
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_icmp_arguments(params):
29 args = []
30 rta = 200, 500
31 loss = 80, 100
32 for key, value in params.items():
33 if key == "timeout":
34 args.append("-t %d" % value)
35 elif key == "packets":
36 args.append("-n %d" % value)
37 elif key == "rta":
38 rta = value
39 elif key == "loss":
40 loss = value
41 args.append("-w %.2f,%d%%" % (rta[0], loss[0]))
42 args.append("-c %.2f,%d%%" % (rta[1], loss[1]))
44 target = params.get("address", "address")
45 if target == "address":
46 args.append("'$HOSTADDRESS$'")
48 elif target == "alias":
49 args.append("'$HOSTALIAS$'")
51 elif target == "all_ipv4addresses":
52 args += ["$HOST_ADDRESSES_4$", "$HOST_ADDRESS_4$"]
54 elif target == "all_ipv6addresses":
55 args += ["-6", "$HOST_ADDRESSES_6$", "$HOST_ADDRESS_6$"]
57 elif target == "additional_ipv4addresses":
58 args.append("$HOST_ADDRESSES_4$")
60 elif target == "additional_ipv6addresses":
61 args += ["-6", "$HOST_ADDRESSES_6$"]
63 elif target[0] == "indexed_ipv4address":
64 args.append("$HOST_ADDRESS_4_%s$" % target[1])
66 elif target[0] == "indexed_ipv6address":
67 args.append("$HOST_ADDRESS_6_%s$" % target[1])
69 else: # custom
70 args.append(quote_shell_string(target[1]))
71 return " ".join(args)
74 def check_icmp_description(params):
75 description = "PING"
76 target = params.get("address", "address")
77 if target[0] == "indexed_ipv4address":
78 description += " IPv4/%s" % target[1]
79 elif target[0] == "indexed_ipv6address":
80 description += " IPv6/%s" % target[1]
81 return description
84 active_check_info['icmp'] = {
85 "command_line": '$USER1$/check_icmp $ARG1$',
86 "argument_function": check_icmp_arguments,
87 "service_description": check_icmp_description,
88 "has_perfdata": True,