Package com.squareup.pagerduty.incidents

Examples of com.squareup.pagerduty.incidents.NotifyResult


    @Override
    public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException {
        PagerDuty pagerDuty = PagerDuty.create(subscription.getTarget(), new RestAdapter.Builder()
                .setEndpoint(Endpoints.newFixedEndpoint(baseUrl))
                .build());
        NotifyResult result = null;

        try {
            if (check.getState() == AlertType.ERROR) {
                Trigger trigger = new Trigger.Builder("Check '" + check.getName() + "' has exceeded its threshold.")
                        .withIncidentKey(incidentKey(check))
                        .client("Seyren")
                        .clientUrl(url(check))
                        .addDetails(details(check, alerts))
                        .build();
                result = pagerDuty.notify(trigger);
            } else if (check.getState() == AlertType.OK) {
                Resolution resolution = new Resolution.Builder(incidentKey(check))
                        .withDescription("Check '" + check.getName() + "' has been resolved.")
                        .addDetails(details(check, alerts))
                        .build();
                result = pagerDuty.notify(resolution);
            } else {
                LOGGER.warn("Did not send notification to PagerDuty for check in state: {}", check.getState());
            }
        } catch (Exception e) {
            throw new NotificationFailedException("Failed to send notification to PagerDuty", e);
        }

        if (result != null && !"success".equals(result.status())) {
            throw new NotificationFailedException("Failed to send notification to PagerDuty: '" + result.status() + "', " + result.message());
        }
    }
View Full Code Here

TOP

Related Classes of com.squareup.pagerduty.incidents.NotifyResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.