Search in sources :

Example 1 with Webhook

use of com.navercorp.pinpoint.web.vo.Webhook 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)

Example 2 with Webhook

use of com.navercorp.pinpoint.web.vo.Webhook in project pinpoint by naver.

the class MemoryWebhookSendInfoDao method selectWebhookSendInfoByApplicationId.

@Override
public List<WebhookSendInfo> selectWebhookSendInfoByApplicationId(String applicationId) {
    List<WebhookSendInfo> selectedWebhookSendInfos = new LinkedList<>();
    List<Webhook> webhooks = webhookDao.selectWebhookByApplicationId(applicationId);
    for (Webhook webhook : webhooks) {
        for (WebhookSendInfo webhookSendInfo : webhookSendInfos.values()) {
            if (webhook.getWebhookId().equals(webhookSendInfo.getWebhookId())) {
                selectedWebhookSendInfos.add(webhookSendInfo);
            }
        }
    }
    return selectedWebhookSendInfos;
}
Also used : Webhook(com.navercorp.pinpoint.web.vo.Webhook) WebhookSendInfo(com.navercorp.pinpoint.web.vo.WebhookSendInfo) LinkedList(java.util.LinkedList)

Example 3 with Webhook

use of com.navercorp.pinpoint.web.vo.Webhook in project pinpoint by naver.

the class WebhookSendInfoServiceImplTest method before.

@Before
public void before() {
    webhookSendInfoList = new ArrayList<>(3);
    webhookSendInfoList.add(new WebhookSendInfo("0", "1340", "4115234"));
    webhookSendInfoList.add(new WebhookSendInfo("1", "5134", "4115234"));
    webhookSendInfoList.add(new WebhookSendInfo("2", "5134", "4115230"));
    webhookList = new ArrayList<>(2);
    webhookList.add(new Webhook("1340", "webhook", "testUrl", "testApp", "testGroup"));
    webhookList.add(new Webhook("1341", "webhook1", "testUrl1", "testApp", "testGroup"));
}
Also used : Webhook(com.navercorp.pinpoint.web.vo.Webhook) WebhookSendInfo(com.navercorp.pinpoint.web.vo.WebhookSendInfo) Before(org.junit.Before)

Example 4 with Webhook

use of com.navercorp.pinpoint.web.vo.Webhook in project pinpoint by naver.

the class WebhookServiceImplTest method before.

@Before
public void before() {
    webhookList = new ArrayList<>(2);
    webhookList.add(new Webhook("1340", "webhook", "testUrl", "testApp", "testGroup"));
    webhookList.add(new Webhook("1341", "webhook1", "testUrl1", "testApp", "testGroup1"));
    webhookList.add(new Webhook("1342", "webhook2", "testUrl2", "testApp1", "testGroup1"));
}
Also used : Webhook(com.navercorp.pinpoint.web.vo.Webhook) Before(org.junit.Before)

Example 5 with Webhook

use of com.navercorp.pinpoint.web.vo.Webhook in project pinpoint by naver.

the class WebhookServiceImplTest method insertAndDeleteWebhookTest.

@Test
public void insertAndDeleteWebhookTest() {
    WebhookSendInfoDao webhookSendInfoDao = new MemoryWebhookSendInfoDao(mock(WebhookDao.class));
    WebhookDao webhookDao = new MemoryWebhookDao(mock(AlarmDao.class));
    WebhookService webhookService = new WebhookServiceImpl(webhookDao, webhookSendInfoDao);
    Webhook webhook = new Webhook("0", "alias", "url", "applicationId", "groupId");
    webhookService.insertWebhook(webhook);
    Webhook selectedWebhook = webhookDao.selectWebhook("0");
    assertEquals(webhook.getWebhookId(), selectedWebhook.getWebhookId());
    assertEquals(webhook.getAlias(), selectedWebhook.getAlias());
    assertEquals(webhook.getUrl(), selectedWebhook.getUrl());
    assertEquals(webhook.getApplicationId(), selectedWebhook.getApplicationId());
    assertEquals(webhook.getServiceName(), selectedWebhook.getServiceName());
    webhookService.deleteWebhook(webhook);
    selectedWebhook = webhookDao.selectWebhook("0");
    assertNull(selectedWebhook);
}
Also used : WebhookSendInfoDao(com.navercorp.pinpoint.web.dao.WebhookSendInfoDao) MemoryWebhookSendInfoDao(com.navercorp.pinpoint.web.dao.memory.MemoryWebhookSendInfoDao) MemoryWebhookDao(com.navercorp.pinpoint.web.dao.memory.MemoryWebhookDao) WebhookDao(com.navercorp.pinpoint.web.dao.WebhookDao) MemoryWebhookDao(com.navercorp.pinpoint.web.dao.memory.MemoryWebhookDao) MemoryWebhookSendInfoDao(com.navercorp.pinpoint.web.dao.memory.MemoryWebhookSendInfoDao) Webhook(com.navercorp.pinpoint.web.vo.Webhook) AlarmDao(com.navercorp.pinpoint.web.dao.AlarmDao) Test(org.junit.Test)

Aggregations

Webhook (com.navercorp.pinpoint.web.vo.Webhook)9 AlarmDao (com.navercorp.pinpoint.web.dao.AlarmDao)4 WebhookDao (com.navercorp.pinpoint.web.dao.WebhookDao)4 WebhookSendInfoDao (com.navercorp.pinpoint.web.dao.WebhookSendInfoDao)4 MemoryWebhookDao (com.navercorp.pinpoint.web.dao.memory.MemoryWebhookDao)4 MemoryWebhookSendInfoDao (com.navercorp.pinpoint.web.dao.memory.MemoryWebhookSendInfoDao)4 Test (org.junit.Test)4 WebhookSendInfo (com.navercorp.pinpoint.web.vo.WebhookSendInfo)3 LinkedList (java.util.LinkedList)2 Before (org.junit.Before)2 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 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestClientException (org.springframework.web.client.RestClientException)1