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)"))
def _title_prefix(self, recurring_number): if recurring_number: from cmk.gui.cee.plugins.wato.cmc import \ recurring_downtimes_types # pylint: disable=no-name-in-module,import-outside-toplevel description = (_("schedule a periodic downtime every %s") % recurring_downtimes_types()[recurring_number]) else: description = _("schedule an immediate downtime") return description
def action(self, cmdtag, spec, row, row_index, num_rows): down_from = int(time.time()) down_to = None if self._has_recurring_downtimes() and html.get_checkbox( "_down_do_recur"): from cmk.gui.cee.plugins.wato.cmc import recurring_downtimes_types recurring_type = int(html.request.var("_down_recurring")) title_start = _("schedule a periodic downtime every %s" ) % recurring_downtimes_types()[recurring_type] else: title_start = _("schedule an immediate downtime") rangebtns = (varname for varname, _value in html.request.itervars( prefix="_downrange")) def resolve_end(name): now = time.localtime(down_from) if name == "next_day": return time.mktime((now.tm_year, now.tm_mon, now.tm_mday, 23, 59, 59, 0, 0, now.tm_isdst)) + 1, \ _("<b>%s until 24:00:00</b> on") % title_start elif name == "next_week": wday = now.tm_wday days_plus = 6 - wday res = time.mktime((now.tm_year, now.tm_mon, now.tm_mday, 23, 59, 59, 0, 0, now.tm_isdst)) + 1 res += days_plus * 24 * 3600 return res, _("<b>%s until sunday night</b> on") % title_start elif name == "next_month": new_month = now.tm_mon + 1 if new_month == 13: new_year = now.tm_year + 1 new_month = 1 else: new_year = now.tm_year return time.mktime((new_year, new_month, 1, 0, 0, 0, 0, 0, now.tm_isdst)), \ _("<b>%s until end of month</b> on") % title_start elif name == "next_year": return time.mktime((now.tm_year, 12, 31, 23, 59, 59, 0, 0, now.tm_isdst)) + 1, \ _("<b>%s until end of %d</b> on") % (title_start, now.tm_year) else: duration = int(name) return down_from + duration, \ _("<b>%s of %s length</b> on") %\ (title_start, self._get_duration_human_readable(duration)) try: rangebtn = next(rangebtns) except StopIteration: rangebtn = None if rangebtn: _btnname, end = rangebtn.split("__", 1) down_to, title = resolve_end(end) elif html.request.var("_down_from_now"): try: minutes = int(html.request.var("_down_minutes", "")) except ValueError: minutes = 0 if minutes <= 0: raise MKUserError( "_down_minutes", _("Please enter a positive number of minutes.")) down_to = time.time() + minutes * 60 title = _("<b>%s for the next %d minutes</b> on") % (title_start, minutes) elif html.request.var("_down_adhoc"): minutes = config.adhoc_downtime.get("duration", 0) down_to = time.time() + minutes * 60 title = _("<b>%s for the next %d minutes</b> on") % (title_start, minutes) elif html.request.var("_down_custom"): down_from = html.get_datetime_input("_down_from") down_to = html.get_datetime_input("_down_to") if down_to < time.time(): raise MKUserError( "_down_to", _("You cannot set a downtime that ends in the past. " "This incident will be reported.")) if down_to < down_from: raise MKUserError( "_down_to", _("Your end date is before your start date.")) title = _("<b>schedule a downtime from %s to %s</b> on ") % ( time.asctime(time.localtime(down_from)), time.asctime(time.localtime(down_to))) elif html.request.var("_down_remove") and config.user.may( "action.remove_all_downtimes"): if html.request.var("_on_hosts"): raise MKUserError( "_on_hosts", _("The checkbox for setting host downtimes does not work when removing downtimes." )) downtime_ids = [] if cmdtag == "HOST": prefix = "host_" else: prefix = "service_" for id_ in row[prefix + "downtimes"]: if id_ != "": downtime_ids.append(int(id_)) commands = [] for dtid in downtime_ids: commands.append("DEL_%s_DOWNTIME;%d\n" % (cmdtag, dtid)) title = _("<b>remove all scheduled downtimes</b> of ") return commands, title if down_to: if html.request.var("_down_adhoc"): comment = config.adhoc_downtime.get("comment", "") else: comment = html.get_unicode_input("_down_comment") if not comment: raise MKUserError( "_down_comment", _("You need to supply a comment for your downtime.")) if html.request.var("_down_flexible"): fixed = 0 duration = html.get_time_input("_down_duration", _("the duration")) else: fixed = 1 duration = 0 if html.get_checkbox("_down_do_recur"): fixed_and_recurring = recurring_type * 2 + fixed else: fixed_and_recurring = fixed def make_command(spec, cmdtag): return ("SCHEDULE_" + cmdtag + "_DOWNTIME;%s;" % spec) + ("%d;%d;%d;0;%d;%s;" % ( down_from, down_to, fixed_and_recurring, duration, config.user.id, )) + livestatus.lqencode(comment) if "aggr_tree" in row: # BI mode commands = [] for site, host, service in bi.find_all_leaves( row["aggr_tree"]): if service: spec = "%s;%s" % (host, service) cmdtag = "SVC" else: spec = host cmdtag = "HOST" commands.append((site, make_command(spec, cmdtag))) else: if html.request.var("_include_childs"): # only for hosts specs = [spec] + self._get_child_hosts( row["site"], [spec], recurse=bool( html.request.var("_include_childs_recurse"))) elif html.request.var( "_on_hosts"): # set on hosts instead of services specs = [spec.split(";")[0]] title += " the hosts of" cmdtag = "HOST" else: specs = [spec] commands = [make_command(spec, cmdtag) for spec in specs] return commands, title
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(" " + _("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(" - ") 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(" " + _('to') + " ") 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()