use of com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserGroup in project pinpoint by naver.
the class WebhookSenderImpl method sendWebhook.
@Override
public void sendWebhook(AlarmChecker<?> checker, int sequenceCount, StepExecution stepExecution) {
Rule rule = checker.getRule();
String userGroupId = rule.getUserGroupId();
List<UserMember> userMembers = userService.selectUserByUserGroupId(userGroupId).stream().map(WebhookSenderImpl::newUser).collect(Collectors.toList());
UserGroup userGroup = new UserGroup(userGroupId, userMembers);
WebhookPayload webhookPayload = webhookPayloadFactory.newPayload(checker, sequenceCount, userGroup);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
List<Webhook> webhookSendInfoList = webhookService.selectWebhookByRuleId(rule.getRuleId());
for (Webhook webhook : webhookSendInfoList) {
try {
HttpEntity<WebhookPayload> httpEntity = new HttpEntity<>(webhookPayload, httpHeaders);
restTemplate.exchange(webhook.getUrl(), HttpMethod.POST, httpEntity, String.class);
logger.info("Successfully sent webhook : {}", webhook);
} catch (RestClientException e) {
logger.warn("Failed at sending webhook. Failed Webhook : {} for Rule : {}", webhook, rule, e);
}
}
logger.info("Finished sending webhooks for rule : {}", rule);
}
Aggregations