Search in sources :

Example 1 with WebhookPayload

use of com.navercorp.pinpoint.batch.alarm.vo.sender.payload.WebhookPayload 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);
}
Also used : UserMember(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserMember) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) WebhookPayload(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.WebhookPayload) RestClientException(org.springframework.web.client.RestClientException) Webhook(com.navercorp.pinpoint.web.vo.Webhook) Rule(com.navercorp.pinpoint.web.alarm.vo.Rule) UserGroup(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserGroup)

Aggregations

UserGroup (com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserGroup)1 UserMember (com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserMember)1 WebhookPayload (com.navercorp.pinpoint.batch.alarm.vo.sender.payload.WebhookPayload)1 Rule (com.navercorp.pinpoint.web.alarm.vo.Rule)1 Webhook (com.navercorp.pinpoint.web.vo.Webhook)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestClientException (org.springframework.web.client.RestClientException)1