Search in sources :

Example 1 with Silence

use of io.hops.hopsworks.alerting.api.alert.dto.Silence in project hopsworks by logicalclocks.

the class SilenceBuilder method items.

private SilenceDTO items(SilenceDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, SilenceBeanParam silenceBeanParam, Project project) throws AlertException {
    uri(dto, uriInfo);
    expand(dto, resourceRequest);
    if (dto.isExpand()) {
        List<Silence> silenceList;
        try {
            if (project != null) {
                silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter(), project);
            } else {
                silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter());
            }
        } catch (AlertManagerClientCreateException | AlertManagerUnreachableException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
        } catch (AlertManagerResponseException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.RESPONSE_ERROR, Level.FINE, e.getMessage());
        } catch (AlertManagerAccessControlException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
        }
        if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getStatus())) {
            silenceList = silenceList.stream().filter((s) -> s.getStatus().getState().equals(silenceBeanParam.getSilenceFilterBy().getStatus())).collect(Collectors.toList());
        }
        if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getCreatedBy())) {
            silenceList = silenceList.stream().filter((s) -> s.getCreatedBy().equals(silenceBeanParam.getSilenceFilterBy().getCreatedBy())).collect(Collectors.toList());
        }
        dto.setCount((long) silenceList.size());
        return items(dto, uriInfo, resourceRequest, silenceList, silenceBeanParam);
    }
    return dto;
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerResponseException(io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)

Example 2 with Silence

use of io.hops.hopsworks.alerting.api.alert.dto.Silence in project hopsworks by logicalclocks.

the class AlertManager method getSilence.

public Silence getSilence(String uuid) throws AlertManagerResponseException, AlertManagerClientCreateException, AlertManagerUnreachableException {
    doClientSanityCheck();
    try {
        Silence response = client.getSilence(uuid);
        registerSuccess();
        return response;
    } catch (AlertManagerServerException e) {
        registerServerError();
        throw new AlertManagerUnreachableException("Alertmanager not reachable." + e.getMessage(), e);
    }
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerServerException(io.hops.hopsworks.alerting.exceptions.AlertManagerServerException)

Example 3 with Silence

use of io.hops.hopsworks.alerting.api.alert.dto.Silence in project hopsworks by logicalclocks.

the class AlertManager method getSilences.

public List<Silence> getSilences(Set<String> filters) throws AlertManagerResponseException, AlertManagerClientCreateException, AlertManagerUnreachableException {
    doClientSanityCheck();
    try {
        List<Silence> response = client.getSilences(filters);
        registerSuccess();
        return response;
    } catch (AlertManagerServerException e) {
        registerServerError();
        throw new AlertManagerUnreachableException("Alertmanager not reachable." + e.getMessage(), e);
    }
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerServerException(io.hops.hopsworks.alerting.exceptions.AlertManagerServerException)

Example 4 with Silence

use of io.hops.hopsworks.alerting.api.alert.dto.Silence in project hopsworks by logicalclocks.

the class AlertManagerClient method getSilences.

public List<Silence> getSilences(Set<String> filters) throws AlertManagerResponseException, AlertManagerServerException {
    WebTarget wt = webTarget.path(Settings.ALERTS_API_SILENCES);
    wt = setFilters(wt, filters);
    LOGGER.log(Level.FINE, "Sending request getSilences to: {0}", wt.toString());
    List<Silence> silences = getResponseList(sendRequest(wt.request(MediaType.APPLICATION_JSON), RequestMethod.GET, null), Silence.class);
    return silences;
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) WebTarget(javax.ws.rs.client.WebTarget)

Example 5 with Silence

use of io.hops.hopsworks.alerting.api.alert.dto.Silence in project hopsworks by logicalclocks.

the class AlertManagerClient method getSilence.

public Silence getSilence(String uuid) throws AlertManagerResponseException, AlertManagerServerException {
    WebTarget wt = webTarget.path(Settings.ALERTS_API_SILENCE).path(uuid);
    LOGGER.log(Level.FINE, "Sending request getSilence to: {0}", wt.toString());
    Silence silence = getResponse(sendRequest(wt.request(MediaType.APPLICATION_JSON), RequestMethod.GET, null), Silence.class);
    return silence;
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

PostableSilence (io.hops.hopsworks.alerting.api.alert.dto.PostableSilence)5 Silence (io.hops.hopsworks.alerting.api.alert.dto.Silence)5 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)3 AlertManagerServerException (io.hops.hopsworks.alerting.exceptions.AlertManagerServerException)2 WebTarget (javax.ws.rs.client.WebTarget)2 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)1 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)1 AlertManagerResponseException (io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException)1 AlertException (io.hops.hopsworks.exceptions.AlertException)1