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();
}
Aggregations