Module: check_mk
Branch: master
Commit: 30c4bf61d7807130dc6681ff61740e052d288437
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=30c4bf61d78071…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Apr 23 10:23:28 2013 +0200
New config variable check_mk_exit_status
---
ChangeLog | 2 ++
modules/check_mk.py | 10 +++++++
modules/check_mk_base.py | 27 +++++++++--------
web/plugins/wato/check_mk_configuration.py | 44 ++++++++++++++++++++++++++--
4 files changed, 68 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f2d531c..d4885e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@
* New variable snmp_check_interval which can be used to customize
the check intervals of SNMP based checks
* setup: Added missing vars rrd_path and rrdcached_sock
+ * new variable check_mk_exit_status: allows to make Check_MK service OK,
+ even if host in not reachable.
Multisite:
* New availability view for arbitrary host/service collections
diff --git a/modules/check_mk.py b/modules/check_mk.py
index aed0ad3..f5483df 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1080,6 +1080,13 @@ def snmp_port_spec(hostname):
else:
return ":%d" % port
+def exit_code_spec(hostname):
+ spec = {}
+ specs = host_extra_conf(hostname, check_mk_exit_status)
+ for entry in specs[::-1]:
+ spec.update(entry)
+ return spec
+
def service_description(check_type, item):
if check_type not in check_info:
@@ -2894,6 +2901,9 @@ no_inventory_possible = None
output.write("def agent_port_of(hostname):\n return %d\n\n" %
agent_port_of(hostname))
output.write("def snmp_port_spec(hostname):\n return %r\n\n" %
snmp_port_spec(hostname))
+ # Exit code of Check_MK in case of various errors
+ output.write("def exit_code_spec(hostname):\n return %r\n\n" %
exit_code_spec(hostname))
+
# Piggyback translations
output.write("def get_piggyback_translation(hostname):\n return %r\n\n"
% get_piggyback_translation(hostname))
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 7dfd799..d78200d 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -871,25 +871,28 @@ def do_check(hostname, ipaddress, only_check_types = None):
start_time = time.time()
+ # Exit state in various situations is confiugrable since 1.2.3i1
+ exit_spec = exit_code_spec(hostname)
+
try:
load_counters(hostname)
agent_version, num_success, error_sections, problems =
do_all_checks_on_host(hostname, ipaddress, only_check_types)
num_errors = len(error_sections)
save_counters(hostname)
if problems:
- output = "CRIT - %s, " % problems
- status = 2
+ output = "%s, " % problems
+ status = exit_spec.get("connection", 2)
elif num_errors > 0 and num_success > 0:
- output = "WARN - Missing agent sections: %s - " % ",
".join(error_sections)
- status = 1
+ output = "Missing agent sections: %s - " % ",
".join(error_sections)
+ status = exit_spec.get("missing_sections", 1)
elif num_errors > 0:
- output = "CRIT - Got no information from host, "
- status = 2
+ output = "Got no information from host, "
+ status = exit_spec.get("empty_output", 2)
elif agent_min_version and agent_version < agent_min_version:
- output = "WARN - old plugin version %s (should be at least %s), " %
(agent_version, agent_min_version)
- status = 1
+ output = "old plugin version %s (should be at least %s), " %
(agent_version, agent_min_version)
+ status = exit_spec.get("wrong_version", 1)
else:
- output = "OK - "
+ output = ""
if agent_version != None:
output += "Agent version %s, " % agent_version
status = 0
@@ -897,8 +900,8 @@ def do_check(hostname, ipaddress, only_check_types = None):
except MKGeneralException, e:
if opt_debug:
raise
- output = "UNKNOWN - %s, " % e
- status = 3
+ output = "%s, " % e
+ status = exit_spec.get("exception", 3)
if aggregate_check_mk:
try:
@@ -919,7 +922,7 @@ def do_check(hostname, ipaddress, only_check_types = None):
else:
output += "execution time %.1f sec|execution_time=%.3f\n" % (run_time,
run_time)
- sys.stdout.write(output)
+ sys.stdout.write(nagios_state_names[status] + " - " + output)
sys.exit(status)
def check_unimplemented(checkname, params, info):
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index efbe7a2..4c7eab9 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1655,12 +1655,50 @@ group = "agent/" + _("Check_MK Agent")
register_rule(group,
"agent_ports",
Integer(
- help = _("This variable allows to specify the TCP port to "
- "be used to connect to the agent on a per-host-basis. "),
minvalue = 1,
maxvalue = 65535,
default_value = 6556),
- title = _("TCP port for connection to Check_MK agent")
+ title = _("TCP port for connection to Check_MK agent"),
+ help = _("This variable allows to specify the TCP port to "
+ "be used to connect to the agent on a per-host-basis. "),
+)
+
+register_rule(group,
+ "check_mk_exit_status",
+ Dictionary(
+ elements = [
+ ( "connection",
+ MonitoringState(
+ default_value = 2,
+ title = _("State in case of connection problems")),
+ ),
+ ( "missing_sections",
+ MonitoringState(
+ default_value = 1,
+ title = _("State if just <i>some</i> agent sections are
missing")),
+ ),
+ ( "empty_output",
+ MonitoringState(
+ default_value = 2,
+ title = _("State in case of empty agent output")),
+ ),
+ ( "wrong_version",
+ MonitoringState(
+ default_value = 1,
+ title = _("State in case of wrong agent version")),
+ ),
+ ( "exception",
+ MonitoringState(
+ default_value = 3,
+ title = _("State in case of unhandled exception")),
+ ),
+ ],
+ ),
+ title = _("Status of the Check_MK service"),
+ help = _("This ruleset specifies the total status of the Check_MK service in
"
+ "case of various error situations. One use case is the monitoring
"
+ "of hosts that are not always up. You can have Check_MK an OK status
"
+ "here if the host is not reachable."),
)
register_rule(group,