Search in sources :

Example 1 with WebhookNotifierConfiguration

use of io.gravitee.rest.api.service.impl.alert.WebhookNotifierConfiguration in project gravitee-api-management by gravitee-io.

the class AlertMapper method createAlertWebhookNotifications.

private List<Notification> createAlertWebhookNotifications(AlertInput alertInput) {
    if (alertInput.getWebhook() != null) {
        try {
            WebhookNotifierConfiguration webhookConfig = new WebhookNotifierConfiguration(alertInput.getWebhook().getHttpMethod().getValue(), alertInput.getWebhook().getUrl().strip());
            if (alertInput.getWebhook().getHttpMethod() == HttpMethod.PUT || alertInput.getWebhook().getHttpMethod() == HttpMethod.POST || alertInput.getWebhook().getHttpMethod() == HttpMethod.PATCH) {
                webhookConfig.getHeaders().add(new HttpHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON));
                webhookConfig.setBody(objectMapper.writeValueAsString(alertInput));
            }
            Notification webhookNotification = new Notification();
            webhookNotification.setType(DEFAULT_WEBHOOK_NOTIFIER);
            webhookNotification.setConfiguration(objectMapper.writeValueAsString(webhookConfig));
            return List.of(webhookNotification);
        } catch (JsonProcessingException e) {
            LOGGER.error("Failed to convert AlertWebhook to List<Notification>", e);
        }
    }
    return Collections.emptyList();
}
Also used : HttpHeader(io.gravitee.common.http.HttpHeader) WebhookNotifierConfiguration(io.gravitee.rest.api.service.impl.alert.WebhookNotifierConfiguration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Notification(io.gravitee.notifier.api.Notification)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpHeader (io.gravitee.common.http.HttpHeader)1 Notification (io.gravitee.notifier.api.Notification)1 WebhookNotifierConfiguration (io.gravitee.rest.api.service.impl.alert.WebhookNotifierConfiguration)1