Module: check_mk
Branch: master
Commit: b2479c92dda49ed0a92f0ade6f1da720dfc4ccfa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2479c92dda49e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Sep 14 11:46:35 2013 +0200
Allow to specify custom host check via WATO (arbitrary command line)
This can now directly be configured via WATO. It is very similar to
the "classical active and passive nagios checks" and allows to use
an arbitrary command line instead of PING, etc.
---
ChangeLog | 7 +++--
modules/check_mk.py | 31 ++++++++++++++-------
web/plugins/wato/active_checks.py | 40 +++++++++++++++-------------
web/plugins/wato/check_mk_configuration.py | 3 ++-
4 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 91c95af..304fdbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,8 +14,11 @@
* New option explicit_snmp_communities to override rule based SNMP settings
* Preparations for significant SNMP monitoring performance improvement
(It's named Inline SNMP, which is available as special feature via
subscriptions)
- * livestatus: new service column staleness: indicator for outdated service checks
- * livestatus: new host column staleness: indicator for outdated host checks
+ * Allow to specify custom host check via WATO (arbitrary command line)
+
+ Livestatus:
+ * new service column staleness: indicator for outdated service checks
+ * new host column staleness: indicator for outdated host checks
Checks & Agents:
* esx_hostystem multipath: criticize standby paths only if not equal to active paths
diff --git a/modules/check_mk.py b/modules/check_mk.py
index b6ce1db..f1905b9 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1451,6 +1451,13 @@ def host_check_command(hostname, ip, is_clust):
elif value[0] == "tcp":
return "check-mk-host-tcp!" + str(value[1])
+ elif value[0] == "custom":
+ try:
+ custom_commands_to_define.add("check-mk-custom")
+ except:
+ pass # not needed and not available with CMC
+ return "check-mk-custom!" + autodetect_plugin(value[1])
+
raise MKGeneralException("Invalid value %r for host_check_command of host
%s." % (
value, hostname))
@@ -2159,16 +2166,7 @@ define service {
continue
if command_line:
- plugin_name = command_line.split()[0]
- if command_line[0] not in [ '$', '/' ]:
- try:
- for dir in [ "/local", "" ]:
- path = omd_root + dir + "/lib/nagios/plugins/"
- if os.path.exists(path + plugin_name):
- command_line = path + command_line
- break
- except:
- pass
+ command_line = autodetect_plugin(command_line)
if "freshness" in entry:
freshness = " check_freshness\t\t1\n" + \
@@ -2225,6 +2223,19 @@ define service {
""" % (pingonly_template, ping_command, check_icmp_arguments(hostname),
extra_service_conf_of(hostname, "PING"), hostname))
+def autodetect_plugin(command_line):
+ plugin_name = command_line.split()[0]
+ if command_line[0] not in [ '$', '/' ]:
+ try:
+ for dir in [ "/local", "" ]:
+ path = omd_root + dir + "/lib/nagios/plugins/"
+ if os.path.exists(path + plugin_name):
+ command_line = path + command_line
+ break
+ except:
+ pass
+ return command_line
+
def simulate_command(command):
if simulation_mode:
custom_commands_to_define.add("check-mk-simulation")
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index 449693a..e978655 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -810,6 +810,24 @@ register_rule(group,
),
match = 'all')
+def PluginCommandLine(addhelp = ""):
+ return TextAscii(
+ title = _("Command line"),
+ help = _("Please enter the complete shell command including "
+ "path name and arguments to execute. You can use Nagios "
+ "macros here. The most important are:<ul>"
+ "<li><tt>$HOSTADDRESS$</tt>: The IP address of
the host</li>"
+ "<li><tt>$HOSTNAME$</tt>: The name of the
host</li>"
+ "<li><tt>$USER1$</tt>: user macro 1 (usually
path to shipped plugins)</li>"
+ "<li><tt>$USER2$</tt>: user marco 2 (usually
path to your own plugins)</li>"
+ "</ul>"
+ "If you are using OMD, then you can omit the path and just
specify "
+ "the command (e.g. <tt>check_foobar</tt>). This
command will be "
+ "searched first in the local plugins directory "
+ "(<tt>~/local/lib/nagios/plugins</tt>) and then in
the shipped plugins "
+ "directory (<tt>~/lib/nagios/plugins</tt>) within
your site directory."),
+ size = "max",
+ )
register_rule(group,
"custom_checks",
@@ -830,25 +848,9 @@ register_rule(group,
default_value = _("Customcheck"))
),
( "command_line",
- TextAscii(
- title = _("Command line"),
- help = _("Please enter the complete shell command including
"
- "path name and arguments to execute. You can use Nagios
"
- "macros here. The most important are:<ul>"
- "<li><tt>$HOSTADDRESS$</tt>: The IP
address of the host</li>"
- "<li><tt>$HOSTNAME$</tt>: The name of
the host</li>"
- "<li><tt>$USER1$</tt>: user macro 1
(usually path to shipped plugins)</li>"
- "<li><tt>$USER2$</tt>: user marco 2
(usually path to your own plugins)</li>"
- "</ul>"
- "If you are using OMD, then you can omit the path and
just specify "
- "the command (e.g. <tt>check_foobar</tt>).
This command will be "
- "searched first in the local plugins directory "
- "(<tt>~/local/lib/nagios/plugins</tt>) and
then in the shipped plugins "
- "directory (<tt>~/lib/nagios/plugins</tt>)
within your site directory.<br><br>"
- "<b>Passive checks</b>: Do no specify a
command line if you want "
- "to define passive checks."),
- size = "max",
- )
+ PluginCommandLine(addhelp = _("<br><br>"
+ "<b>Passive checks</b>: Do no specify a command line
if you want "
+ "to define passive checks.")),
),
( "command_name",
TextAscii(
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 2d3fc41..68d5706 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1433,7 +1433,8 @@ register_rule(
( "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 )),
+ ( "service", _("Use the status of the service..."),
TextUnicode(label = ":", size=45, allow_empty=False )),
+ ( "custom", _("Use a custom check plugin..."),
PluginCommandLine() ),
],
default_value = "ping",
html_separator = " ",