Пример #1
0
def set_acknowledgement_on_hostgroup(params):
    """Acknowledge for hosts of a host group"""
    body = params['body']
    acknowledge_hostgroup_problem(
        sites.live(),
        params['hostgroup_name'],
        sticky=body['sticky'],
        notify=body['notify'],
        persistent=body['persistent'],
        user=config.user.ident,
        comment=body['comment'],
    )
    return http.Response(status=204)
Пример #2
0
def _set_acknowledgement_on_hostgroup(
    connection,
    hostgroup_name: str,
    sticky: bool,
    notify: bool,
    persistent: bool,
    comment: str,
):
    """Acknowledge for hosts of a host group"""
    acknowledge_hostgroup_problem(
        connection,
        hostgroup_name,
        sticky=sticky,
        notify=notify,
        persistent=persistent,
        user=_user_id(),
        comment=comment,
    )
    return http.Response(status=204)
Пример #3
0
def set_acknowledgement_on_hosts(params):
    """Set acknowledgement on related hosts"""
    body = params['body']
    live = sites.live()

    sticky = body['sticky']
    notify = body['notify']
    persistent = body['persistent']
    comment = body['comment']

    acknowledge_type = body['acknowledge_type']

    if acknowledge_type == 'host':
        name = body['host_name']
        host_state = Query([Hosts.state], Hosts.name == name).value(live)
        if not host_state:
            raise ProblemException(
                status=422,
                title=f'Host {name!r} has no problem.',
            )
        acknowledge_host_problem(
            live,
            name,
            sticky=sticky,
            notify=notify,
            persistent=persistent,
            user=config.user.ident,
            comment=comment,
        )
    elif acknowledge_type == 'hostgroup':
        host_group = body['hostgroup_name']
        try:
            acknowledge_hostgroup_problem(
                live,
                host_group,
                sticky=sticky,
                notify=notify,
                persistent=persistent,
                user=config.user.ident,
                comment=comment,
            )
        except ValueError:
            raise ProblemException(
                404,
                title="Hostgroup could not be found.",
                detail=f"Unknown hostgroup: {host_group}",
            )
    elif acknowledge_type == 'host_by_query':
        query = body['query']
        hosts = Query([Hosts.name], query).fetchall(live)
        if not hosts:
            raise ProblemException(
                status=422,
                title="The provided query returned no monitored hosts",
            )
        for host in hosts:
            acknowledge_host_problem(
                live,
                host.name,
                sticky=sticky,
                notify=notify,
                persistent=persistent,
                user=config.user.ident,
                comment=comment,
            )
    else:
        raise ProblemException(
            status=400,
            title="Unhandled acknowledge-type.",
            detail=
            f"The acknowledge-type {acknowledge_type!r} is not supported.",
        )

    return http.Response(status=204)