Example #1
0
def _show_inventory_results_on_console(trees: InventoryTrees) -> None:
    section.section_success(
        "Found %s%s%d%s inventory entries" %
        (tty.bold, tty.yellow, trees.inventory.count_entries(), tty.normal))
    section.section_success(
        "Found %s%s%d%s status entries" %
        (tty.bold, tty.yellow, trees.status_data.count_entries(), tty.normal))
Example #2
0
def _show_inventory_results_on_console(inventory_tree, status_data_tree):
    # type: (StructuredDataTree, 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))
Example #3
0
def _commandline_discovery_on_host(
    host_name: HostName,
    ipaddress: Optional[HostAddress],
    parsed_sections_broker: ParsedSectionsBroker,
    run_plugin_names: Container[CheckPluginName],
    only_new: bool,
    *,
    load_labels: bool,
    only_host_labels: bool,
    on_error: OnError,
) -> None:

    section.section_step("Analyse discovered host labels")

    host_labels = analyse_node_labels(
        host_name=host_name,
        ipaddress=ipaddress,
        parsed_sections_broker=parsed_sections_broker,
        load_labels=load_labels,
        save_labels=True,
        on_error=on_error,
    )

    count = len(host_labels.new) if host_labels.new else (
        "no new" if only_new else "no")
    section.section_success(f"Found {count} host labels")

    if only_host_labels:
        return

    section.section_step("Analyse discovered services")

    service_result = analyse_discovered_services(
        host_name=host_name,
        ipaddress=ipaddress,
        parsed_sections_broker=parsed_sections_broker,
        run_plugin_names=run_plugin_names,
        only_new=only_new,
        on_error=on_error,
    )

    # TODO (mo): for the labels the corresponding code is in _host_labels.
    # We should put the persisting in one place.
    autochecks.save_autochecks_file(host_name, service_result.present)

    new_per_plugin = Counter(s.check_plugin_name for s in service_result.new)
    for name, count in sorted(new_per_plugin.items()):
        console.verbose("%s%3d%s %s\n" %
                        (tty.green + tty.bold, count, tty.normal, name))

    count = len(service_result.new) if service_result.new else (
        "no new" if only_new else "no")
    section.section_success(f"Found {count} services")

    for detail in check_parsing_errors(
            parsed_sections_broker.parsing_errors()).details:
        console.warning(detail)
Example #4
0
def test_section_success(caplog, capsys):
    caplog.set_level(console.VERBOSE, logger="cmk.base")

    section.section_success("hello")

    captured = capsys.readouterr()
    assert "hello" in captured.out
    assert "SUCCESS" in captured.out
    assert captured.out.endswith("\n")
    assert not captured.err
Example #5
0
def _do_discovery_for(
    host_name: HostName,
    ipaddress: Optional[HostAddress],
    parsed_sections_broker: ParsedSectionsBroker,
    run_plugin_names: Container[CheckPluginName],
    only_new: bool,
    discovery_parameters: DiscoveryParameters,
) -> None:

    host_labels = analyse_host_labels(
        host_name=host_name,
        ipaddress=ipaddress,
        parsed_sections_broker=parsed_sections_broker,
        discovery_parameters=discovery_parameters,
    )

    service_result = analyse_discovered_services(
        host_name=host_name,
        ipaddress=ipaddress,
        parsed_sections_broker=parsed_sections_broker,
        discovery_parameters=discovery_parameters,
        run_plugin_names=run_plugin_names,
        only_new=only_new,
    )

    # TODO (mo): for the labels the corresponding code is in _host_labels.
    # We should put the persisting and logging in one place.
    autochecks.save_autochecks_file(host_name, service_result.present)

    new_per_plugin = Counter(s.check_plugin_name for s in service_result.new)
    for name, count in sorted(new_per_plugin.items()):
        console.verbose("%s%3d%s %s\n" %
                        (tty.green + tty.bold, count, tty.normal, name))

    section.section_success("%s, %s" % (
        f"Found {len(service_result.new)} services" if service_result.new else
        "Found no%s services" % (" new" if only_new else ""),
        f"{len(host_labels.new)} host labels" if host_labels.new else
        "no%s host labels" % (" new" if only_new else ""),
    ))
Example #6
0
def _commandline_inventory_on_host(
    *,
    host_config: config.HostConfig,
    run_plugin_names: Container[InventoryPluginName],
    selected_sections: SectionNameCollection,
) -> None:

    section.section_step("Inventorizing")

    inv_result = _inventorize_host(
        host_config=host_config,
        selected_sections=selected_sections,
        run_plugin_names=run_plugin_names,
        retentions_tracker=RetentionsTracker([]),
    )

    for subresult in check_parsing_errors(errors=inv_result.parsing_errors):
        for line in subresult.details:
            console.warning(line)

    # TODO: inv_results.source_results is completely ignored here.
    # We should process the results to make errors visible on the console
    count_i = inv_result.trees.inventory.count_entries()
    count_s = inv_result.trees.status_data.count_entries()
    section.section_success(f"Found {count_i} inventory entries")
    section.section_success(f"Found {count_s} status entries")

    if not host_config.inventory_export_hooks:
        return

    section.section_step("Execute inventory export hooks")

    _run_inventory_export_hooks(host_config, inv_result.trees.inventory)

    count = len(host_config.inventory_export_hooks)
    section.section_success(f"Sucessfully ran {count} export hooks")