def _migrate_pagetype_topics(self, topics: Dict):
        topic_created_for: Set[UserId] = set()

        for page_type_cls in pagetypes.all_page_types().values():
            if not issubclass(page_type_cls, pagetypes.PageRenderer):
                continue

            page_type_cls.load()
            modified_user_instances = set()

            # First modify all instances in memory and remember which things have changed
            for instance in page_type_cls.instances():
                owner = instance.owner()
                instance_modified, topic_created = self._transform_pre_17_topic_to_id(
                    topics, instance.internal_representation())

                if instance_modified and owner:
                    modified_user_instances.add(owner)

                if topic_created and owner:
                    topic_created_for.add(owner)

            # Now persist all modified instances
            for user_id in modified_user_instances:
                page_type_cls.save_user_instances(user_id)

        return topic_created_for
Beispiel #2
0
def get_view_menu_items() -> 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 config.visible_views or name in config.visible_views) and
                     (not config.hidden_views or name not in config.hidden_views)]

    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 += page_type_items

    return make_topic_menu(visuals_to_show)
Beispiel #3
0
def get_view_menu_items():
    # type: () -> Dict[Text, List[ViewMenuItem]]
    # TODO: One bright day drop this whole visuals stuff and only use page_types
    page_type_topics = {
    }  # type: Dict[Text, List[Tuple[Text, Text, str, bool]]]
    for page_type in pagetypes.all_page_types().values():
        if issubclass(page_type, pagetypes.PageRenderer):
            for t, title, url in page_type.sidebar_links():
                page_type_topics.setdefault(t, []).append(
                    (t, title, url, False))

    visuals_topics_with_entries = visuals_by_topic(
        list(views.get_permitted_views().items()) +
        list(dashboard.get_permitted_dashboards().items()))
    all_topics_with_entries = []
    for topic, entries in visuals_topics_with_entries:
        if topic in page_type_topics:
            entries = entries + page_type_topics[topic]
            del page_type_topics[topic]
        all_topics_with_entries.append((topic, entries))

    all_topics_with_entries += page_type_topics.items()

    # Filter hidden / not permitted entries
    by_topic = OrderedDict()  # type: Dict[Text, List[ViewMenuItem]]
    for topic, entries in all_topics_with_entries:
        for t, title, name, is_view in entries:
            if is_view and config.visible_views and name not in config.visible_views:
                continue
            if is_view and config.hidden_views and name in config.hidden_views:
                continue
            if t != topic:
                continue

            url = view_menu_url(name, is_view)
            by_topic.setdefault(topic, []).append(
                ViewMenuItem(title=title, name=name, is_view=is_view, url=url))

    return by_topic
Beispiel #4
0
    def show(self):
        dashboard.load_dashboards()

        def render_topic(topic, entries):
            first = True
            for t, title, name, is_view in entries:
                if is_view and config.visible_views and name not in config.visible_views:
                    continue
                if is_view and config.hidden_views and name in config.hidden_views:
                    continue
                if t == topic:
                    if first:
                        html.begin_foldable_container("views",
                                                      topic,
                                                      False,
                                                      topic,
                                                      indent=True)
                        first = False
                    if is_view:
                        bulletlink(
                            title,
                            "view.py?view_name=%s" % name,
                            onclick=
                            "return cmk.sidebar.wato_views_clicked(this)")
                    elif "?name=" in name:
                        bulletlink(title, name)
                    else:
                        bulletlink(
                            title,
                            'dashboard.py?name=%s' % name,
                            onclick=
                            "return cmk.sidebar.wato_views_clicked(this)")

            # TODO: One day pagestypes should handle the complete snapin.
            # for page_type in pagetypes.all_page_types().values():
            #     if issubclass(page_type, pagetypes.PageRenderer):
            #         for t, title, url in page_type.sidebar_links():
            #             if t == topic:
            #                 bulletlink(title, url)

            if not first:  # at least one item rendered
                html.end_foldable_container()

        # TODO: One bright day drop this whole visuals stuff and only use page_types
        page_type_topics = {}
        for page_type in pagetypes.all_page_types().values():
            if issubclass(page_type, pagetypes.PageRenderer):
                for t, title, url in page_type.sidebar_links():
                    page_type_topics.setdefault(t, []).append(
                        (t, title, url, False))

        visuals_topics_with_entries = visuals_by_topic(
            views.get_permitted_views().items() +
            dashboard.permitted_dashboards().items())
        all_topics_with_entries = []
        for topic, entries in visuals_topics_with_entries:
            if topic in page_type_topics:
                entries = entries + page_type_topics[topic]
                del page_type_topics[topic]
            all_topics_with_entries.append((topic, entries))

        all_topics_with_entries += sorted(page_type_topics.items())

        for topic, entries in all_topics_with_entries:
            render_topic(topic, entries)

        links = []
        if config.user.may("general.edit_views"):
            if config.debug:
                links.append((_("Export"), "export_views.py"))
            links.append((_("Edit"), "edit_views.py"))
            footnotelinks(links)
Beispiel #5
0
def _configure_menu_topics() -> List[TopicMenuTopic]:
    general_items = []

    monitoring_items = [
        TopicMenuItem(
            name="views",
            title=_("Views"),
            url="edit_views.py",
            sort_index=10,
            is_advanced=False,
            icon_name="view",
        ),
        TopicMenuItem(
            name="dashboards",
            title=_("Dashboards"),
            url="edit_dashboards.py",
            sort_index=20,
            is_advanced=False,
            icon_name="dashboard",
        ),
        TopicMenuItem(
            name="reports",
            title=_("Reports"),
            url="edit_reports.py",
            sort_index=30,
            is_advanced=True,
            icon_name="report",
        ),
    ]

    graph_items = []

    for index, page_type in enumerate(pagetypes.all_page_types().values()):
        item = TopicMenuItem(
            name=page_type.type_name(),
            title=page_type.phrase("title_plural"),
            url="%ss.py" % page_type.type_name(),
            sort_index=40 + (index * 10),
            is_advanced=page_type.type_is_advanced(),
            icon_name=page_type.type_name(),
        )

        if page_type.type_name() in ("pagetype_topic", "bookmark_list",
                                     "custom_snapin"):
            general_items.append(item)
        elif "graph" in page_type.type_name():
            graph_items.append(item)
        else:
            monitoring_items.append(item)

    return [
        TopicMenuTopic(
            name="general",
            title=_("General"),
            icon_name="topic_general",
            items=general_items,
        ),
        TopicMenuTopic(
            name="monitoring",
            title=_("Monitoring"),
            icon_name="topic_configure",
            items=monitoring_items,
        ),
        TopicMenuTopic(
            name="graphs",
            title=_("Graphs"),
            icon_name="topic_graphs",
            items=graph_items,
        )
    ]