Esempio n. 1
0
    def render(self, row, cell):
        classes = ["perfometer"]
        if is_stale(row):
            classes.append("stale")

        try:
            title, h = Perfometer(row).render()
            if title is None and h is None:
                return "", ""
        except Exception as e:
            logger.exception()
            if config.debug:
                raise
            return " ".join(classes), _("Exception: %s") % e

        content = html.render_div(HTML(h), class_=["content"]) \
                + html.render_div(title, class_=["title"]) \
                + html.render_div("", class_=["glass"])

        # pnpgraph_present: -1 means unknown (path not configured), 0: no, 1: yes
        if display_options.enabled(display_options.X) \
           and row["service_pnpgraph_present"] != 0:
            if metrics.cmk_graphs_possible():
                import cmk.gui.cee.plugins.views.graphs
                url = cmk.gui.cee.plugins.views.graphs.cmk_graph_url(row, "service")
            else:
                url = pnp_url(row, "service")
            disabled = False
        else:
            url = "javascript:void(0)"
            disabled = True

        return " ".join(classes), \
            html.render_a(content=content, href=url, title=html.strip_tags(title),
                          class_=["disabled" if disabled else None])
Esempio n. 2
0
    def _pnp_icon(self, row, what):
        url = self._pnp_graph_icon_link(row, what)

        if not metrics.cmk_graphs_possible(row["site"]):
            # Directly ask PNP for all data, don't try to use the new graph fetching mechanism
            # to keep the number of single requests low
            force_pnp_graphing = True
        else:
            # Don't show the icon with Check_MK graphing. The hover makes no sense and there is no
            # mobile view for graphs, so the graphs on the bottom of the host/service view are enough
            # for the moment.
            if html.is_mobile():
                return

            force_pnp_graphing = False

        return html.render_a(
            content=html.render_icon('pnp', ''),
            href=url,
            onmouseout="cmk.hover.hide()",
            onmouseover=
            "cmk.graph_integration.show_hover_graphs(event, %s, %s, %s, %s, %s);"
            % (
                json.dumps(row['site']),
                json.dumps(row["host_name"]),
                json.dumps(row.get('service_description', '_HOST_')),
                json.dumps(self._pnp_popup_url(row, what)),
                json.dumps(force_pnp_graphing),
            ))
Esempio n. 3
0
    def _pnp_graph_icon_link(self, row, what):
        if display_options.disabled(display_options.X):
            return ""

        if not metrics.cmk_graphs_possible(row["site"]):
            return pnp_url(row, what)

        import cmk.gui.cee.plugins.views.graphs  # pylint: disable=redefined-outer-name,import-error,no-name-in-module
        return cmk.gui.cee.plugins.views.graphs.cmk_graph_url(row, what)  # pylint: disable=no-member
Esempio n. 4
0
def mobile_html_head(title, ready_code=""):
    html.mobile = True
    html.write(
        """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">"""
    )
    html.open_html()
    html.open_head()
    html.meta(content="text/html;",
              charset="utf-8",
              **{"http-equiv": "Content-Type"})
    html.meta(name="viewport", content="initial-scale=1.0")
    html.meta(name="apple-mobile-web-app-capable", content="yes")
    html.meta(name="apple-mobile-web-app-title", content="Check_MK")
    html.title(title)
    html.stylesheet(href="jquery/jquery.mobile-1.0.css")
    html.stylesheet(href="themes/classic/theme.css")

    html.write(
        html._render_opening_tag("link",
                                 rel="apple-touch-icon",
                                 href="themes/classic/images/ios_logo.png",
                                 close_tag=True))
    html.javascript_file(src='js/mobile_min.js')

    if metrics.cmk_graphs_possible():
        html.javascript_file(src='js/graphs.js')

    # Never allow the mobile page to be opened in a frameset. Redirect top page to the current content page.
    # This will result in a full screen mobile interface page.
    html.javascript(
        '''if(top != self) { window.top.location.href = location; }''')

    html.javascript("""
      $(document).ready(function() { %s });
      $(document).ready(function() {
          $("a").click(function (event) {
            event.preventDefault();
            window.location = $(this).attr("href");
          });
      });""" % ready_code)

    html.close_head()
    html.open_body(class_="mobile")
Esempio n. 5
0
    def _parameter_elements(cls):
        elements = [
            # TODO: Cleanup: switch to generic Timerange() valuespec!
            ("timerange",
             DropdownChoice(
                 title=_('Timerange'),
                 default_value='1',
                 choices=[
                     ("0", _("4 Hours")),
                     ("1", _("25 Hours")),
                     ("2", _("One Week")),
                     ("3", _("One Month")),
                     ("4", _("One Year")),
                 ],
             )),
            ("source",
             Integer(
                 title=_("Source (n'th graph)"),
                 default_value=1,
                 minvalue=1,
             )),
        ]

        import cmk.gui.metrics as metrics
        if metrics.cmk_graphs_possible():
            from cmk.gui.cee.plugins.metrics.html_render import default_dashlet_graph_render_options  # pylint: disable=no-name-in-module
            from cmk.gui.cee.plugins.metrics.valuespecs import vs_graph_render_options  # pylint: disable=no-name-in-module

            elements += [
                ("graph_render_options",
                 vs_graph_render_options(
                     default_values=default_dashlet_graph_render_options,
                     exclude=[
                         "show_time_range_previews",
                     ],
                 )),
            ]

        return elements