Search in sources :

Example 6 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsController method getAlerts.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Lists the current alerts.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the alerts.", response = AlertRange.class))
public AlertRange getAlerts(@QueryParam("limit") Integer limit, @QueryParam("type") String type, @QueryParam("subtype") String subtype, @QueryParam("state") String state, @QueryParam("level") String level, @QueryParam("before") String before, @QueryParam("after") String after, @QueryParam("cleared") @DefaultValue("false") String cleared, @QueryParam("filter") String filter) {
    List<Alert> alerts = new ArrayList<>();
    AlertCriteria criteria = createCriteria(limit, type, subtype, state, level, before, after, cleared);
    criteria.orFilter(filter);
    provider.getAlerts(criteria).forEachRemaining(alerts::add);
    return new AlertRange(alerts.stream().map(alertsModel::toModel).collect(Collectors.toList()));
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertRange(com.thinkbiganalytics.alerts.rest.model.AlertRange) ArrayList(java.util.ArrayList) Alert(com.thinkbiganalytics.alerts.api.Alert) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsController method getAlertSummary.

@GET
@Path("/summary")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Lists summary grouped alerts.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns summary of the alerts grouped.", response = AlertRange.class))
public Collection<AlertSummaryGrouped> getAlertSummary(@QueryParam("state") String state, @QueryParam("level") String level, @QueryParam("type") String type, @QueryParam("subtype") String subtype, @QueryParam("cleared") @DefaultValue("false") String cleared) {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = createCriteria(null, type, subtype, state, level, null, null, cleared);
    provider.getAlertsSummary(criteria).forEachRemaining(alerts::add);
    return alertsModel.groupAlertSummaries(alerts);
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsController method createCriteria.

private AlertCriteria createCriteria(Integer limit, String type, String subtype, String stateStr, String levelStr, String before, String after, String cleared) {
    AlertCriteria criteria = provider.criteria();
    new AlertCriteriaInput.Builder().limit(limit).type(type).subtype(subtype).state(stateStr).level(levelStr).before(before).after(after).cleared(cleared).applyToCriteria(criteria);
    /*
        if (limit != null) {
            criteria.limit(limit);
        }
        if (type != null) {
            try {
                criteria.type(URI.create(type));
            }catch (IllegalArgumentException e){

            }
        }
        if (subtype != null) {
            criteria.subtype(subtype);
        }
        if (stateStr != null) {
            try {
                criteria.state(Alert.State.valueOf(stateStr.toUpperCase()));
            }catch (IllegalArgumentException e){

            }
        }
        if (levelStr != null) {
            try {
            criteria.level(Alert.Level.valueOf(levelStr.toUpperCase()));
            }catch (IllegalArgumentException e){

            }
        }
        if (before != null) {
            try {
            criteria.before(Formatters.parseDateTime(before));
            }catch (IllegalArgumentException e){

            }
        }
        if (after != null) {
            try {
            criteria.after(Formatters.parseDateTime(after));
            }catch (IllegalArgumentException e){

            }
        }
        if (cleared != null) {
            criteria.includedCleared(Boolean.parseBoolean(cleared));
        }
*/
    return criteria;
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) AlertCriteriaInput(com.thinkbiganalytics.alerts.api.core.AlertCriteriaInput)

Example 9 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class AlertsCache method fetchUnhandledAlerts.

protected List<AlertSummaryGrouped> fetchUnhandledAlerts() {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = alertProvider.criteria();
    new AlertCriteriaInput.Builder().state(Alert.State.UNHANDLED).asServiceAccount(true).onlyIfChangesDetected(true).applyToCriteria(criteria);
    Iterator<? extends AlertSummary> itr = alertProvider.getAlertsSummary(criteria);
    if (itr.hasNext()) {
        itr.forEachRemaining(alerts::add);
        List<AlertSummaryGrouped> latestAlerts = new ArrayList<>(alertsModel.groupAlertSummaries(alerts));
        return latestAlerts;
    } else {
        return Collections.emptyList();
    }
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) CacheBuilder(com.google.common.cache.CacheBuilder) AlertSummaryGrouped(com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary)

Example 10 with AlertCriteria

use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.

the class FeedsRestController method getAlerts.

private Collection<AlertSummaryGrouped> getAlerts(final String feedName, final String feedId) {
    return metadataAccess.read(() -> {
        String derivedFeedId = feedId;
        // get necessary feed info
        if (StringUtils.isBlank(feedId) && StringUtils.isNotBlank(feedName)) {
            // get the feedId for this feed name
            OpsManagerFeed feed = opsFeedManagerFeedProvider.findByName(feedName);
            if (feed != null) {
                derivedFeedId = feed.getId().toString();
            }
        }
        if (StringUtils.isBlank(derivedFeedId)) {
            return Collections.emptyList();
        }
        List<? extends ServiceLevelAgreementDescription> slas = serviceLevelAgreementDescriptionProvider.findForFeed(opsFeedManagerFeedProvider.resolveId(derivedFeedId));
        List<String> slaIds = new ArrayList<>();
        if (slas != null && !slas.isEmpty()) {
            slaIds = slas.stream().map(sla -> sla.getSlaId().toString()).collect(Collectors.toList());
        }
        List<String> ids = new ArrayList<>();
        ids.addAll(slaIds);
        ids.add(derivedFeedId);
        String filter = ids.stream().collect(Collectors.joining("||"));
        List<AlertSummary> alerts = new ArrayList<>();
        AlertCriteria criteria = alertProvider.criteria().state(Alert.State.UNHANDLED).orFilter(filter);
        alertProvider.getAlertsSummary(criteria).forEachRemaining(alerts::add);
        return alertsModel.groupAlertSummaries(alerts);
    });
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary)

Aggregations

AlertCriteria (com.thinkbiganalytics.alerts.api.AlertCriteria)10 ArrayList (java.util.ArrayList)7 AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)6 Alert (com.thinkbiganalytics.alerts.api.Alert)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)3 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)2 AlertProvider (com.thinkbiganalytics.alerts.api.AlertProvider)2 AlertResponse (com.thinkbiganalytics.alerts.api.AlertResponse)2 AlertCriteriaInput (com.thinkbiganalytics.alerts.api.core.AlertCriteriaInput)2 AlertRange (com.thinkbiganalytics.alerts.rest.model.AlertRange)2 AlertSummaryGrouped (com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped)2 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)2 URI (java.net.URI)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2