def _schedule_downtime( sites, command: LivestatusCommand, site_id, host_or_group: str, service_description: Optional[str], start_time: dt.datetime, end_time: dt.datetime, recur: RecurMode = "fixed", trigger_id: int = 0, duration: int = 0, user_id: str = "", comment: str = "", ): """Unified low level function See: * schedule_host_downtime * schedule_service_downtime """ # TODO: provide reference documents for recurring magic numbers _user.need_permission("action.downtimes") recur_mode = _recur_mode(recur, duration) if command == "SCHEDULE_HOST_DOWNTIME": params = [host_or_group] elif command == "SCHEDULE_SVC_DOWNTIME": if not service_description: raise ValueError("Service description necessary.") params = [host_or_group, service_description] else: raise ValueError(f"Unsupported command: {command}") return send_command( sites, command, [ *params, to_timestamp(start_time), to_timestamp(end_time), recur_mode, trigger_id, duration, user_id, comment.replace("\n", ""), ], site_id, )
def force_schedule_host_check(connection, host_name: str, check_time: dt.datetime): """Schedule a forced active check of a particular host Args: connection: A livestatus connection object host_name: The name of the host where the forced check should be performed on check_time: The time at which this forced check should be performed Examples: >>> import pytz >>> _check_time = dt.datetime(1970, 1, 1, tzinfo=pytz.timezone("UTC")) >>> from cmk.gui.livestatus_utils.testing import simple_expect >>> from cmk.gui.config import load_config >>> from cmk.gui.utils.script_helpers import application_and_request_context >>> from cmk.gui.logged_in import SuperUserContext >>> cmd = "COMMAND [...] SCHEDULE_FORCED_HOST_CHECK;example.com;0" >>> expect = simple_expect(cmd, match_type="ellipsis") >>> with expect as live, application_and_request_context(), SuperUserContext(): ... load_config() ... force_schedule_host_check(live, 'example.com', _check_time) """ _user.need_permission("action.reschedule") return send_command(connection, "SCHEDULE_FORCED_HOST_CHECK", [host_name, to_timestamp(check_time)])
def force_schedule_service_check(connection, host_name: str, service_description: str, check_time: dt.datetime): """Schedule a forced active check of a particular service Args: connection: A livestatus connection object host_name: The name of the host where the service is service_description: The service description for which the forced check should be performed on check_time: The time at which this forced check should be performed Examples: >>> import pytz >>> _check_time = dt.datetime(1970, 1, 1, tzinfo=pytz.timezone("UTC")) >>> from cmk.gui.livestatus_utils.testing import simple_expect >>> cmd = "COMMAND [...] SCHEDULE_FORCED_SVC_CHECK;example.com;CPU Load;0" >>> with simple_expect(cmd, match_type="ellipsis") as live: ... force_schedule_service_check(live,'example.com', 'CPU Load', _check_time) """ return send_command( connection, "SCHEDULE_FORCED_SVC_CHECK", [host_name, service_description, to_timestamp(check_time)], )