Module: check_mk
Branch: master
Commit: 887a99382f28eba10b1de8478c957bb410c1888e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=887a99382f28eb…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Jul 24 15:14:05 2018 +0200
6379 check_icmp: Ping additional IPv4/6 address which refers to its numbering in the host
attributes
Change-Id: Ia9b759552f31603be606445d54800af71f7f40f4
---
.werks/6379 | 14 ++++++++++++++
checks/check_icmp | 24 +++++++++++++++++++++++-
cmk/gui/plugins/wato/active_checks.py | 2 ++
cmk_base/core_config.py | 7 +++++++
4 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/.werks/6379 b/.werks/6379
new file mode 100644
index 0000000..5043763
--- /dev/null
+++ b/.werks/6379
@@ -0,0 +1,14 @@
+Title: check_icmp: Ping additional IPv4/6 address which refers to its index in the host
properties
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1532437758
+Class: feature
+
+Below the host properties you can set additional IPv4/6 addresses
+which are numbered. In the ruleset {{Check hosts with PING (ICMP Echo Request)}}
+you can choose {{Additional IPv4/6 address identified by its index in the host
properties}}
+below {{Alternative address to ping}}. There you can give the index of the
+IPv4/6 address which you want to ping.
diff --git a/checks/check_icmp b/checks/check_icmp
index 2dbd55a..d0f7afa 100644
--- a/checks/check_icmp
+++ b/checks/check_icmp
@@ -44,25 +44,47 @@ def check_icmp_arguments(params):
target = params.get("address", "address")
if target == "address":
args.append("'$HOSTADDRESS$'")
+
elif target == "alias":
args.append("'$HOSTALIAS$'")
+
elif target == "all_ipv4addresses":
args += ["$HOST_ADDRESSES_4$", "$HOST_ADDRESS_4$"]
+
elif target == "all_ipv6addresses":
args += ["-6", "$HOST_ADDRESSES_6$",
"$HOST_ADDRESS_6$"]
+
elif target == "additional_ipv4addresses":
args.append("$HOST_ADDRESSES_4$")
+
elif target == "additional_ipv6addresses":
args += ["-6", "$HOST_ADDRESSES_6$"]
+
+ elif target[0] == "indexed_ipv4address":
+ args.append("$HOST_ADDRESS_4_%s$" % target[1])
+
+ elif target[0] == "indexed_ipv6address":
+ args.append("$HOST_ADDRESS_6_%s$" % target[1])
+
else: # custom
args.append(quote_shell_string(target[1]))
return " ".join(args)
+def check_icmp_description(params):
+ description = "PING"
+ target = params.get("address", "address")
+ if target[0] == "indexed_ipv4address":
+ description += " IPv4/%s" % target[1]
+ elif target[0] == "indexed_ipv6address":
+ description += " IPv6/%s" % target[1]
+ return description
+
+
active_check_info['icmp'] = {
"command_line" : '$USER1$/check_icmp $ARG1$',
"argument_function" : check_icmp_arguments,
- "service_description" : lambda args: args.get("description",
"PING"),
+ "service_description" : check_icmp_description,
"has_perfdata" : True,
}
diff --git a/cmk/gui/plugins/wato/active_checks.py
b/cmk/gui/plugins/wato/active_checks.py
index 872affc..9b791f2 100644
--- a/cmk/gui/plugins/wato/active_checks.py
+++ b/cmk/gui/plugins/wato/active_checks.py
@@ -259,6 +259,8 @@ register_rule(group,
("all_ipv6addresses", _("Ping all IPv6
addresses")),
("additional_ipv4addresses", _("Ping additional IPv4
addresses")),
("additional_ipv6addresses", _("Ping additional IPv6
addresses")),
+ ("indexed_ipv4address", _("Ping IPv4 address
identified by its index"), Integer(default_value=1)),
+ ("indexed_ipv6address", _("Ping IPv6 address
identified by its index"), Integer(default_value=1)),
]
)),
] + check_icmp_params,
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index c06c768..84c3741 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -391,8 +391,15 @@ def get_host_attributes(hostname, tags):
add_ipv4addrs, add_ipv6addrs = config.get_additional_ipaddresses_of(hostname)
if add_ipv4addrs:
attrs["_ADDRESSES_4"] = " ".join(add_ipv4addrs)
+ for nr, ipv4_address in enumerate(add_ipv4addrs):
+ key = "_ADDRESS_4_%s" % (nr+1)
+ attrs[key] = ipv4_address
+
if add_ipv6addrs:
attrs["_ADDRESSES_6"] = " ".join(add_ipv6addrs)
+ for nr, ipv6_address in enumerate(add_ipv6addrs):
+ key = "_ADDRESS_6_%s" % (nr+1)
+ attrs[key] = ipv6_address
# Add the optional WATO folder path
path = config.host_paths.get(hostname)