Module: check_mk
Branch: master
Commit: e4f833e96e0a6474acf50214ab3fb344f140f464
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e4f833e96e0a64…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jan 22 13:49:05 2018 +0100
5622 Hosts can have multiple IP addresses which are checked by ICMP service
In the host properties you can configure multiple IP addresses
below 'Address'. Within the rule 'Check hosts with PING (ICMP Echo
Request)'
you can choose 'PING all configured addresses' below
'Alternative address to ping'.
Change-Id: Id03f0a3b13f00cf378d188e865b39568142546f8
---
.werks/5622 | 27 +++++++++++++++++++++++++++
checks/check_icmp | 9 +++++++++
cmk_base/config.py | 5 +++++
cmk_base/core_config.py | 16 +++++++++++-----
cmk_base/default_config/base.py | 2 ++
web/plugins/wato/active_checks.py | 11 +++++++----
web/plugins/wato/builtin_attributes.py | 32 ++++++++++++++++++++++++++++++++
7 files changed, 93 insertions(+), 9 deletions(-)
diff --git a/.werks/5622 b/.werks/5622
new file mode 100644
index 0000000..4ed044d
--- /dev/null
+++ b/.werks/5622
@@ -0,0 +1,27 @@
+Title: Hosts can have multiple IP addresses which may be checked by ICMP service
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i3
+Date: 1516625065
+Class: feature
+
+In the host properties you can configure extra IPv4 or IPv6 addresses
+below 'Address'. Within the rule 'Check hosts with PING (ICMP Echo
Request)'
+you can choose 'PING all IPv4 addresses', 'PING all IPv6 addresses',
+'Ping additional IPv4 addresses' or 'Ping additional IPv6 addresses'
+below 'Alternative address to ping'.
+
+Note that the active check ICMP can ping multiple IP addresses which have
+to be of the same type. That means if you want to ping
+
+- only IPv4 addresses, use
+ 'PING all IPv4 addresses' or 'Ping additional IPv4 addresses' in the
check
+ configuration.
+
+- only IPv6 addresses, use
+ 'PING all IPv6 addresses' or 'Ping additional IPv6 addresses' in the
check
+ configuration.
+
+- both IPv4 and IPv6 addresses, you have to configure two active checks.
diff --git a/checks/check_icmp b/checks/check_icmp
index dcfa61b..2dbd55a 100644
--- a/checks/check_icmp
+++ b/checks/check_icmp
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
def check_icmp_arguments(params):
args = []
rta = 200, 500
@@ -45,6 +46,14 @@ def check_icmp_arguments(params):
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$"]
else: # custom
args.append(quote_shell_string(target[1]))
return " ".join(args)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 7e4138b..9213114 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -568,6 +568,11 @@ def alias_of(hostname, fallback):
return aliases[0]
+def get_additional_ipaddresses_of(hostname):
+ return (host_attributes.get(hostname, {}).get("additional_ipv4addresses",
[]),
+ host_attributes.get(hostname, {}).get("additional_ipv6addresses",
[]))
+
+
def parents_of(hostname):
par = rulesets.host_extra_conf(hostname, parents)
# Use only those parents which are defined and active in
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index e9d20a2..0f81d26 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -390,12 +390,18 @@ def get_host_attributes(hostname, tags):
ipv6_primary = config.is_ipv6_primary(hostname)
if ipv6_primary:
- attrs["address"] = attrs["_ADDRESS_6"]
+ attrs["address"] = attrs["_ADDRESS_6"]
attrs["_ADDRESS_FAMILY"] = "6"
else:
- attrs["address"] = attrs["_ADDRESS_4"]
+ attrs["address"] = attrs["_ADDRESS_4"]
attrs["_ADDRESS_FAMILY"] = "4"
+ add_ipv4addrs, add_ipv6addrs = config.get_additional_ipaddresses_of(hostname)
+ if add_ipv4addrs:
+ attrs["_ADDRESSES_4"] = " ".join(add_ipv4addrs)
+ if add_ipv6addrs:
+ attrs["_ADDRESSES_6"] = " ".join(add_ipv6addrs)
+
# Add the optional WATO folder path
path = config.host_paths.get(hostname)
if path:
@@ -526,9 +532,9 @@ def fallback_ip_for(hostname, family=None):
def get_host_macros_from_attributes(hostname, attrs):
macros = {
- "$HOSTNAME$" : hostname,
- "$HOSTADDRESS$" : attrs['address'],
- "$HOSTALIAS$" : attrs['alias'],
+ "$HOSTNAME$" : hostname,
+ "$HOSTADDRESS$" : attrs['address'],
+ "$HOSTALIAS$" : attrs['alias'],
}
# Add custom macros
diff --git a/cmk_base/default_config/base.py b/cmk_base/default_config/base.py
index 722e124..0cebcfc 100644
--- a/cmk_base/default_config/base.py
+++ b/cmk_base/default_config/base.py
@@ -161,6 +161,8 @@ datasource_programs = []
service_dependencies = []
ipaddresses = {} # mapping from hostname to IPv4 address
ipv6addresses = {} # mapping from hostname to IPv6 address
+additional_ipv4addresses = {} # mapping from hostname to addtional IPv4
addresses
+additional_ipv6addresses = {} # mapping from hostname to addtional IPv6
addresses
only_hosts = None
distributed_wato_site = None # used by distributed WATO
is_wato_slave_site = False
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index acbc909..9edd30c 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -239,10 +239,13 @@ register_rule(group,
"you want to check a secondary IP address of the host in
question)."),
orientation = "horizontal",
choices = [
- ( "address", _("Ping the normal IP address")),
- ( "alias", _("Use the alias as DNS name / IP
address")),
- ( "explicit", _("Ping the following explicity address
/ DNS name"),
- Hostname()),
+ ("address", _("Ping the normal IP address")),
+ ("alias", _("Use the alias as DNS name / IP
address")),
+ ("explicit", _("Ping the following explicity address
/ DNS name"), Hostname()),
+ ("all_ipv4addresses", _("Ping all IPv4
addresses")),
+ ("all_ipv6addresses", _("Ping all IPv6
addresses")),
+ ("additional_ipv4addresses", _("Ping additional IPv4
addresses")),
+ ("additional_ipv6addresses", _("Ping additional IPv6
addresses")),
]
)),
] + check_icmp_params,
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index 118e2df..b1feafb 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -82,6 +82,38 @@ declare_host_attribute(ValueSpecAttribute("ipv6address",
topic = _("Address"),
)
+declare_host_attribute(ValueSpecAttribute("additional_ipv4addresses",
+ ListOf(
+ HostAddress(
+ allow_empty = False,
+ allow_ipv6_address = False,
+ ),
+ title = _("Additional IPv4 addresses"),
+ help = _("Here you can specify additional IPv4 addresses. "
+ "These can be used in some active checks like ICMP."),
+ )),
+ show_in_table = True,
+ show_in_folder = False,
+ depends_on_tags = ["ip-v4"],
+ topic = _("Address"),
+)
+
+declare_host_attribute(ValueSpecAttribute("additional_ipv6addresses",
+ ListOf(
+ HostAddress(
+ allow_empty = False,
+ allow_ipv4_address = False,
+ ),
+ title = _("Additional IPv6 addresses"),
+ help = _("Here you can specify additional IPv4 addresses. "
+ "These can be used in some active checks like ICMP."),
+ )),
+ show_in_table = True,
+ show_in_folder = False,
+ depends_on_tags = ["ip-v6"],
+ topic = _("Address"),
+)
+
_snmpv3_auth_elements = [
DropdownChoice(
choices = [