Exemple #1
0
    def render(self, what):
        html.write_text(_('Downtime Comment') + ": ")
        html.text_input("_down_comment", "", size=60, submit="")
        html.hr()
        html.button("_down_from_now", _("From now for"))
        html.nbsp()
        html.number_input("_down_minutes", 60, size=4, submit="_down_from_now")
        html.write_text("  " + _("minutes"))
        html.hr()
        for time_range in config.user_downtime_timeranges:
            html.button("_downrange__%s" % time_range['end'], _u(time_range['title']))
        if what != "aggr" and config.user.may("action.remove_all_downtimes"):
            html.write_text("   -  ")
            html.button("_down_remove", _("Remove all"))
        html.hr()
        if config.adhoc_downtime and config.adhoc_downtime.get("duration"):
            adhoc_duration = config.adhoc_downtime.get("duration")
            adhoc_comment = config.adhoc_downtime.get("comment", "")
            html.button("_down_adhoc", _("Adhoc for %d minutes") % adhoc_duration)
            html.nbsp()
            html.write_text(_('with comment') + ": ")
            html.write(adhoc_comment)
            html.hr()

        html.button("_down_custom", _("Custom time range"))
        html.datetime_input("_down_from", time.time(), submit="_down_custom")
        html.write_text("  " + _('to') + "  ")
        html.datetime_input("_down_to", time.time() + 7200, submit="_down_custom")
        html.hr()
        html.checkbox("_down_flexible", False, label="%s " % _('flexible with max. duration'))
        html.time_input("_down_duration", 2, 0)
        html.write_text(" " + _('(HH:MM)'))
        if what == "host":
            html.hr()
            html.checkbox("_include_childs", False, label=_('Also set downtime on child hosts'))
            html.write_text("  ")
            html.checkbox("_include_childs_recurse", False, label=_('Do this recursively'))
        elif what == "service":
            html.hr()
            html.checkbox("_on_hosts",
                          False,
                          label=_('Schedule downtimes on the affected '
                                  '<b>hosts</b> instead of on the individual '
                                  'services'))

        if self._has_recurring_downtimes():
            html.hr()
            html.checkbox("_down_do_recur",
                          False,
                          label=_("Repeat this downtime on a regular basis every"))
            html.write_text(" ")

            from cmk.gui.cee.plugins.wato.cmc import recurring_downtimes_types  # pylint: disable=no-name-in-module

            recurring_selections = [
                (str(k), v) for (k, v) in sorted(recurring_downtimes_types().items())
            ]
            html.dropdown("_down_recurring", recurring_selections, deflt="3")
            html.write_text(_("(This only works when using CMC)"))
Exemple #2
0
    def render_input(self, varprefix: str, value: str) -> None:
        if self._label:
            html.write(self._label)
            html.nbsp()

        if value is None:
            clean_choices = self.choices()
        else:
            # Need to create an on the fly metric option
            clean_choices = [
                next(((metric_id, metric_detail['title'])
                      for metric_id, metric_detail in metric_info.items()
                      if metric_id == value), (value, value.title()))
            ]

        html.write(_("Select metric: "))
        html.dropdown(varprefix,
                      self._options_for_html(clean_choices),
                      deflt=self._option_for_html(value),
                      class_="metric-selector",
                      style="width: 250px;",
                      read_only=self._read_only)

        vs_host = MonitoredHostname(
            label=_("Filter metric selection by hostname: "),
            placeholder=_("Hint a hostname"),
            size=20,
        )
        html.br()
        host_varprefix = varprefix + "_hostname_hint"
        vs_host.render_input(host_varprefix, None)
        html.javascript(
            "cmk.valuespecs.transfer_context_onchange('context_host_p_host', %s)"
            % json.dumps(host_varprefix))

        completion_js = '(() => ({host: document.getElementsByName(%s)[0].value}))()' % json.dumps(
            host_varprefix)
        vs_service = MonitoredServiceDescription(
            label=_("Filter metric selection by service: "),
            placeholder=_("Hint a service"),
            completion_params_js=completion_js,
            size=20)
        service_varprefix = varprefix + "_service_hint"
        html.br()
        vs_service.render_input(service_varprefix, None)
        html.javascript(
            "cmk.valuespecs.transfer_context_onchange('context_service_p_service', %s)"
            % json.dumps(service_varprefix))
Exemple #3
0
    def render_input(self, varprefix, value):
        html.open_div(style="white-space: nowrap;")

        super(RuleComment, self).render_input(varprefix, value)

        date_and_user = "******" % (time.strftime(
            "%F", time.localtime()), config.user.id)

        html.nbsp()
        html.icon_button(
            None,
            title=_("Prefix date and your name to the comment"),
            icon="insertdate",
            onclick=
            "cmk.valuespecs.rule_comment_prefix_date_and_user(this, '%s');" %
            date_and_user)
        html.close_div()
Exemple #4
0
    def show(self):
        mode = self._host_mode_ident()
        sites.live().set_prepend_site(True)
        query = "GET hosts\nColumns: name state worst_service_state\nLimit: 100\n"
        view = "host"

        if mode == "problems":
            view = "problemsofhost"
            # Exclude hosts and services in downtime
            svc_query = "GET services\nColumns: host_name\n"\
                        "Filter: state > 0\nFilter: scheduled_downtime_depth = 0\n"\
                        "Filter: host_scheduled_downtime_depth = 0\nAnd: 3"
            problem_hosts = {x[1] for x in sites.live().query(svc_query)}

            query += "Filter: state > 0\nFilter: scheduled_downtime_depth = 0\nAnd: 2\n"
            for host in problem_hosts:
                query += "Filter: name = %s\n" % host
            query += "Or: %d\n" % (len(problem_hosts) + 1)

        hosts = sites.live().query(query)
        sites.live().set_prepend_site(False)
        hosts.sort()

        longestname = 0
        for site, host, state, worstsvc in hosts:
            longestname = max(longestname, len(host))
        if longestname > 15:
            num_columns = 1
        else:
            num_columns = 2

        target = views.get_context_link(config.user.id, view)
        html.open_table(class_="allhosts")
        col = 1
        for site, host, state, worstsvc in hosts:
            if col == 1:
                html.open_tr()
            html.open_td()

            if state > 0 or worstsvc == 2:
                statecolor = 2
            elif worstsvc == 1:
                statecolor = 1
            elif worstsvc == 3:
                statecolor = 3
            else:
                statecolor = 0
            html.open_div(class_=["statebullet", "state%d" % statecolor])
            html.nbsp()
            html.close_div()
            link(host, target + "&host=%s&site=%s" % (html.urlencode(host), html.urlencode(site)))
            html.close_td()
            if col == num_columns:
                html.close_tr()
                col = 1
            else:
                col += 1

        if col < num_columns:
            html.close_tr()
        html.close_table()
Exemple #5
0
    def _show_host_row(self, rendered_hosts, table, hostname, search_text,
                       show_checkboxes, colspan, host_errors,
                       contact_group_names):
        if search_text and (search_text.lower() not in hostname.lower()):
            return

        host = self._folder.host(hostname)
        rendered_hosts.append(hostname)
        effective = host.effective_attributes()

        table.row()

        # Column with actions (buttons)

        if show_checkboxes:
            table.cell(html.render_input(
                "_toggle_group",
                type_="button",
                class_="checkgroup",
                onclick="cmk.selection.toggle_all_rows();",
                value='X'),
                       sortable=False,
                       css="checkbox")
            # Use CSS class "failed" in order to provide information about
            # selective toggling inventory-failed hosts for Javascript
            html.input(name="_c_%s" % hostname,
                       type_="checkbox",
                       value=colspan,
                       class_="failed" if host.discovery_failed() else None)
            html.label("", "_c_%s" % hostname)

        table.cell(_("Actions"), css="buttons", sortable=False)
        self._show_host_actions(host)

        # Hostname with link to details page (edit host)
        table.cell(_("Hostname"))
        errors = host_errors.get(hostname, []) + host.validation_errors()
        if errors:
            msg = _("Warning: This host has an invalid configuration: ")
            msg += ", ".join(errors)
            html.icon(msg, "validation_error")
            html.nbsp()

        if host.is_offline():
            html.icon(_("This host is disabled"), "disabled")
            html.nbsp()

        if host.is_cluster():
            html.icon(
                _("This host is a cluster of %s") %
                ", ".join(host.cluster_nodes()), "cluster")
            html.nbsp()

        html.a(hostname, href=host.edit_url())

        # Show attributes
        for attr in host_attribute_registry.attributes():
            if attr.show_in_table():
                attrname = attr.name()
                if attrname in host.attributes():
                    tdclass, tdcontent = attr.paint(
                        host.attributes()[attrname], hostname)
                else:
                    tdclass, tdcontent = attr.paint(effective.get(attrname),
                                                    hostname)
                    tdclass += " inherited"
                table.cell(attr.title(),
                           escaping.escape_attribute(tdcontent),
                           css=tdclass)

        # Am I authorized?
        reason = host.reason_why_may_not("read")
        if not reason:
            icon = "authok"
            title = _("You have permission to this host.")
        else:
            icon = "autherr"
            title = escaping.strip_tags(reason)

        table.cell(_('Auth'),
                   html.render_icon(icon, title),
                   css="buttons",
                   sortable=False)

        # Permissions and Contact groups - through complete recursion and inhertance
        permitted_groups, host_contact_groups, _use_for_services = host.groups(
        )
        table.cell(
            _("Permissions"),
            HTML(", ").join([
                self._render_contact_group(contact_group_names, g)
                for g in permitted_groups
            ]))
        table.cell(
            _("Contact Groups"),
            HTML(", ").join([
                self._render_contact_group(contact_group_names, g)
                for g in host_contact_groups
            ]))

        if not config.wato_hide_hosttags:
            table.cell(_("Tags"), css="tag-ellipsis")
            tag_groups, show_all_code = self._limit_labels(host.tag_groups())
            html.write(
                cmk.gui.view_utils.render_tag_groups(tag_groups,
                                                     "host",
                                                     with_links=False))
            html.write(show_all_code)

        table.cell(_("Explicit labels"), css="tag-ellipsis")
        labels, show_all_code = self._limit_labels(host.labels())
        html.write(
            cmk.gui.view_utils.render_labels(
                labels,
                "host",
                with_links=False,
                label_sources={k: "explicit"
                               for k in labels.keys()}))
        html.write(show_all_code)

        # Located in folder
        if self._folder.is_search_folder():
            table.cell(_("Folder"))
            html.a(host.folder().alias_path(), href=host.folder().url())
Exemple #6
0
    def render(self, what):
        html.open_div(class_="group")
        html.text_input("_down_comment",
                        id_="down_comment",
                        size=60,
                        label=_("Comment"),
                        required=True)
        html.close_div()

        html.open_div(class_="group")
        html.button("_down_from_now", _("From now for"), cssclass="hot")
        html.nbsp()
        html.text_input("_down_minutes",
                        default_value="60",
                        size=4,
                        submit="_down_from_now",
                        cssclass="number")
        html.write_text("&nbsp; " + _("minutes"))
        html.close_div()

        html.open_div(class_="group")
        for time_range in config.user_downtime_timeranges:
            html.button("_downrange__%s" % time_range['end'], _u(time_range['title']))
        if what != "aggr" and config.user.may("action.remove_all_downtimes"):
            html.write_text(" &nbsp; - &nbsp;")
            html.button("_down_remove", _("Remove all"))
        html.close_div()

        if config.adhoc_downtime and config.adhoc_downtime.get("duration"):
            adhoc_duration = config.adhoc_downtime.get("duration")
            adhoc_comment = config.adhoc_downtime.get("comment", "")
            html.open_div(class_="group")
            html.button("_down_adhoc", _("Adhoc for %d minutes") % adhoc_duration)
            html.nbsp()
            html.write_text(_('with comment') + ": ")
            html.write(adhoc_comment)
            html.close_div()

        html.open_div(class_="group")
        html.button("_down_custom", _("Custom time range"))
        self._vs_down_from().render_input("_down_from", time.time())
        html.write_text("&nbsp; " + _('to') + " &nbsp;")
        self._vs_down_to().render_input("_down_to", time.time() + 7200)
        html.close_div()

        html.open_div(class_="group")
        html.checkbox("_down_flexible", False, label="%s " % _('flexible with max. duration'))
        self._vs_duration().render_input("_down_duration", 7200)
        html.close_div()

        if what == "host":
            html.open_div(class_="group")
            html.checkbox("_include_childs", False, label=_('Also set downtime on child hosts'))
            html.write_text("  ")
            html.checkbox("_include_childs_recurse", False, label=_('Do this recursively'))
            html.close_div()
        elif what == "service":
            html.open_div(class_="group")
            html.checkbox("_on_hosts",
                          False,
                          label=_('Schedule downtimes on the affected '
                                  '<b>hosts</b> instead of on the individual '
                                  'services'))
            html.close_div()

        if self._has_recurring_downtimes():
            html.open_div(class_="group")
            html.checkbox("_down_do_recur",
                          False,
                          label=_("Repeat this downtime on a regular basis every"))

            from cmk.gui.cee.plugins.wato.cmc import recurring_downtimes_types  # pylint: disable=no-name-in-module,import-outside-toplevel

            recurring_selections: Choices = [
                (str(k), v) for (k, v) in sorted(recurring_downtimes_types().items())
            ]
            html.dropdown("_down_recurring", recurring_selections, deflt="3")
            html.write_text(" " + _("(only works with the microcore)"))
            html.close_div()
Exemple #7
0
    def show(self) -> None:
        mode = self._host_mode_ident()
        sites.live().set_prepend_site(True)
        query = "GET hosts\nColumns: name state worst_service_state\nLimit: 100\n"
        view = "host"

        if mode == "problems":
            view = "problemsofhost"
            # Exclude hosts and services in downtime
            svc_query = (
                "GET services\nColumns: host_name\n"
                "Filter: state > 0\nFilter: scheduled_downtime_depth = 0\n"
                "Filter: host_scheduled_downtime_depth = 0\nAnd: 3")
            problem_hosts = {x[1] for x in sites.live().query(svc_query)}

            query += "Filter: state > 0\nFilter: scheduled_downtime_depth = 0\nAnd: 2\n"
            for host in problem_hosts:
                query += "Filter: name = %s\n" % host
            query += "Or: %d\n" % (len(problem_hosts) + 1)

        hosts = sites.live().query(query)
        sites.live().set_prepend_site(False)
        hosts.sort()

        longestname = 0
        for site, host, state, worstsvc in hosts:
            longestname = max(longestname, len(host))
        if longestname > 15:
            num_columns = 1
        else:
            num_columns = 2

        html.open_table(class_="allhosts")
        col = 1
        for site, host, state, worstsvc in hosts:
            if col == 1:
                html.open_tr()
            html.open_td()

            if state > 0 or worstsvc == 2:
                statecolor = 2
            elif worstsvc == 1:
                statecolor = 1
            elif worstsvc == 3:
                statecolor = 3
            else:
                statecolor = 0
            html.open_div(class_=["statebullet", "state%d" % statecolor])
            html.nbsp()
            html.close_div()
            link(
                text=host,
                url=makeuri_contextless(
                    request,
                    [
                        ("view_name", view),
                        ("host", host),
                        ("site", site),
                    ],
                    filename="view.py",
                ),
            )
            html.close_td()
            if col == num_columns:
                html.close_tr()
                col = 1
            else:
                col += 1

        if col < num_columns:
            html.close_tr()
        html.close_table()