Module: check_mk
Branch: master
Commit: 416602c49d74f60a9dca72ff985b7656077d9cfb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=416602c49d74f6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 9 15:35:38 2019 +0200
Execute label discovery during regular check execution
This is done in the way the structured status data inventory is done.
CMK-1818
Change-Id: I309208b6e45d36d35e04cd4fdd99288ae64e6a28
---
cmk/gui/plugins/wato/inventory.py | 8 +++++---
cmk_base/checking.py | 16 +++-------------
cmk_base/inventory.py | 31 +++++++++++++++++++++++++------
3 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/cmk/gui/plugins/wato/inventory.py b/cmk/gui/plugins/wato/inventory.py
index aec3f69..8f971e1 100644
--- a/cmk/gui/plugins/wato/inventory.py
+++ b/cmk/gui/plugins/wato/inventory.py
@@ -120,10 +120,12 @@ class RulespecActiveChecksCmkInv(HostRulespec):
)),
("host_label_inventory",
DropdownChoice(
- title=_("Host label inventory"),
+ title=_("Host label discovery"),
+ help=_("All hosts configured via this ruleset will try to find
new "
+ "host labels during every check cycle."),
choices=[
- (True, _("Do automatic host label inventory")),
- (False, _("Do not perform automatic host label
inventory")),
+ (True, _("Do automatic host label discovery")),
+ (False, _("Do not perform automatic host label
discovery")),
],
default_value=True,
)),
diff --git a/cmk_base/checking.py b/cmk_base/checking.py
index f1ac1e0..08d9a8f 100644
--- a/cmk_base/checking.py
+++ b/cmk_base/checking.py
@@ -245,24 +245,14 @@ def _do_all_checks_on_host(sources, hostname, ipaddress,
only_check_plugin_names
else:
missing_sections.add(cmk_base.check_utils.section_name_of(check_plugin_name))
- if config.do_status_data_inventory_for(hostname):
- import cmk_base.inventory as inventory
- inventory.do_status_data_inventory(sources, multi_host_sections, hostname,
ipaddress)
- else:
- _cleanup_status_data(hostname)
+ import cmk_base.inventory as inventory
+ inventory.do_inventory_actions_during_checking_for(sources, multi_host_sections,
hostname,
+ ipaddress)
missing_section_list = sorted(list(missing_sections))
return num_success, missing_section_list
-def _cleanup_status_data(hostname):
- filepath = "%s/%s" % (cmk.utils.paths.status_data_dir, hostname)
- if os.path.exists(filepath): # Remove empty status data files.
- os.remove(filepath)
- if os.path.exists(filepath + ".gz"):
- os.remove(filepath + ".gz")
-
-
def execute_check(multi_host_sections, hostname, ipaddress, check_plugin_name, item,
params,
description):
# Make a bit of context information globally available, so that functions
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index 4090ec7..6ca87b4 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -167,19 +167,38 @@ def do_inv_check(hostname, options):
return status, infotexts, long_infotexts, perfdata
-def do_status_data_inventory(sources, multi_host_sections, hostname, ipaddress):
- if config.is_cluster(hostname):
- return
- # cmk_base/modes/check_mk.py loads check plugins but not inventory plugins
+def do_inventory_actions_during_checking_for(sources, multi_host_sections, hostname,
ipaddress):
+ do_status_data_inventory = not config.is_cluster(hostname) \
+ and config.do_status_data_inventory_for(hostname)
+
+ do_host_label_discovery = config.do_host_label_discovery_for(hostname)
+
+ if not do_status_data_inventory:
+ _cleanup_status_data(hostname)
+
+ if not do_status_data_inventory and not do_host_label_discovery:
+ return # nothing to do here
+
+ # This is called during checking, but the inventory plugins are not loaded yet
import cmk_base.inventory_plugins as inventory_plugins
inventory_plugins.load_plugins(check_api.get_check_api_context,
get_inventory_context)
+
_do_inv_for(
sources,
multi_host_sections=multi_host_sections,
hostname=hostname,
ipaddress=ipaddress,
- do_status_data_inv=True,
- do_host_label_discovery=False)
+ do_status_data_inv=do_status_data_inventory,
+ do_host_label_discovery=do_host_label_discovery,
+ )
+
+
+def _cleanup_status_data(hostname):
+ filepath = "%s/%s" % (cmk.utils.paths.status_data_dir, hostname)
+ if os.path.exists(filepath): # Remove empty status data files.
+ os.remove(filepath)
+ if os.path.exists(filepath + ".gz"):
+ os.remove(filepath + ".gz")
def _do_inv_for(sources, multi_host_sections, hostname, ipaddress, do_status_data_inv,