예제 #1
0
def update_timeperiod(params):
    """Update a time period"""

    body = params['body']
    name = params['name']
    if name == "24X7":
        raise ProblemException(405, http.client.responses[405],
                               "You cannot change the built-in time period")

    time_period = load_timeperiod(name)
    if time_period is None:
        raise ProblemException(404, http.client.responses[404],
                               f"Time period {name} not found")

    if "exceptions" in body:
        time_period = dict(
            (key, time_period[key])
            for key in [*defines.weekday_ids(), "alias", "exclude"]
            if key in time_period)
        time_period["exceptions"] = _format_exceptions(body["exceptions"])

    if "alias" in body:
        time_period['alias'] = body['alias']

    if "active_time_ranges" in body:
        time_period.update(_daily_time_ranges(body['active_time_ranges']))

    if "exclude" in body:
        time_period["exclude"] = body["exclude"]

    save_timeperiod(name, time_period)
    return Response(status=204)
예제 #2
0
def update_timeperiod(params):
    """Update a time period"""

    body = params["body"]
    name = params["name"]
    if name == "24X7":
        raise ProblemException(405, http.client.responses[405],
                               "You cannot change the built-in time period")
    try:
        time_period = load_timeperiod(name)
    except KeyError:
        raise ProblemException(404, http.client.responses[404],
                               f"Time period {name} not found")

    time_period = _to_api_format(time_period, internal_format=True)

    updated_time_period = _to_checkmk_format(
        alias=body.get("alias", time_period["alias"]),
        periods=_daily_time_ranges(
            body.get("active_time_ranges", time_period["active_time_ranges"])),
        exceptions=_format_exceptions(
            body.get("exceptions", time_period["exceptions"])),
        exclude=body.get("exclude", time_period["exclude"]),
    )

    save_timeperiod(name, updated_time_period)
    return Response(status=204)
예제 #3
0
def create_timeperiod(params):
    """Create a time period"""
    body = params['body']
    exceptions = _format_exceptions(body.get("exceptions", []))
    periods = _daily_time_ranges(body["active_time_ranges"])
    time_period = _time_period(alias=body['alias'],
                               periods=periods,
                               exceptions=exceptions,
                               exclude=body.get("exclude", []))
    save_timeperiod(body['name'], time_period)
    return Response(status=204)
예제 #4
0
def create_timeperiod(params):
    """Create a time period"""
    body = params["body"]
    name = body["name"]
    exceptions = _format_exceptions(body.get("exceptions", []))
    periods = _daily_time_ranges(body["active_time_ranges"])
    time_period = _to_checkmk_format(
        alias=body["alias"], periods=periods, exceptions=exceptions, exclude=body.get("exclude", [])
    )
    save_timeperiod(name, time_period)
    return _serve_time_period(_to_api_format(load_timeperiod(name)))
예제 #5
0
def create_timeperiod(params):
    """Create a time period"""
    body = params['body']
    name = body['name']
    exceptions = _format_exceptions(body.get("exceptions", []))
    periods = _daily_time_ranges(body["active_time_ranges"])
    time_period = _time_period(alias=body['alias'],
                               periods=periods,
                               exceptions=exceptions,
                               exclude=body.get("exclude", []))
    save_timeperiod(name, time_period)
    return _serve_time_period(_readable_format(load_timeperiod(name)))