Module: check_mk
Branch: master
Commit: d97254f9741db1c05f9528992ba4b978cb1055c3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d97254f9741db1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Oct 12 15:00:26 2015 +0200
Added missing "PING v4/v6" service to nagios based installations
---
check_mk_templates.cfg | 7 +---
modules/check_mk.py | 79 ++++++++++++++++++++++++++++++-----------
web/plugins/views/painters.py | 3 +-
3 files changed, 62 insertions(+), 27 deletions(-)
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index ddb65a3..9094329 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -318,12 +318,7 @@ define command {
# Commands for services of PING-only hosts
define command {
command_name check-mk-ping
- command_line @CHECK_ICMP@ $ARG1$ $HOSTADDRESS$
-}
-
-define command {
- command_name check-mk-ping-cluster
- command_line @CHECK_ICMP@ -m 1 $ARG1$ $_HOSTNODEIPS$
+ command_line @CHECK_ICMP@ $ARG1$
}
# Host check commands
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 284f767..d20f98e 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -724,6 +724,27 @@ def get_host_attributes(hostname):
return attrs
+def get_cluster_attributes(hostname, nodes):
+ attrs = {}
+ node_ips_4 = []
+ if is_ipv4_host(hostname):
+ node_ips_4 = [ ip_address_of(h, 4) for h in nodes ]
+
+ node_ips_6 = []
+ if is_ipv6_host(hostname):
+ node_ips_6 = [ ip_address_of(h, 6) for h in nodes ]
+
+ if is_ipv6_primary(hostname):
+ node_ips = node_ips_6
+ else:
+ node_ips = node_ips_4
+
+ for suffix, val in [ ("", node_ips), ("_4", node_ips_4),
("_6", node_ips_6) ]:
+ attrs["_NODEIPS%s" % suffix] = " ".join(val)
+
+ return attrs
+
+
def ip_address_of(hostname, family=None):
try:
return lookup_ip_address(hostname, family)
@@ -2225,16 +2246,16 @@ def create_nagios_config_host(outfile, hostname):
outfile.write("\n#
----------------------------------------------------\n")
outfile.write("# %s\n" % hostname)
outfile.write("# ----------------------------------------------------\n")
+ host_attrs = get_host_attributes(hostname)
if generate_hostconf:
- create_nagios_hostdefs(outfile, hostname)
- create_nagios_servicedefs(outfile, hostname)
+ create_nagios_hostdefs(outfile, hostname, host_attrs)
+ create_nagios_servicedefs(outfile, hostname, host_attrs)
-def create_nagios_hostdefs(outfile, hostname):
+def create_nagios_hostdefs(outfile, hostname, attrs):
is_clust = is_cluster(hostname)
# Determine IP address. For cluster hosts this is optional.
# A cluster might have or not have a service ip address.
- attrs = get_host_attributes(hostname)
if not is_clust and attrs["address"] in [ "0.0.0.0",
"::" ]:
if ignore_ip_lookup_failures:
failed_ip_lookups.append(hostname)
@@ -2247,6 +2268,16 @@ def create_nagios_hostdefs(outfile, hostname):
(hostname,
varname))
ip = attrs["address"]
+ if is_clust:
+ verify_cluster_address_family(hostname)
+
+ nodes = nodes_of(hostname)
+ for node in nodes:
+ if node not in all_active_realhosts():
+ raise MKGeneralException("Node %s of cluster %s not in
all_hosts." % (node, hostname))
+
+ attrs.update(get_cluster_attributes(hostname, nodes))
+
# _
# / |
# | |
@@ -2306,15 +2337,7 @@ def create_nagios_hostdefs(outfile, hostname):
# Special handling of clusters
if is_clust:
- verify_cluster_address_family(hostname)
-
- nodes = nodes_of(hostname)
- for node in nodes:
- if node not in all_active_realhosts():
- raise MKGeneralException("Node %s of cluster %s not in
all_hosts." % (node, hostname))
- node_ips = [ lookup_ip_address(h) for h in nodes ]
alias = "cluster of %s" % ", ".join(nodes)
- outfile.write(" _NODEIPS\t\t\t%s\n" % " ".join(node_ips))
if not extra_conf_parents:
outfile.write(" parents\t\t\t%s\n" % ",".join(nodes))
@@ -2378,7 +2401,7 @@ def create_nagios_hostdefs(outfile, hostname):
outfile.write("}\n")
outfile.write("\n")
-def create_nagios_servicedefs(outfile, hostname):
+def create_nagios_servicedefs(outfile, hostname, host_attrs):
# _____
# |___ /
# |_ \
@@ -2752,22 +2775,38 @@ define servicedependency {
}
""" % (service_dependency_template, hostname, hostname,
service_discovery_name))
- # Levels for host check
+ # No check_mk service, no legacy service -> create PING service
+ if not have_at_least_one_service and not legchecks and not actchecks and not
custchecks:
+ add_ping_service(outfile, hostname, host_attrs["address"],
is_ipv6_primary(hostname) and 6 or 4,
+ "PING", host_attrs.get("_NODEIPS"))
+
+ if is_ipv4v6_host(hostname):
+ if is_ipv6_primary(hostname):
+ add_ping_service(outfile, hostname, host_attrs["_ADDRESS_4"], 4,
+ "PING IPv4",
host_attrs.get("_NODEIPS_4"))
+ else:
+ add_ping_service(outfile, hostname, host_attrs["_ADDRESS_6"], 6,
+ "PING IPv6",
host_attrs.get("_NODEIPS_6"))
+
+
+def add_ping_service(outfile, hostname, ipaddress, family, descr, node_ips):
+ arguments = check_icmp_arguments_of(hostname, family=family)
+
+ ping_command = 'check-mk-ping'
if is_cluster(hostname):
- ping_command = 'check-mk-ping-cluster'
+ arguments += ' -m 1 ' + node_ips
else:
- ping_command = 'check-mk-ping'
+ arguments += ' ' + ipaddress
- # No check_mk service, no legacy service -> create PING service
- if not have_at_least_one_service and not legchecks and not actchecks and not
custchecks:
- outfile.write("""
+ outfile.write("""
define service {
use\t\t\t\t%s
+ service_description\t\t%s
check_command\t\t\t%s!%s
%s host_name\t\t\t%s
}
-""" % (pingonly_template, ping_command, check_icmp_arguments_of(hostname),
extra_service_conf_of(hostname, "PING"), hostname))
+""" % (pingonly_template, descr, ping_command, arguments,
extra_service_conf_of(hostname, descr), hostname))
def verify_cluster_address_family(hostname):
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 1063117..77c53af 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -1611,7 +1611,8 @@ multisite_painters["host_custom_vars"] = {
"title" : _("Host custom variables"),
"columns" : [ "host_custom_variables" ],
"groupby" : lambda row:
tuple(row["host_custom_variables"].items()),
- "paint" : lambda row: paint_custom_vars('host', row, [
'FILENAME', 'TAGS', 'ADDRESS_4', 'ADDRESS_6',
'ADDRESS_FAMILY' ]),
+ "paint" : lambda row: paint_custom_vars('host', row, [
'FILENAME', 'TAGS', 'ADDRESS_4', 'ADDRESS_6',
+ 'ADDRESS_FAMILY',
'NODEIPS', 'NODEIPS_4', 'NODEIPS_6' ]),
}