Exemplo n.º 1
0
    def _show_view_as_dashlet(self, view_spec: ViewSpec):
        html.add_body_css_class("view")
        html.open_div(id_="dashlet_content_wrapper")

        is_reload = request.has_var("_reload")

        view_display_options = "SIXLW"
        if not is_reload:
            view_display_options += "HR"

        request.set_var("display_options", view_display_options)
        request.set_var("_display_options", view_display_options)
        html.add_body_css_class("dashlet")

        # Need to be loaded before processing the painter_options below.
        # TODO: Make this dependency explicit
        display_options.load_from_html(request, html)

        painter_options = PainterOptions.get_instance()
        painter_options.load(self._dashlet_spec["name"])

        # Here the linked view default context has the highest priority
        # linkedview default>dashlet>url active filter, dashboard
        context = visuals.get_merged_context(self.context,
                                             view_spec["context"])

        view = views.View(self._dashlet_spec["name"], view_spec, context)
        view.row_limit = views.get_limit()
        view.only_sites = visuals.get_only_sites_from_context(context)
        view.user_sorters = views.get_user_sorters()

        views.process_view(views.GUIViewRenderer(view, show_buttons=False))

        html.close_div()
Exemplo n.º 2
0
    def __init__(self, dashboard_name: DashboardName, dashboard: DashboardConfig,
                 dashlet_id: DashletId, dashlet: DashletConfig) -> None:
        super().__init__(dashboard_name=dashboard_name,
                         dashboard=dashboard,
                         dashlet_id=dashlet_id,
                         dashlet=dashlet)

        context = visuals.get_merged_context(
            visuals.get_context_from_uri_vars(["host", "service"], self.single_infos()),
            self._dashlet_spec["context"])

        if any((
                self.type_name() == 'pnpgraph' and
            ("host" not in context or "service" not in context),
                self.type_name() == 'custom_graph' and
                self._dashlet_spec.get('custom_graph') is None,
        )):
            return  # The dashlet is not yet configured

        self._dashlet_spec["_graph_identification"] = self.graph_identification(context)

        graph_recipes = resolve_graph_recipe(self._dashlet_spec["_graph_identification"])
        if not isinstance(graph_recipes, list):
            return
        if graph_recipes:
            self._dashlet_spec["_graph_title"] = graph_recipes[0]["title"]
        else:
            raise MKGeneralException(_("Failed to calculate a graph recipe."))

        # New graphs which have been added via "add to visual" option don't have a timerange
        # configured. So we assume the default timerange here by default.
        self._dashlet_spec.setdefault('timerange', '1')
Exemplo n.º 3
0
def page_index():
    # type: () -> None
    title = _("Check_MK Mobile")
    mobile_html_head(title)
    jqm_page_header(title,
                    right_button=("javascript:document.location.reload();", _("Reload"), "refresh"),
                    id_="data")
    items = []
    for view_name, view_spec in views.get_permitted_views().items():
        if view_spec.get("mobile") and not view_spec.get("hidden"):

            datasource = data_source_registry[view_spec["datasource"]]()
            context = visuals.get_merged_context(
                visuals.get_context_from_uri_vars(datasource.infos),
                view_spec["context"],
            )

            view = views.View(view_name, view_spec, context)
            view.row_limit = views.get_limit()
            view.only_sites = views.get_only_sites()
            view.user_sorters = views.get_user_sorters()

            url = "mobile_view.py?view_name=%s" % view_name
            count = ""
            if not view_spec.get("mustsearch"):
                painter_options = PainterOptions.get_instance()
                painter_options.load(view_name)
                view_renderer = MobileViewRenderer(view)
                # TODO: Horrible API ahead!
                count_num = views.show_view(view, view_renderer, only_count=True)
                count = '<span class="ui-li-count">%d</span>' % count_num

            topic = view_spec.get("topic")
            if topic is None:
                topic = ""
            this_title = '%s %s' % (view_spec.get("linktitle", view_spec["title"]), count)
            items.append((topic, url, this_title))

    jqm_page_index(_("Check_MK Mobile"), items)
    # Link to non-mobile GUI

    html.hr()
    html.open_ul(**{"data-role": "listview", "data-theme": "b", "data-inset": "true"})
    html.open_li()
    html.a(_("Classical web GUI"),
           href="index.py?mobile=",
           **{
               "data-ajax": "false",
               "data-transition": "fade"
           })
    html.close_li()
    html.close_ul()

    html.open_ul(**{"data-role": "listview", "data-theme": "f", "data-inset": "true"})
    html.open_li()
    html.a(_("Logout"), href="logout.py", **{"data-ajax": "false", "data-transition": "fade"})
    html.close_li()
    html.close_ul()
    mobile_html_foot()
Exemplo n.º 4
0
    def _get_context(self) -> Optional[VisualContext]:
        if not self.has_context():
            return None

        return visuals.get_merged_context(
            self._dashboard["context"],
            self._dashlet_spec["context"],
        )
Exemplo n.º 5
0
    def _get_context(self) -> Optional[Dict]:
        if not self.has_context():
            return None

        return visuals.get_merged_context(
            self._dashboard["context"],
            visuals.get_context_from_uri_vars(self.infos(), self.single_infos()),
            self._dashlet_spec["context"],
        )
Exemplo n.º 6
0
def page_index() -> None:
    title = _("Checkmk Mobile")
    mobile_html_head(title)
    jqm_page_header(
        title,
        right_button=("javascript:document.location.reload();", _("Reload"), "refresh"),
        id_="data",
    )
    items = []
    for view_name, view_spec in views.get_permitted_views().items():
        if view_spec.get("mobile") and not view_spec.get("hidden"):

            datasource = data_source_registry[view_spec["datasource"]]()
            context = visuals.get_merged_context(
                visuals.get_context_from_uri_vars(datasource.infos),
                view_spec["context"],
            )

            view = views.View(view_name, view_spec, context)
            view.row_limit = views.get_limit()
            view.only_sites = visuals.get_only_sites_from_context(context)
            view.user_sorters = views.get_user_sorters()
            view.want_checkboxes = views.get_want_checkboxes()

            url = "mobile_view.py?view_name=%s" % view_name
            count = ""
            if not view_spec.get("mustsearch"):
                painter_options = PainterOptions.get_instance()
                painter_options.load(view_name)
                count = '<span class="ui-li-count">%d</span>' % views.get_row_count(view)

            topic = PagetypeTopics.get_topic(view_spec.get("topic", ""))
            items.append((topic.title(), url, "%s %s" % (view_spec["title"], count)))

    jqm_page_index(_("Checkmk Mobile"), items)
    # Link to non-mobile GUI

    html.hr()
    html.open_ul(**{"data-role": "listview", "data-theme": "b", "data-inset": "true"})
    html.open_li()
    html.a(
        _("Classical web GUI"),
        href="index.py?mobile=",
        **{"data-ajax": "false", "data-transition": "fade"},
    )
    html.close_li()
    html.close_ul()

    html.open_ul(**{"data-role": "listview", "data-theme": "f", "data-inset": "true"})
    html.open_li()
    html.a(_("Logout"), href="logout.py", **{"data-ajax": "false", "data-transition": "fade"})
    html.close_li()
    html.close_ul()
    mobile_html_foot()
Exemplo n.º 7
0
    def _show_view_as_dashlet(self, view_spec: ViewSpec):
        html.add_body_css_class("view")
        html.open_div(id_="dashlet_content_wrapper")

        is_reload = request.has_var("_reload")

        view_display_options = "SIXLW"
        if not is_reload:
            view_display_options += "HR"

        request.set_var("display_options", view_display_options)
        request.set_var("_display_options", view_display_options)
        html.add_body_css_class("dashlet")

        # Need to be loaded before processing the painter_options below.
        # TODO: Make this dependency explicit
        display_options.load_from_html(request, html)

        painter_options = PainterOptions.get_instance()
        painter_options.load(self._dashlet_spec["name"])

        # Here the linked view default context has the highest priority
        # linkedview default>dashlet>url active filter> dashboard. However views
        # have the "show_filters" default to prefill the filtermenu with empty
        # valued filters(UX). Those need to be cleared out. Otherwise those
        # empty filters are the highest priority filters and the user can never
        # filter the view.

        view_context = {
            filtername: filtervalues
            for filtername, filtervalues in view_spec["context"].items() if {
                var: value
                for var, value in filtervalues.items()
                # These are the filters request variables. Keep set values
                # For the TriStateFilters unset == ignore == "-1"
                # all other cases unset is an empty string
                if (var.startswith("is_") and value != "-1"
                    )  # TriState filters except ignore
                or (not var.startswith("is_") and value
                    )  # Rest of filters with some value
            }
        }
        context = visuals.get_merged_context(self.context, view_context)

        view = views.View(self._dashlet_spec["name"], view_spec, context)
        view.row_limit = views.get_limit()
        view.only_sites = visuals.get_only_sites_from_context(context)
        view.user_sorters = views.get_user_sorters()

        views.process_view(views.GUIViewRenderer(view, show_buttons=False))

        html.close_div()
Exemplo n.º 8
0
    def _init_graph(self):
        context = visuals.get_merged_context(
            visuals.get_context_from_uri_vars(["host", "service"],
                                              self.single_infos()),
            self._dashlet_spec["context"])
        self._dashlet_spec[
            "_graph_identification"] = self.graph_identification(context)

        graph_recipes = resolve_graph_recipe(
            self._dashlet_spec["_graph_identification"])
        if isinstance(graph_recipes, list) and graph_recipes:
            self._dashlet_spec["_graph_title"] = graph_recipes[0]["title"]
        else:
            raise MKGeneralException(_("Failed to calculate a graph recipe."))
Exemplo n.º 9
0
    def _init_graph(self):
        context = visuals.get_merged_context(
            visuals.get_context_from_uri_vars(["host", "service"], self.single_infos()),
            self._dashlet_spec["context"])
        self._dashlet_spec["_graph_identification"] = self.graph_identification(context)

        try:
            graph_recipes = resolve_graph_recipe(self._dashlet_spec["_graph_identification"])
        except MKMissingDataError:
            raise
        except:
            raise MKGeneralException(_("Failed to calculate a graph recipe."))

        self._dashlet_spec["_graph_title"] = graph_recipes[0]["title"]
Exemplo n.º 10
0
def page_view() -> None:
    view_name = html.request.var("view_name")
    if not view_name:
        return page_index()

    view_spec = views.get_permitted_views().get(view_name)
    if not view_spec:
        raise MKUserError("view_name",
                          "No view defined with the name '%s'." % view_name)

    datasource = data_source_registry[view_spec["datasource"]]()
    context = visuals.get_merged_context(
        visuals.get_context_from_uri_vars(
            datasource.infos, single_infos=view_spec["single_infos"]),
        view_spec["context"],
    )

    view = views.View(view_name, view_spec, context)
    view.row_limit = views.get_limit()
    view.only_sites = visuals.get_only_sites_from_context(context)
    view.user_sorters = views.get_user_sorters()
    view.want_checkboxes = views.get_want_checkboxes()

    title = views.view_title(view.spec, view.context)
    mobile_html_head(title)

    # Need to be loaded before processing the painter_options below.
    # TODO: Make this dependency explicit
    display_options.load_from_html(html)

    painter_options = PainterOptions.get_instance()
    painter_options.load(view_name)

    try:
        views.process_view(MobileViewRenderer(view))
    except Exception as e:
        logger.exception("error showing mobile view")
        if config.debug:
            raise
        html.write("ERROR showing view: %s" %
                   escaping.escape_attribute(str(e)))

    mobile_html_foot()
Exemplo n.º 11
0
def dashlet_http_variables(dashlet: Dashlet) -> HTTPVariables:
    vs_general_settings = dashlet_vs_general_settings(dashlet,
                                                      dashlet.single_infos())
    dashlet_settings = vs_general_settings.value_to_json(dashlet._dashlet_spec)
    dashlet_params = dashlet.vs_parameters()
    assert isinstance(dashlet_params, ValueSpec)  # help mypy
    dashlet_properties = dashlet_params.value_to_json(dashlet._dashlet_spec)

    context = visuals.get_merged_context(
        visuals.get_context_from_uri_vars(["host", "service"],
                                          dashlet.single_infos()),
        dashlet._dashlet_spec["context"])

    args: HTTPVariables = []
    args.append(("settings", json.dumps(dashlet_settings)))
    args.append(("context", json.dumps(context)))
    args.append(("properties", json.dumps(dashlet_properties)))

    return args
Exemplo n.º 12
0
    def _init_graph(self):
        context = visuals.get_merged_context(
            visuals.get_context_from_uri_vars(["host", "service"],
                                              self.single_infos()),
            self._dashlet_spec["context"])
        self._dashlet_spec[
            "_graph_identification"] = self.graph_identification(context)

        try:
            graph_recipes = resolve_graph_recipe(
                self._dashlet_spec["_graph_identification"])
        except MKMissingDataError:
            raise
        except livestatus.MKLivestatusNotFoundError as livestatus_excpt:
            raise MKMissingDataError(
                _("Missing data needed to render this graph. Details: %s") %
                livestatus_excpt)
        except Exception:
            raise MKGeneralException(_("Failed to calculate a graph recipe."))

        self._dashlet_spec["_graph_title"] = graph_recipes[0]["title"]
Exemplo n.º 13
0
def page_view() -> None:
    view_name = html.request.var("view_name")
    if not view_name:
        return page_index()

    view_spec = views.get_permitted_views().get(view_name)
    if not view_spec:
        raise MKUserError("view_name",
                          "No view defined with the name '%s'." % view_name)

    datasource = data_source_registry[view_spec["datasource"]]()
    context = visuals.get_merged_context(
        visuals.get_context_from_uri_vars(
            datasource.infos, single_infos=view_spec["single_infos"]),
        view_spec["context"],
    )

    view = views.View(view_name, view_spec, context)
    view.row_limit = views.get_limit()
    view.only_sites = views.get_only_sites()
    view.user_sorters = views.get_user_sorters()

    title = views.view_title(view_spec)
    mobile_html_head(title)

    painter_options = PainterOptions.get_instance()
    painter_options.load(view_name)

    try:
        view_renderer = MobileViewRenderer(view)
        views.show_view(view, view_renderer)
    except Exception as e:
        logger.exception("error showing mobile view")
        if config.debug:
            raise
        html.write("ERROR showing view: %s" %
                   escaping.escape_attribute(str(e)))

    mobile_html_foot()