コード例 #1
0
ファイル: inventory.py プロジェクト: surajrb/checkmk
def do_inventory_actions_during_checking_for(sources, multi_host_sections,
                                             host_config, ipaddress):
    # type: (data_sources.DataSources, data_sources.MultiHostSections, config.HostConfig, Optional[HostAddress]) -> None
    hostname = host_config.hostname
    do_status_data_inventory = not host_config.is_cluster and host_config.do_status_data_inventory

    if not do_status_data_inventory:
        _cleanup_status_data(hostname)

    if not do_status_data_inventory:
        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  # pylint: disable=import-outside-toplevel
    inventory_plugins.load_plugins(check_api.get_check_api_context,
                                   get_inventory_context)

    config_cache = config.get_config_cache()
    host_config = config_cache.get_host_config(hostname)

    _inventory_tree, status_data_tree = _do_inv_for(
        sources,
        multi_host_sections=multi_host_sections,
        host_config=host_config,
        ipaddress=ipaddress,
    )
    _save_status_data_tree(hostname, status_data_tree)
コード例 #2
0
def _get_inv_info():
    inventory_plugins.load_plugins(
        check_api.get_check_api_context,
        inventory.get_inventory_context,
    )
    assert len(inventory_plugins.inv_info) > 100  # sanity check
    return inventory_plugins.inv_info.copy()
コード例 #3
0
    def load(self):
        import cmk.base.inventory_plugins as inv_plugins  # pylint: disable=import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=import-outside-toplevel
        g_inv_tree = MockStructuredDataTree()
        g_status_tree = MockStructuredDataTree()

        def get_inventory_context():
            return {
                "inv_tree_list": g_inv_tree.get_list,
                "inv_tree": g_inv_tree.get_dict,
            }

        inv_plugins.load_plugins(check_api.get_check_api_context, get_inventory_context)
        return g_inv_tree, g_status_tree
コード例 #4
0
ファイル: __init__.py プロジェクト: n00rm/checkmk
    def load(self):
        if sys.version_info[0] < 3:
            # This has not been ported to Python 3 yet. Prevent mypy in Python 3 mode from following
            import cmk.base.inventory_plugins as inv_plugins
            import cmk.base.check_api as check_api
        g_inv_tree = MockStructuredDataTree()
        g_status_tree = MockStructuredDataTree()

        def get_inventory_context():
            return {
                "inv_tree_list": g_inv_tree.get_list,
                "inv_tree": g_inv_tree.get_dict,
            }

        inv_plugins.load_plugins(check_api.get_check_api_context,
                                 get_inventory_context)
        return g_inv_tree, g_status_tree
コード例 #5
0
ファイル: checking.py プロジェクト: majma24/checkmk
def _get_relevant_raw_sections(services: List[Service], host_config: config.HostConfig):
    # see if we can remove this function, once inventory plugins have been migrated to
    # the new API. In particular, we schould be able to get rid of the imports.

    if host_config.do_status_data_inventory:
        # This is called during checking, but the inventory plugins are not loaded yet
        import cmk.base.inventory_plugins as inventory_plugins  # pylint: disable=import-outside-toplevel
        from cmk.base.check_api import get_check_api_context  # pylint: disable=import-outside-toplevel
        inventory_plugins.load_plugins(get_check_api_context, inventory.get_inventory_context)
        inventory_plugin_names: Iterable[InventoryPluginName] = (
            InventoryPluginName(name.split('.')[0]) for name in inventory_plugins.inv_info)
    else:
        inventory_plugin_names = ()

    return agent_based_register.get_relevant_raw_sections(
        check_plugin_names=(s.check_plugin_name for s in services),
        inventory_plugin_names=inventory_plugin_names,
    )