Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def delete_downtime(params):
    """Delete downtime"""
    is_service = Query(
        [Downtimes.is_service],
        Downtimes.id.contains(params['downtime_id']),
    ).value(sites.live())
    downtime_type = "SVC" if is_service else "HOST"
    command_delete = remove_downtime_command(downtime_type, params['downtime_id'])
    execute_livestatus_command(command_delete, params['host_name'])
    return Response(status=204)
Exemplo n.º 3
0
def delete_downtime(params):
    live = sites.live()

    q = Query([Downtimes.id, Downtimes.is_service])

    q = q.filter(Downtimes.id.contains(params['downtime_id']))
    gen_downtime = q.iterate(live)
    downtime_info = next(gen_downtime)
    downtime_type = "SVC" if downtime_info['is_service'] else "HOST"
    command_delete = remove_downtime_command(downtime_type,
                                             params['downtime_id'])
    execute_livestatus_command(command_delete, params['host_name'])
    return Response(status=204)