Module: check_mk
Branch: master
Commit: 4099be80723cf8dd70035bbc2e55b9ae86af6929
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4099be80723cf8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Mar 8 19:01:14 2013 +0100
Host check command configurable via WATO
including automatic command definition for Nagios
---
.f12 | 11 +++++
ChangeLog | 3 +
check_mk_templates.cfg | 16 ++++++-
doc/.f12 | 13 ------
modules/check_mk.py | 63 ++++++++++++++++++++++++----
web/plugins/wato/active_checks.py | 1 +
web/plugins/wato/check_mk_configuration.py | 33 ++++++++++++--
7 files changed, 111 insertions(+), 29 deletions(-)
diff --git a/.f12 b/.f12
index 3871f7d..9b77ef2 100644
--- a/.f12
+++ b/.f12
@@ -1,3 +1,14 @@
+SITE=${SITE:-$(omd sites --bare | head -n 1)}
+sed -e "s#@BINDIR@#/omd/sites/$SITE/bin#g" \
+ -e "s#@VARDIR@#/omd/sites/$SITE/var/check_mk#g" \
+ -e "s#@CHECK_ICMP@#/omd/sites/$SITE/lib/nagios/plugins/check_icmp#g" \
+ -e "s#@PNPURL@#/$SITE/pnp4nagios/#g" \
+ -e "s#@CGIURL@#/$SITE/nagios/cgi-bin#g" \
+ < check_mk_templates.cfg > /tmp/check_mk_templates.cfg
+
+sudo mv /tmp/check_mk_templates.cfg /omd/sites/$SITE/etc/nagios/conf.d
+
+(cd doc ; bash .f12)
(cd web ; bash .f12)
(cd modules ; bash .f12)
(cd checks ; bash .f12)
diff --git a/ChangeLog b/ChangeLog
index 64a5db7..f6eec15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
Core:
* Agents can send data for other hosts "piggyback". This is being
used by the vSphere and SAP plugins
+ * New variable host_check_commands, that allows the definition of
+ an alternative host check command (without manually defining one)
Multisite:
* New availability view for arbitrary host/service collections
@@ -58,6 +60,7 @@
* Removed global option logwatch_forward_to_ec, moved this to the
logwatch_ec ruleset. With this option the forwarding can now be enabled
for each logfile on a host
+ * Configuration of an alternativ host check command
1.2.2b5:
Core:
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index 381e585..f20ac04 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -316,16 +316,28 @@ define command {
}
define command {
- command_name check-mk-ping
+ command_name check-mk-host-ping
command_line @CHECK_ICMP@ $ARG1$ $HOSTADDRESS$
}
# Check for clusters: it is UP if at least one node is up
define command {
- command_name check-mk-ping-cluster
+ command_name check-mk-host-ping-cluster
command_line @CHECK_ICMP@ -m 1 $ARG1$ $_HOSTNODEIPS$
}
+# Dummy host check that always assumes that the host is up
+define command {
+ command_name check-mk-host-ok
+ command_line echo "OK - Host is always assumed to be up"
+}
+
+define command {
+ command_name check-mk-host-tcp
+ command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$
+}
+
+
# General notification script. Details can be configured
# in main.mk via notification_... options
define command {
diff --git a/doc/.f12 b/doc/.f12
index 64efbb0..096bb80 100644
--- a/doc/.f12
+++ b/doc/.f12
@@ -1,14 +1 @@
-#!/bin/bash
-SITE=${SITE:-$(omd sites --bare | head -n 1)}
-set -xe
-
-sed -e "s#@BINDIR@#/omd/sites/$SITE/bin#g" \
- -e "s#@VARDIR@#/omd/sites/$SITE/var/check_mk#g" \
- -e "s#@CHECK_ICMP@#/omd/sites/$SITE/lib/nagios/plugins/check_icmp#g" \
- -e "s#@PNPURL@#/$SITE/pnp4nagios/#g" \
- -e "s#@CGIURL@#/$SITE/nagios/cgi-bin#g" \
- < check_mk_templates.cfg > /tmp/check_mk_templates.cfg
-
-sudo mv /tmp/check_mk_templates.cfg /omd/sites/$SITE/etc/nagios/conf.d
-sudo omd restart $SITE nagios
sudo cp -pr * /omd/versions/default/share/doc/check_mk
diff --git a/modules/check_mk.py b/modules/check_mk.py
index a56ad20..24fa8c8 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -320,9 +320,11 @@ donation_command = 'mail -r
checkmk(a)yoursite.de -s "Host do
scanparent_hosts = [ ( ALL_HOSTS ) ]
host_attributes = {} # needed by WATO, ignored by Check_MK
ping_levels = [] # special parameters for host/PING
check_command
+host_check_commands = [] # alternative host check instead of check_icmp
check_periods = []
+
# global variables used to cache temporary values (not needed in check_mk_base)
ip_to_hostname_cache = None
@@ -1268,6 +1270,43 @@ def extra_conf_of(confdict, hostname, service):
result += format % (key, values[0])
return result
+def host_check_command(hostname, ip, is_clust):
+ # Check dedicated host check command
+ values = host_extra_conf(hostname, host_check_commands)
+ if values:
+ value = values[0]
+ else:
+ value = "ping"
+
+ if value == "ping":
+ ping_args = check_icmp_arguments(hostname)
+ if is_clust and ip: # Do check cluster IP address if one is there
+ return "check-mk-host-ping!%s" % ping_args
+ elif ping_args and is_clust: # use check_icmp in cluster mode
+ return "check-mk-host-ping-cluster!%s" % ping_args
+ elif ping_args: # use special arguments
+ return "check-mk-host-ping!%s" % ping_args
+ else:
+ return None
+
+ elif value == "ok":
+ return "check-mk-host-ok"
+
+ elif value == "agent" or value[0] == "service":
+ service = value == "agent" and "Check_MK" or value[1]
+ command = "check-mk-host-custom-%d" %
(len(hostcheck_commands_to_define) + 1)
+ hostcheck_commands_to_define.append((command,
+ 'echo "$SERVICEOUTPUT:%s:%s$" && exit
$SERVICESTATEID:%s:%s$' % (hostname, service, hostname, service)))
+ return command
+
+ elif value[0] == "tcp":
+ return "check-mk-host-tcp!" + str(value[1])
+
+ raise MKGeneralException("Invalid value %r for host_check_command of host
%s." % (
+ value, hostname))
+
+
+
def check_icmp_arguments(hostname):
values = host_extra_conf(hostname, ping_levels)
levels = {}
@@ -1499,6 +1538,8 @@ def create_nagios_config(outfile = sys.stdout, hostnames = None):
active_checks_to_define = set([])
global custom_commands_to_define
custom_commands_to_define = set([])
+ global hostcheck_commands_to_define
+ hostcheck_commands_to_define = []
if host_notification_periods != []:
raise MKGeneralException("host_notification_periods is not longer supported.
Please use extra_host_conf['notification_period'] instead.")
@@ -1571,15 +1612,10 @@ def create_nagios_hostdefs(outfile, hostname):
outfile.write(" address\t\t\t%s\n" % (ip and make_utf8(ip) or
"0.0.0.0"))
outfile.write(" _TAGS\t\t\t\t%s\n" % "
".join(tags_of_host(hostname)))
- # Levels for host check
- ping_args = check_icmp_arguments(hostname)
- if is_clust and ip: # Do check cluster IP address if one is there
- outfile.write(" check_command\t\t\tcheck-mk-ping!%s\n" % ping_args)
- elif ping_args and is_clust: # use check_icmp in cluster mode
- outfile.write(" check_command\t\t\tcheck-mk-ping-cluster!%s\n" %
ping_args)
- elif ping_args: # use special arguments
- outfile.write(" check_command\t\t\tcheck-mk-ping!%s\n" % ping_args)
-
+ # Host check command might differ from default
+ command = host_check_command(hostname, ip, is_clust)
+ if command:
+ outfile.write(" check_command\t\t\t%s\n" % command)
# WATO folder path
path = host_paths.get(hostname)
@@ -2093,6 +2129,15 @@ def create_nagios_config_commands(outfile):
""" % command_name)
+ # custom host checks
+ for command_name, command_line in hostcheck_commands_to_define:
+ outfile.write("""define command {
+ command_name\t\t\t%s
+ command_line\t\t\t%s
+}
+
+""" % (command_name, command_line))
+
def create_nagios_config_timeperiods(outfile):
if len(timeperiods) > 0:
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index e18d2de..4a1b3d0 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -892,3 +892,4 @@ register_rule(group,
match = 'all'
)
+
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 528ed29..0a9fcf2 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1153,15 +1153,38 @@ register_rule(group,
"the state of the host will stay at its last status.")),
)
+register_rule(
+ group,
+ "host_check_commands",
+ CascadingDropdown(
+ title = _("Host Check Command"),
+ help = _("Usually Check_MK uses a series of PING (ICMP echo request) in
order to determine "
+ "whether a host is up. In some cases this is not possible, however.
With this rule "
+ "you can specify an alternative way of determining the host's
state."),
+ choices = [
+ ( "ping", _("PING (ICMP echo request)") ),
+ ( "tcp" , _("TCP Connect"), Integer(label = _("to
port:"), minvalue=1, maxvalue=65535, default_value=80 )),
+ ( "ok", _("Always assume host to be up") ),
+ ( "agent", _("Use the status of the Check_MK Agent") ),
+ ( "service", _("Use the status of the service..."),
TextUnicode(label = ":", size=32, allow_empty=False )),
+ ],
+ default_value = "ping",
+ html_separator = " ",
+ ),
+ match = 'first'
+)
+
+
register_rule(group,
"extra_host_conf:check_command",
TextAscii(
+ title = _("Internal Command for Hosts Check"),
label = _("Command:"),
- title = _("Check Command for Hosts Check"),
- help = _("This parameter changes the default check_command for "
- "a host check"),
- ),
- )
+ help = _("This ruleset is deprecated and will be removed soon: "
+ "it changes the default check_command for a host check. You need to
"
+ "define that command manually in your monitoring
configuration."),
+ ),
+)
group = "monconf/" + _("Notifications")
register_rule(group,