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