def create_downtime(params): body = params['body'] host_name = body['host_name'] start_dt = _time_dt(body['start_time']) end_dt = _time_dt(body['end_time']) delayed_duration = body.get("delayed_duration", 0) if "recurring_option" not in body: recurring_number = 0 else: recurring_number = RECURRING_OPTIONS[body["recurring_option"]] mode = determine_downtime_mode(recurring_number, delayed_duration) if "service_description" in body: service_description = body["service_description"] spec = _service_spec(service_description, host_name) comment = body.get("comment", "Downtime for service: %s" % service_description) downtime_tag = "SVC" else: spec = host_name downtime_tag = "HOST" comment = body.get("comment", "Downtime for host: %s" % host_name) downtime = DowntimeSchedule(start_dt.timestamp(), end_dt.timestamp(), mode, delayed_duration, comment) command = downtime.livestatus_command(spec, downtime_tag) execute_livestatus_command(command, host_name) return Response(status=204)
def action(self, cmdtag: Any, spec: Any, row: Any, row_index: Any, num_rows: Any) -> Any: """Prepares the livestatus command for any received downtime information through WATO""" if html.request.var("_down_remove"): return self._remove_downtime_details(cmdtag, row) recurring_number = self._recurring_number() title_prefix = self._title_prefix(recurring_number) if html.request.var("_down_from_now"): start_time = self._current_local_time() duration_minutes = self._from_now_minutes() end_time = self._time_after_minutes(start_time, duration_minutes) title = self._title_for_next_minutes(duration_minutes, title_prefix) elif html.request.var("_down_adhoc"): start_time = self._current_local_time() duration_minutes = config.adhoc_downtime.get("duration", 0) end_time = self._time_after_minutes(start_time, duration_minutes) title = self._title_for_next_minutes(duration_minutes, title_prefix) elif html.request.var("_down_custom"): start_time = self._custom_start_time() end_time = self._custom_end_time(start_time) title = self._title_range(start_time, end_time) else: # one of the default time buttons button_value = self.button_interval_value() if button_value is None: # the remove button in the Show Downtimes WATO view returns None here # TODO: separate the remove mechanism from the create downtime procedure in the views call return next_time_interval = button_value start_time = self._current_local_time() end_time = time_interval_end(next_time_interval, start_time) if end_time is None: end_time = start_time + int(next_time_interval) title = time_interval_to_human_readable(next_time_interval, title_prefix) comment = self._comment() delayed_duration = self._flexible_option() mode = determine_downtime_mode(recurring_number, delayed_duration) downtime = DowntimeSchedule(start_time, end_time, mode, delayed_duration, comment) cmdtag, specs, title = self._downtime_specs(cmdtag, row, spec, title) if "aggr_tree" in row: # BI mode node = row["aggr_tree"] return bi_commands(downtime, node), title return [downtime.livestatus_command(spec_, cmdtag) for spec_ in specs], title
def bi_commands(downtime: DowntimeSchedule, node: Any) -> List[Tuple[Any, Any]]: """Generate the list of downtime command strings for the BI module""" commands_aggr = [] for site, host, service in bi.find_all_leaves(node): if service: spec = "%s;%s" % (host, service) cmdtag = "SVC" else: spec = host cmdtag = "HOST" commands_aggr.append((site, downtime.livestatus_command(spec, cmdtag))) return commands_aggr