Exemplo n.º 1
0
def print_man_page_table():
    table = []
    for name, path in sorted(all_man_pages().items()):
        try:
            table.append((name, _get_title_from_man_page(Path(path))))
        except MKGeneralException as e:
            sys.stderr.write("ERROR: %s" % e)

    tty.print_table(['Check type', 'Title'], [tty.bold, tty.normal], table)
Exemplo n.º 2
0
def print_man_page_table() -> None:
    table = []
    for name, path in sorted(all_man_pages().items()):
        try:
            table.append([name, get_title_from_man_page(Path(path))])
        except MKGeneralException as e:
            sys.stderr.write(str("ERROR: %s" % e))

    tty.print_table([str("Check type"), str("Title")], [tty.bold, tty.normal], table)
Exemplo n.º 3
0
def test_print_table(capsys):
    tty.reinit()
    tty.print_table(["foo", "bar"], ["", ""],
                    [["Guildo", "Horn"], ["Dieter Thomas", "Kuhn"]])  #
    captured = capsys.readouterr()
    assert captured.out == ("foo           bar \n"
                            "------------- ----\n"
                            "Guildo        Horn\n"
                            "Dieter Thomas Kuhn\n")
    assert captured.err == ""
Exemplo n.º 4
0
def test_print_colored_table(capsys):
    tty.reinit()
    tty.print_table(["foo", "bar"], ["XX", "YY"],
                    [["Angus", "Young"], ["Estas", "Tonne"]])  #
    captured = capsys.readouterr()
    assert captured.out == ("XXfoo  YY bar  \n"
                            "XX-----YY -----\n"
                            "XXAngusYY Young\n"
                            "XXEstasYY Tonne\n")
    assert captured.err == ""
Exemplo n.º 5
0
def test_print_table(capsys):
    tty.reinit()
    tty.print_table(
        ['foo', 'bar'],  #
        ['', ''],
        [['Guildo', 'Horn'], ['Dieter Thomas', 'Kuhn']])
    captured = capsys.readouterr()
    assert captured.out == ('foo           bar \n'
                            '------------- ----\n'
                            'Guildo        Horn\n'
                            'Dieter Thomas Kuhn\n')
    assert captured.err == ''
Exemplo n.º 6
0
def test_print_colored_table(capsys):
    tty.reinit()
    tty.print_table(
        ['foo', 'bar'],  #
        ['XX', 'YY'],
        [['Angus', 'Young'], ['Estas', 'Tonne']])
    captured = capsys.readouterr()
    assert captured.out == ('XXfoo  YY bar  \n'
                            'XX-----YY -----\n'
                            'XXAngusYY Young\n'
                            'XXEstasYY Tonne\n')
    assert captured.err == ''
Exemplo n.º 7
0
def test_print_indented_colored_table(capsys):
    tty.reinit()
    tty.print_table(
        ['foo', 'bar'],  #
        ['XX', 'YY'],
        [['Dieter', 'Bohlen'], ['Thomas', 'Anders']],
        indent='====')
    captured = capsys.readouterr()
    assert captured.out == ('====XXfoo   YY bar   \n'
                            '====XX------YY ------\n'
                            '====XXDieterYY Bohlen\n'
                            '====XXThomasYY Anders\n')
    assert captured.err == ''
Exemplo n.º 8
0
def package_list(args):
    if len(args) > 0:
        for name in args:
            show_package_contents(name)
    else:
        if logger.isEnabledFor(VERBOSE):
            table = []
            for pacname in all_package_names():
                package = read_package_info(pacname)
                table.append((pacname, package["title"], package["num_files"]))
            tty.print_table(["Name", "Title", "Files"], [tty.bold, "", ""], table)
        else:
            for pacname in all_package_names():
                sys.stdout.write("%s\n" % pacname)
Exemplo n.º 9
0
def test_print_indented_colored_table(capsys):
    tty.reinit()
    tty.print_table(
        ["foo", "bar"],
        ["XX", "YY"],
        [["Dieter", "Bohlen"], ["Thomas", "Anders"]],
        indent="===="  #
    )
    captured = capsys.readouterr()
    assert captured.out == ("====XXfoo   YY bar   \n"
                            "====XX------YY ------\n"
                            "====XXDieterYY Bohlen\n"
                            "====XXThomasYY Anders\n")
    assert captured.err == ""
Exemplo n.º 10
0
def package_list(args):
    # type: (List[str]) -> None
    if len(args) > 0:
        for name in args:
            show_package_contents(name)
    else:
        if logger.isEnabledFor(VERBOSE):
            table = []
            for pacname in all_package_names():
                package = read_package_info(pacname)
                if package is None:
                    table.append([pacname, "package info is missing or broken", "0"])
                else:
                    table.append([pacname, package["title"], str(package["num_files"])])
            tty.print_table(["Name", "Title", "Files"], [tty.bold, "", ""], table)
        else:
            for pacname in all_package_names():
                sys.stdout.write("%s\n" % pacname)
Exemplo n.º 11
0
def dump_host(hostname: HostName) -> None:
    config_cache = config.get_config_cache()
    host_config = config_cache.get_host_config(hostname)

    out.output("\n")
    if host_config.is_cluster:
        nodes = host_config.nodes
        if nodes is None:
            raise RuntimeError()
        color = tty.bgmagenta
        add_txt = " (cluster of " + (", ".join(nodes)) + ")"
    else:
        color = tty.bgblue
        add_txt = ""
    out.output("%s%s%s%-78s %s\n" %
               (color, tty.bold, tty.white, hostname + add_txt, tty.normal))

    ipaddress = _ip_address_for_dump_host(
        host_config, family=host_config.default_address_family)

    addresses: Optional[str] = ""
    if not host_config.is_ipv4v6_host:
        addresses = ipaddress
    else:
        try:
            secondary = _ip_address_for_dump_host(
                host_config,
                family=socket.AF_INET
                if host_config.is_ipv6_primary else socket.AF_INET6,
            )
        except Exception:
            secondary = "X.X.X.X"

        addresses = "%s, %s" % (ipaddress, secondary)
        if host_config.is_ipv6_primary:
            addresses += " (Primary: IPv6)"
        else:
            addresses += " (Primary: IPv4)"

    out.output(tty.yellow + "Addresses:              " + tty.normal +
               (addresses if addresses is not None else "No IP") + "\n")

    tag_template = tty.bold + "[" + tty.normal + "%s" + tty.bold + "]" + tty.normal
    tags = [(tag_template % ":".join(t))
            for t in sorted(host_config.tag_groups.items())]
    out.output(tty.yellow + "Tags:                   " + tty.normal +
               ", ".join(tags) + "\n")

    labels = [
        tag_template % ":".join(l) for l in sorted(host_config.labels.items())
    ]
    out.output(tty.yellow + "Labels:                 " + tty.normal +
               ", ".join(labels) + "\n")

    # TODO: Clean this up once cluster parent handling has been moved to HostConfig
    if host_config.is_cluster:
        parents_list = host_config.nodes
        if parents_list is None:
            raise RuntimeError()
    else:
        parents_list = host_config.parents
    if len(parents_list) > 0:
        out.output(tty.yellow + "Parents:                " + tty.normal +
                   ", ".join(parents_list) + "\n")
    out.output(tty.yellow + "Host groups:            " + tty.normal +
               ", ".join(host_config.hostgroups) + "\n")
    out.output(tty.yellow + "Contact groups:         " + tty.normal +
               ", ".join(host_config.contactgroups) + "\n")

    agenttypes = [
        source.description
        for source in sources.make_sources(host_config, ipaddress)
    ]

    if host_config.is_ping_host:
        agenttypes.append("PING only")

    out.output(tty.yellow + "Agent mode:             " + tty.normal)
    out.output(host_config.agent_description + "\n")

    out.output(tty.yellow + "Type of agent:          " + tty.normal)
    if len(agenttypes) == 1:
        out.output(agenttypes[0] + "\n")
    else:
        out.output("\n  ")
        out.output("\n  ".join(agenttypes) + "\n")

    out.output(tty.yellow + "Services:" + tty.normal + "\n")

    headers = ["checktype", "item", "params", "description", "groups"]
    colors = [tty.normal, tty.blue, tty.normal, tty.green, tty.normal]

    table_data = []
    for service in sorted(check_table.get_check_table(hostname).values(),
                          key=lambda s: s.description):
        table_data.append([
            str(service.check_plugin_name),
            str(service.item),
            _evaluate_params(service.parameters),
            service.description,
            ",".join(
                config_cache.servicegroups_of_service(hostname,
                                                      service.description)),
        ])

    tty.print_table(headers, colors, table_data, "  ")
Exemplo n.º 12
0
def dump_host(hostname):
    config_cache = config.get_config_cache()
    host_config = config_cache.get_host_config(hostname)

    console.output("\n")
    if host_config.is_cluster:
        color = tty.bgmagenta
        add_txt = " (cluster of " + (", ".join(host_config.nodes)) + ")"
    else:
        color = tty.bgblue
        add_txt = ""
    console.output(
        "%s%s%s%-78s %s\n" %
        (color, tty.bold, tty.white, hostname + add_txt, tty.normal))

    ipaddress = _ip_address_for_dump_host(host_config)

    addresses = ""
    if not host_config.is_ipv4v6_host:
        addresses = ipaddress
    else:
        try:
            if host_config.is_ipv6_primary:
                secondary = _ip_address_for_dump_host(host_config, 4)
            else:
                secondary = _ip_address_for_dump_host(host_config, 6)
        except:
            secondary = "X.X.X.X"

        addresses = "%s, %s" % (ipaddress, secondary)
        if host_config.is_ipv6_primary:
            addresses += " (Primary: IPv6)"
        else:
            addresses += " (Primary: IPv4)"

    console.output(tty.yellow + "Addresses:              " + tty.normal +
                   (addresses if addresses is not None else "No IP") + "\n")

    tag_template = tty.bold + "[" + tty.normal + "%s" + tty.bold + "]" + tty.normal
    tags = [(tag_template % ":".join(t))
            for t in sorted(host_config.tag_groups.items())]
    console.output(tty.yellow + "Tags:                   " + tty.normal +
                   ", ".join(tags) + "\n")
    # TODO: Clean this up once cluster parent handling has been moved to HostConfig
    if host_config.is_cluster:
        parents_list = host_config.nodes
    else:
        parents_list = host_config.parents
    if len(parents_list) > 0:
        console.output(tty.yellow + "Parents:                " + tty.normal +
                       ", ".join(parents_list) + "\n")
    console.output(
        tty.yellow + "Host groups:            " + tty.normal +
        cmk_base.utils.make_utf8(", ".join(host_config.hostgroups)) + "\n")
    console.output(
        tty.yellow + "Contact groups:         " + tty.normal +
        cmk_base.utils.make_utf8(", ".join(host_config.contactgroups)) + "\n")

    agenttypes = []
    sources = data_sources.DataSources(hostname, ipaddress)
    for source in sources.get_data_sources():
        agenttypes.append(source.describe())

    if host_config.is_ping_host:
        agenttypes.append('PING only')

    console.output(tty.yellow + "Agent mode:             " + tty.normal)
    console.output(sources.describe_data_sources() + "\n")

    console.output(tty.yellow + "Type of agent:          " + tty.normal)
    if len(agenttypes) == 1:
        console.output(agenttypes[0] + "\n")
    else:
        console.output("\n  ")
        console.output("\n  ".join(agenttypes) + "\n")

    console.output(tty.yellow + "Services:" + tty.normal + "\n")
    check_items = check_table.get_sorted_check_table(hostname)

    headers = ["checktype", "item", "params", "description", "groups"]
    colors = [tty.normal, tty.blue, tty.normal, tty.green, tty.normal]

    tty.print_table(headers, colors, [[
        checktype,
        cmk_base.utils.make_utf8(item),
        _evaluate_params(params),
        cmk_base.utils.make_utf8(description),
        cmk_base.utils.make_utf8(",".join(
            config_cache.servicegroups_of_service(hostname, description)))
    ] for checktype, item, params, description in check_items], "  ")
Exemplo n.º 13
0
def dump_host(hostname):
    # type: (HostName) -> None
    config_cache = config.get_config_cache()
    host_config = config_cache.get_host_config(hostname)

    console.output("\n")
    if host_config.is_cluster:
        nodes = host_config.nodes
        if nodes is None:
            raise RuntimeError()
        color = tty.bgmagenta
        add_txt = " (cluster of " + (", ".join(nodes)) + ")"
    else:
        color = tty.bgblue
        add_txt = ""
    console.output(
        "%s%s%s%-78s %s\n" %
        (color, tty.bold, tty.white, hostname + add_txt, tty.normal))

    ipaddress = _ip_address_for_dump_host(host_config)

    addresses = ""  # type: Optional[str]
    if not host_config.is_ipv4v6_host:
        addresses = ipaddress
    else:
        try:
            if host_config.is_ipv6_primary:
                secondary = _ip_address_for_dump_host(host_config, 4)
            else:
                secondary = _ip_address_for_dump_host(host_config, 6)
        except Exception:
            secondary = "X.X.X.X"

        addresses = "%s, %s" % (ipaddress, secondary)
        if host_config.is_ipv6_primary:
            addresses += " (Primary: IPv6)"
        else:
            addresses += " (Primary: IPv4)"

    console.output(tty.yellow + "Addresses:              " + tty.normal +
                   (addresses if addresses is not None else "No IP") + "\n")

    tag_template = tty.bold + "[" + tty.normal + "%s" + tty.bold + "]" + tty.normal
    tags = [(tag_template % ":".join(t))
            for t in sorted(host_config.tag_groups.iteritems())]
    console.output(tty.yellow + "Tags:                   " + tty.normal +
                   ", ".join(tags) + "\n")

    labels = [(tag_template % ":".join(l)).encode("utf-8")
              for l in sorted(host_config.labels.iteritems())]
    console.output(tty.yellow + "Labels:                 " + tty.normal +
                   ", ".join(labels) + "\n")

    # TODO: Clean this up once cluster parent handling has been moved to HostConfig
    if host_config.is_cluster:
        parents_list = host_config.nodes
        if parents_list is None:
            raise RuntimeError()
    else:
        parents_list = host_config.parents
    if len(parents_list) > 0:
        console.output(tty.yellow + "Parents:                " + tty.normal +
                       ", ".join(parents_list) + "\n")
    console.output(tty.yellow + "Host groups:            " + tty.normal +
                   make_utf8(", ".join(host_config.hostgroups)) + "\n")
    console.output(tty.yellow + "Contact groups:         " + tty.normal +
                   make_utf8(", ".join(host_config.contactgroups)) + "\n")

    agenttypes = []
    sources = data_sources.DataSources(hostname, ipaddress)
    for source in sources.get_data_sources():
        agenttypes.append(source.describe())

    if host_config.is_ping_host:
        agenttypes.append('PING only')

    console.output(tty.yellow + "Agent mode:             " + tty.normal)
    console.output(sources.describe_data_sources() + "\n")

    console.output(tty.yellow + "Type of agent:          " + tty.normal)
    if len(agenttypes) == 1:
        console.output(agenttypes[0] + "\n")
    else:
        console.output("\n  ")
        console.output("\n  ".join(agenttypes) + "\n")

    console.output(tty.yellow + "Services:" + tty.normal + "\n")

    headers = ["checktype", "item", "params", "description", "groups"]
    colors = [tty.normal, tty.blue, tty.normal, tty.green, tty.normal]

    table_data = []  # type: tty.TableRows
    for service in sorted(check_table.get_check_table(hostname).values(),
                          key=lambda s: s.description):
        table_data.append(
            (service.check_plugin_name, make_utf8("%s" % service.item),
             _evaluate_params(service.parameters),
             make_utf8(service.description),
             make_utf8(",".join(
                 config_cache.servicegroups_of_service(hostname,
                                                       service.description)))))

    tty.print_table(headers, colors, table_data, "  ")