Module: check_mk
Branch: master
Commit: 09058ce0b8648e4c11145e71ac6f2f5fcac066b4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09058ce0b8648e…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Jan 25 12:20:06 2018 +0100
Updated werk 5605; Moved rule option 'Do status data inventory' to 'Do
hardware/software inventory' rule
Change-Id: Iac257e189011318478a523c034c966b727f797cd
---
.werks/5605 | 9 +++++----
cmk_base/checks.py | 11 ++++++++++-
cmk_base/inventory.py | 32 ++++++++++++++++++--------------
web/plugins/wato/inventory.py | 25 ++++++++++++++-----------
4 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/.werks/5605 b/.werks/5605
index 4138368..32d2204 100644
--- a/.werks/5605
+++ b/.werks/5605
@@ -31,10 +31,11 @@ Later in the web GUI both tree objects are merged and visible below
'Inventory'.
Inventory history is only calculated for the inventory data, not for the
status data.
-In order to use this feature you have to enable the rule
-'Do status data inventory' for a host. When it's enabled Check_MK does a
-HW/Sw inventory for this host after every check cycle if and only if there's
-a inventory plugin which fills up status data tree.
+If the rule 'Do hardware/software inventory' is enabled for a host then
+doing status data inventory is also enabled. In this case Check_MK does a
+HW/SW inventory for this host after every check cycle if and only if there's a
+inventory plugin which fills up status data tree.
+Within above ruleset 'do status data inventory' can be disabled.
Notes for inventory plugin development:
Previously an inventory plugin used the functions inv_tree_list and inv_tree
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index 13321b9..e0c9104 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -613,5 +613,14 @@ def get_management_board_precedence(check_plugin_name):
else:
return mgmt_board
+
def do_status_data_inventory_for(hostname):
- return rulesets.in_binary_hostlist(hostname, config.status_data_inventory)
+ rules = config.active_checks.get('cmk_inv')
+ # 'host_extra_conf' is already cached thus we can
+ # use it after every check cycle.
+ params = rulesets.host_extra_conf(hostname, rules)
+ if params:
+ # Means: Enabled "Do hardware/software inventory",
+ # => params is at least [{}]
+ return params[0].get('status_data_inventory', True)
+ return False
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index 9b6bd24..26263ab 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -84,20 +84,18 @@ def do_inv(hostnames):
errors = []
for hostname in hostnames:
try:
- console.verbose("Doing HW/SW-Inventory for %s..." % hostname)
-
if config.is_cluster(hostname):
ipaddress = None
else:
ipaddress = ip_lookup.lookup_ip_address(hostname)
do_inv_for(hostname, ipaddress)
- console.verbose("..OK\n")
+ console.verbose(" OK\n")
except Exception, e:
if cmk.debug.enabled():
raise
- console.verbose("Failed: %s\n" % e)
+ console.verbose(" Failed: %s\n" % e)
errors.append("Failed to inventorize %s: %s" % (hostname, e))
finally:
for data_source, exceptions in
data_sources.get_data_source_errors_of_host(hostname, ipaddress).items():
@@ -173,6 +171,8 @@ def do_inv_check(options, hostname):
def do_inv_for(hostname, ipaddress):
+ console.verbose("Doing HW/SW inventory for %s;" % hostname)
+
_initialize_inventory_tree()
inventory_tree = g_inv_tree
status_data_tree = StructuredDataTree()
@@ -185,15 +185,17 @@ def do_inv_for(hostname, ipaddress):
node["is_cluster"] = False
_do_inv_for_realhost(hostname, ipaddress, inventory_tree, status_data_tree)
- if not status_data_tree.is_empty():
- status_data_tree.normalize_nodes()
- _save_status_data_tree(hostname, status_data_tree)
-
inventory_tree.normalize_nodes()
old_timestamp = _save_inventory_tree(hostname, inventory_tree)
- console.verbose("..%s%s%d%s entries" %
+ console.verbose(" %s%s%d%s entries;" %
(tty.bold, tty.yellow, inventory_tree.count_entries(), tty.normal))
+ if not status_data_tree.is_empty():
+ status_data_tree.normalize_nodes()
+ _save_status_data_tree(hostname, status_data_tree)
+ console.verbose(" Status data inventory: %s%s%d%s entries;" %
+ (tty.bold, tty.yellow, status_data_tree.count_entries(), tty.normal))
+
_run_inventory_export_hooks(hostname, inventory_tree)
return old_timestamp, inventory_tree
@@ -219,6 +221,7 @@ def _do_inv_for_realhost(hostname, ipaddress, inventory_tree,
status_data_tree):
multi_host_sections = sources.get_host_sections(hostname, ipaddress)
+ console.verbose(" Execute inventory plugins;")
import cmk_base.inventory_plugins
for section_name, plugin in cmk_base.inventory_plugins.inv_info.items():
section_content = multi_host_sections.get_section_content(hostname, ipaddress,
@@ -233,7 +236,7 @@ def _do_inv_for_realhost(hostname, ipaddress, inventory_tree,
status_data_tree):
# Note: this also excludes existing sections without info..
continue
- console.verbose(tty.green + tty.bold + section_name + " " +
tty.normal)
+ console.verbose(" %s%s%s%s" % (tty.green, tty.bold, section_name,
tty.normal))
# Inventory functions can optionally have a second argument: parameters.
# These are configured via rule sets (much like check parameters).
@@ -254,6 +257,7 @@ def _do_inv_for_realhost(hostname, ipaddress, inventory_tree,
status_data_tree):
else:
args = [section_content]
inv_function(*args, **kwargs)
+ console.verbose(";")
def _gather_snmp_check_plugin_names_inventory(hostname, ipaddress, on_error,
do_snmp_scan):
@@ -319,12 +323,12 @@ def _save_inventory_tree(hostname, inventory_tree):
if inventory_tree:
old_tree = StructuredDataTree().load_from(filepath)
if old_tree.is_equal(inventory_tree):
- console.verbose("..unchanged")
+ console.verbose(" unchanged;")
else:
if old_tree.is_empty():
- console.verbose("..new")
+ console.verbose(" new;")
else:
- console.verbose("..changed")
+ console.verbose(" changed;")
old_time = os.stat(filepath).st_mtime
arcdir = "%s/%s" % (inventory_archive_dir, hostname)
if not os.path.exists(arcdir):
@@ -361,7 +365,7 @@ def _run_inventory_export_hooks(hostname, inventory_tree):
for hookname, ruleset in config.inv_exports.items():
entries = rulesets.host_extra_conf(hostname, ruleset)
if entries:
- console.verbose(", running %s%s%s%s..." % (tty.blue, tty.bold,
hookname, tty.normal))
+ console.verbose(" running %s%s%s%s;" % (tty.blue, tty.bold,
hookname, tty.normal))
params = entries[0]
try:
cmk_base.inventory_plugins.inv_export[hookname]["export_function"](hostname,
params, inventory_tree.get_raw_tree())
diff --git a/web/plugins/wato/inventory.py b/web/plugins/wato/inventory.py
index 52aac82..698e9eb 100644
--- a/web/plugins/wato/inventory.py
+++ b/web/plugins/wato/inventory.py
@@ -60,6 +60,20 @@ register_rule(group,
"off - so you will get no notifications in that
case."),
default_value = 1,
)),
+ ("status_data_inventory", DropdownChoice(
+ title=_("Status data inventory"),
+ help=_("All hosts configured via this ruleset will do a hardware
and "
+ "software inventory after every check cycle if there's
at least "
+ "one inventory plugin which processes status data. "
+ "<b>Note:</b> in order to get any useful
"
+ "result for agent based hosts make sure that you have
installed "
+ "the agent plugin <tt>mk_inventory</tt> on
these hosts."),
+ choices=[
+ (True, _("Do status data inventory")),
+ (False, _("Do not status data inventory")),
+ ],
+ default_value=True,
+ )),
]
),
title = _("Do hardware/software Inventory"),
@@ -149,14 +163,3 @@ register_rule(group,
),
match = "dict",
)
-
-register_rule(group,
- "status_data_inventory",
- title=_("Do status data inventory"),
- help=_("All hosts configured via this ruleset will do a hardware and "
- "software inventory after every check cycle if there's at least "
- "one inventory plugin which processes status data. "
- "<b>Note:</b> in order to get any useful "
- "result for agent based hosts make sure that you have installed "
- "the agent plugin <tt>mk_inventory</tt> on these
hosts."),
-)