示例#1
0
def _show_inventory_results_on_console(
        inventory_tree: StructuredDataTree,
        status_data_tree: StructuredDataTree) -> None:
    section.section_success(
        "Found %s%s%d%s inventory entries" %
        (tty.bold, tty.yellow, inventory_tree.count_entries(), tty.normal))
    section.section_success(
        "Found %s%s%d%s status entries" %
        (tty.bold, tty.yellow, status_data_tree.count_entries(), tty.normal))
示例#2
0
文件: inventory.py 项目: m4c3/checkMK
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]
    hostname = host_config.hostname

    _initialize_inventory_tree()
    inventory_tree = g_inv_tree
    status_data_tree = StructuredDataTree()
    discovered_host_labels = DiscoveredHostLabels(inventory_tree)

    node = inventory_tree.get_dict("software.applications.check_mk.cluster.")
    if host_config.is_cluster:
        node["is_cluster"] = True
        _do_inv_for_cluster(host_config, inventory_tree)
    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.normalize_nodes()
    old_timestamp = _save_inventory_tree(hostname, inventory_tree)
    _run_inventory_export_hooks(host_config, inventory_tree)

    success_msg = [
        "Found %s%s%d%s inventory entries" %
        (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:
        status_data_tree.normalize_nodes()
        _save_status_data_tree(hostname, status_data_tree)

        console.section_success("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