diff --git a/cmk/gui/plugins/wato/inventory.py b/cmk/gui/plugins/wato/inventory.py index 8f971e1f3023b..d8d406c4cda3b 100644 --- a/cmk/gui/plugins/wato/inventory.py +++ b/cmk/gui/plugins/wato/inventory.py @@ -118,17 +118,6 @@ def valuespec(self): ], default_value=True, )), - ("host_label_inventory", - DropdownChoice( - 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 discovery")), - (False, _("Do not perform automatic host label discovery")), - ], - default_value=True, - )), ]), title=_("Do hardware/software Inventory"), help=_("All hosts configured via this ruleset will do a hardware and " diff --git a/cmk_base/config.py b/cmk_base/config.py index 740933aa7ad7e..30e6f625d6b10 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2553,25 +2553,6 @@ def do_status_data_inventory(self): return params.get('status_data_inventory', False) - @property - def do_host_label_discovery(self): - # type: () -> bool - - # TODO: Use dict(self.active_checks).get("cmk_inv", [])? - rules = active_checks.get('cmk_inv') - if rules is None: - return True - - entries = self._config_cache.host_extra_conf(self.hostname, rules) - - if not entries: - return True # No matching rule -> disable - - # Convert legacy rules to current dict format (just like the valuespec) - params = {} if entries[0] is None else entries[0] - - return params.get("host_label_inventory", True) - @property def service_level(self): # type: () -> Optional[int] diff --git a/cmk_base/discovered_labels.py b/cmk_base/discovered_labels.py index 8dbc55bed943b..f152df0de95cc 100644 --- a/cmk_base/discovered_labels.py +++ b/cmk_base/discovered_labels.py @@ -77,18 +77,6 @@ def add_label(self, label): self._labels[label.name] = label.value self._plugin_name[label.name] = label.plugin_name - # TODO: Once we redesign the hw/sw inventory plugin API check if we can - # move it to the inventory API. - def add_labels_to_inventory_tree(self, inventory_tree): - """Add a label + plugin to the inventory tree - """ - inv_labels = inventory_tree.get_list("software.applications.check_mk.host_labels:") - for label_id, label_value in self._labels.iteritems(): - inv_labels.append({ - "label": (label_id, label_value), - "plugin_name": self._plugin_name[label_id], - }) - class ABCLabel(object): """Representing a service label in Checkmk diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py index 401ed0d4cda39..99859d0c77b26 100644 --- a/cmk_base/inventory.py +++ b/cmk_base/inventory.py @@ -38,7 +38,6 @@ import cmk.utils.tty as tty from cmk.utils.exceptions import MKGeneralException from cmk.utils.structured_data import StructuredDataTree -from cmk.utils.labels import DiscoveredHostLabelsStore import cmk.utils.debug import cmk_base.utils @@ -51,7 +50,6 @@ import cmk_base.cleanup import cmk_base.decorator import cmk_base.check_api as check_api -from cmk_base.discovered_labels import DiscoveredHostLabels #. # .--Inventory-----------------------------------------------------------. @@ -118,7 +116,7 @@ def do_inv_check(hostname, options): status, infotexts, long_infotexts, perfdata = 0, [], [], [] sources = data_sources.DataSources(hostname, ipaddress) - old_timestamp, inventory_tree, status_data_tree, discovered_host_labels = _do_inv_for( + old_timestamp, inventory_tree, status_data_tree = _do_inv_for( sources, multi_host_sections=None, host_config=host_config, @@ -126,8 +124,7 @@ def do_inv_check(hostname, options): do_status_data_inv=host_config.do_status_data_inventory, ) - if (inventory_tree.is_empty() and status_data_tree.is_empty() and - discovered_host_labels.is_empty()): + if inventory_tree.is_empty() and status_data_tree.is_empty(): infotexts.append("Found no data") else: @@ -160,9 +157,6 @@ def do_inv_check(hostname, options): if not status_data_tree.is_empty(): infotexts.append("Found %s status entries" % status_data_tree.count_entries()) - if not discovered_host_labels.is_empty(): - infotexts.append("Found %s host labels" % len(discovered_host_labels)) - for source in sources.get_data_sources(): source_state, source_output, _source_perfdata = source.get_summary_result_for_inventory() # Do not output informational (state = 0) things. These information are shown by the "Check_MK" service @@ -181,7 +175,7 @@ def do_inventory_actions_during_checking_for(sources, multi_host_sections, host_ if not do_status_data_inventory: _cleanup_status_data(hostname) - if not do_status_data_inventory and not host_config.do_host_label_discovery: + if not do_status_data_inventory: return # nothing to do here # This is called during checking, but the inventory plugins are not loaded yet @@ -210,13 +204,12 @@ def _cleanup_status_data(hostname): def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_data_inv): - # type: (data_sources.DataSources, data_sources.MultiHostSections, config.HostConfig, Optional[str], bool) -> Tuple[Optional[float], StructuredDataTree, StructuredDataTree, DiscoveredHostLabels] + # type: (data_sources.DataSources, data_sources.MultiHostSections, config.HostConfig, Optional[str], bool) -> Tuple[Optional[float], StructuredDataTree, StructuredDataTree] hostname = host_config.hostname _initialize_inventory_tree() inventory_tree = g_inv_tree status_data_tree = StructuredDataTree() - discovered_host_labels = DiscoveredHostLabels() node = inventory_tree.get_dict("software.applications.check_mk.cluster.") if host_config.is_cluster: @@ -225,9 +218,8 @@ def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_ else: node["is_cluster"] = False _do_inv_for_realhost(host_config, sources, multi_host_sections, hostname, ipaddress, - inventory_tree, status_data_tree, discovered_host_labels) + inventory_tree, status_data_tree) - discovered_host_labels.add_labels_to_inventory_tree(inventory_tree) inventory_tree.normalize_nodes() old_timestamp = _save_inventory_tree(hostname, inventory_tree) _run_inventory_export_hooks(host_config, inventory_tree) @@ -237,11 +229,6 @@ def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_ (tty.bold, tty.yellow, inventory_tree.count_entries(), tty.normal) ] - if host_config.do_host_label_discovery: - DiscoveredHostLabelsStore(hostname).save(discovered_host_labels.to_dict()) - success_msg.append("and %s%s%d%s host labels" % - (tty.bold, tty.yellow, len(discovered_host_labels), tty.normal)) - console.section_success(", ".join(success_msg)) if do_status_data_inv: @@ -252,7 +239,7 @@ def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_ "Found %s%s%d%s status entries" % (tty.bold, tty.yellow, status_data_tree.count_entries(), tty.normal)) - return old_timestamp, inventory_tree, status_data_tree, discovered_host_labels + return old_timestamp, inventory_tree, status_data_tree def _do_inv_for_cluster(host_config, inventory_tree): @@ -268,7 +255,7 @@ def _do_inv_for_cluster(host_config, inventory_tree): def _do_inv_for_realhost(host_config, sources, multi_host_sections, hostname, ipaddress, - inventory_tree, status_data_tree, discovered_host_labels): + inventory_tree, status_data_tree): for source in sources.get_data_sources(): if isinstance(source, data_sources.SNMPDataSource): source.set_on_error("raise") @@ -321,7 +308,6 @@ def _do_inv_for_realhost(host_config, sources, multi_host_sections, hostname, ip for dynamic_arg_name, dynamic_arg_value in [ ("inventory_tree", inventory_tree), ("status_data_tree", status_data_tree), - ("discovered_host_labels", discovered_host_labels), ]: if dynamic_arg_name in inv_function_args: inv_function_args.remove(dynamic_arg_name) diff --git a/inventory/labels b/inventory/labels deleted file mode 100644 index 1a0c5e1a37914..0000000000000 --- a/inventory/labels +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2019 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# tails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -# Example outputs: -# <<>> -# {"tier": "control-plane", "component": "kube-scheduler"} - -import json - - -def inv_labels(info, discovered_host_labels): - for key, value in _parse_labels(info).items(): - discovered_host_labels.add_label(key, value, plugin_name="labels") - - -def _parse_labels(info): - return json.loads(info[0][0]) - - -inv_info['labels'] = { - "inv_function": inv_labels, -} diff --git a/inventory/lnx_distro b/inventory/lnx_distro index 7f232c7018251..a58e8ea7c0432 100644 --- a/inventory/lnx_distro +++ b/inventory/lnx_distro @@ -44,7 +44,7 @@ # /etc/oracle-release|Oracle LinuxServer release 7.1 -def inv_lnx_distro(info, inventory_tree, discovered_host_labels): +def inv_lnx_distro(info, inventory_tree): parsed = _parse_lnx_distro(info) node = inventory_tree.get_dict("software.os.") @@ -63,10 +63,6 @@ def inv_lnx_distro(info, inventory_tree, discovered_host_labels): handler(node, parsed[file_name]) break - if "name" in node: - discovered_host_labels.add_label( - HostLabel(u"os", unicode(node["name"]), discovered_by=("inventory", "lnx_distro")),) # pylint: disable=undefined-variable - def _parse_lnx_distro(info): parsed = {} diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 8773c7c984d8b..eda07212e80ce 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -1567,28 +1567,6 @@ def test_host_config_do_status_data_inventory(monkeypatch, result, ruleset): assert config_cache.get_host_config("abc").do_status_data_inventory == result -@pytest.mark.parametrize("result,ruleset", [ - (True, None), - (True, []), - (True, [(None, [], config.ALL_HOSTS, {})]), - (True, [({}, [], config.ALL_HOSTS, {})]), - (True, [({ - "host_label_inventory": True - }, [], config.ALL_HOSTS, {})]), - (False, [({ - "host_label_inventory": False - }, [], config.ALL_HOSTS, {})]), -]) -def test_host_config_do_host_label_discovery_for(monkeypatch, result, ruleset): - ts = Scenario().add_host("abc") - ts.set_option("active_checks", { - "cmk_inv": ruleset, - }) - config_cache = ts.apply(monkeypatch) - - assert config_cache.get_host_config("abc").do_host_label_discovery == result - - @pytest.mark.parametrize("hostname,result", [ ("testhost1", None), ("testhost2", 10), diff --git a/tests/unit/cmk_base/test_discovered_labels.py b/tests/unit/cmk_base/test_discovered_labels.py index 12d675a5aa942..4f7cf9b039970 100644 --- a/tests/unit/cmk_base/test_discovered_labels.py +++ b/tests/unit/cmk_base/test_discovered_labels.py @@ -96,21 +96,6 @@ def test_discovered_host_labels_store_save(discovered_host_labels_dir): assert store.load() == label_dict -def test_discovered_host_labels_store_to_inventory_tree(discovered_host_labels_dir): - labels = DiscoveredHostLabels(HostLabel(u"xyz", u"äbc", plugin_name="plugin_name_1")) - - tree = StructuredDataTree() - labels.add_labels_to_inventory_tree(tree) - - inv_labels = tree.get_list("software.applications.check_mk.host_labels:") - assert inv_labels == [ - { - "label": (u"xyz", u"äbc"), - "plugin_name": "plugin_name_1" - }, - ] - - def test_service_label(): name, value = u"äbc", u"d{--lulu--}dd" l = ServiceLabel(name, value)