Module: check_mk
Branch: master
Commit: 0a36bcc56c23ea7430f19cb072e5a83a2e2b4f24
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0a36bcc56c23ea…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Feb 22 18:51:55 2012 +0100
Make cmk -v host honor option --checks
---
ChangeLog | 2 ++
modules/check_mk.py | 10 ++++++++--
modules/check_mk_base.py | 9 ++++++---
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1196ce3..4a06866 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@
(such as BINTEC routers)
* Check API allows a check to get node information
* FIX: fix problem with check includes in subchecks
+ * Option --checks now also applies to ad-hoc check (e.g.
+ cmk --checks=mrpe,df -v somehost)
WATO:
* Much more checks are configurable via WATO now
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 9a7e5ed..5faee0a 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3511,7 +3511,7 @@ OPTIONS:
--usewalk use snmpwalk stored with --snmpwalk
--debug never catch Python exceptions
--procs N start up to N processes in parallel during --scan-parents
- --checks A,.. restrict inventory to specified checks (tcp/snmp/check type)
+ --checks A,.. restrict checks/inventory to specified checks (tcp/snmp/check type)
NOTES:
-I can be restricted to certain check types. Write '--checks df -I' if you
@@ -4566,5 +4566,11 @@ if __name__ == "__main__":
print "Cannot resolve hostname '%s'." % hostname
sys.exit(2)
- do_check(hostname, ipaddress)
+ # honor --checks= also when checking (makes testing easier)
+ if inventory_checks:
+ check_types = inventory_checks.split(",")
+ else:
+ check_types = None
+
+ do_check(hostname, ipaddress, check_types)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 5856bb0..86cb88e 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -689,7 +689,7 @@ def save_counters(hostname):
# This is the main check function - the central entry point to all and
# everything
-def do_check(hostname, ipaddress):
+def do_check(hostname, ipaddress, only_check_types = None):
if opt_verbose:
sys.stderr.write("Check_mk version %s\n" % check_mk_version)
@@ -698,7 +698,7 @@ def do_check(hostname, ipaddress):
try:
load_counters(hostname)
- agent_version, num_success, error_sections, problems =
do_all_checks_on_host(hostname, ipaddress)
+ 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:
@@ -808,7 +808,7 @@ def convert_check_info():
# Loops over all checks for a host, gets the data, calls the check
# function that examines that data and sends the result to Nagios
-def do_all_checks_on_host(hostname, ipaddress):
+def do_all_checks_on_host(hostname, ipaddress, only_check_types = None):
global g_aggregated_service_results
g_aggregated_service_results = {}
global g_hostname
@@ -819,6 +819,9 @@ def do_all_checks_on_host(hostname, ipaddress):
problems = []
for checkname, item, params, description, info in check_table:
+ if only_check_types != None and checkname not in only_check_types:
+ continue
+
# In case of a precompiled check table info is the aggrated
# service name. In the non-precompiled version there are the dependencies
if type(info) == str: