def test_ParentChildTopologyPage_get_default_view_hostnames(
    rough_livestatus: MockLiveStatusConnection, ) -> None:
    rough_livestatus.expect_query(
        "GET hosts\nColumns: name\nFilter: parents =")
    with rough_livestatus(expect_status_query=True):
        page = ParentChildTopologyPage()
        result_set = page._get_default_view_hostnames(max_nodes=2)
    assert result_set.pop() == "bar<(/"
def test_ParentChildTopologyPage_get_hostnames_from_filters(
        rough_livestatus: MockLiveStatusConnection, mocker) -> None:
    rough_livestatus.expect_query("GET hosts\nColumns: name")

    class MockView:
        context = None

    mocker.patch(
        "cmk.gui.node_visualization.get_topology_view_and_filters",
        return_value=(MockView, []),
    )
    mocker.patch(
        "cmk.gui.plugins.visuals.utils.get_livestatus_filter_headers",
        return_value=[],
    )

    with rough_livestatus(expect_status_query=True):
        page = ParentChildTopologyPage()
        result_set = page._get_hostnames_from_filters()
    assert "foo<(/" in result_set
Пример #3
0
def get_view_menu_items(include_reports: bool) -> List[TopicMenuTopic]:
    # The page types that are implementing the PageRenderer API should also be
    # part of the menu. Bring them into a visual like structure to make it easy to
    # integrate them.
    page_type_items: List[Tuple[str, Tuple[str, Visual]]] = []
    for page_type in pagetypes.all_page_types().values():
        if not issubclass(page_type, pagetypes.PageRenderer):
            continue

        for page in page_type.pages():
            if page._show_in_sidebar():
                visual = page.internal_representation().copy()
                visual[
                    "hidden"] = False  # Is currently to configurable for pagetypes
                visual[
                    "icon"] = None  # Is currently to configurable for pagetypes

                page_type_items.append(
                    (page_type.type_name(), (page.name(), visual)))

    # Apply some view specific filters
    views_to_show = [
        (name, view) for name, view in views.get_permitted_views().items()
        if (not active_config.visible_views or name in active_config.
            visible_views) and (not active_config.hidden_views
                                or name not in active_config.hidden_views)
    ]

    network_topology_visual_spec = ParentChildTopologyPage.visual_spec()
    pages_to_show = [(network_topology_visual_spec["name"],
                      network_topology_visual_spec)]

    visuals_to_show = [("views", e) for e in views_to_show]
    visuals_to_show += [("dashboards", e)
                        for e in dashboard.get_permitted_dashboards().items()]
    visuals_to_show += [("pages", e) for e in pages_to_show]
    visuals_to_show += page_type_items

    if reporting and include_reports:
        reporting.load_reports()
        visuals_to_show += [("reports", e)
                            for e in reporting.permitted_reports().items()]

    return make_topic_menu(visuals_to_show)