@Test public void basicHappyPathTest() throws Exception { Check check = new Check() .withEnabled(true) .withName("test-check") .withState(AlertType.ERROR); Subscription subscription = new Subscription() .withEnabled(true) .withType(SubscriptionType.HIPCHAT) .withTarget("target"); Alert alert = new Alert() .withFromType(AlertType.OK) .withToType(AlertType.ERROR); List<Alert> alerts = Arrays.asList(alert); String seyrenUrl = URLEncoder.encode(seyrenConfig.getBaseUrl(), "UTF-8"); clientDriver.addExpectation( onRequestTo("/v2/room/target/notification") .withMethod(Method.POST) .withParam("auth_token",seyrenConfig.getHipChatAuthToken()) .withBody(is("message=Check+%3Ca+href%3D" + seyrenUrl + "%2F%23%2Fchecks%2Fnull%3Etest-check%3C%2Fa%3E+has+entered+its+ERROR+state." + "&color=red" + "&message_format=html" + "&notify=true"), "application/x-www-form-urlencoded"), giveEmptyResponse()); notificationService.sendNotification(check, subscription, alerts); }
@Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = seyrenConfig.getHipChatAuthToken(); String from = seyrenConfig.getHipChatUsername(); String[] roomIds = subscription.getTarget().split(","); try { if (check.getState() == AlertType.ERROR) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.RED, roomIds, from, token, true); } else if (check.getState() == AlertType.WARN) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.YELLOW, roomIds, from, token, true); } else if (check.getState() == AlertType.OK) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.GREEN, roomIds, from, token, true); } else { LOGGER.warn("Did not send notification to HipChat for check in state: {}", check.getState()); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to HipChat", e); } }
HipChatNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = seyrenConfig.getHipChatAuthToken(); String from = seyrenConfig.getHipChatUsername(); String[] roomIds = subscription.getTarget().split(","); try { if (check.getState() == AlertType.ERROR) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.RED, roomIds, from, token, true); } else if (check.getState() == AlertType.WARN) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.YELLOW, roomIds, from, token, true); } else if (check.getState() == AlertType.OK) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.GREEN, roomIds, from, token, true); } else { LOGGER.warn("Did not send notification to HipChat for check in state: {}", check.getState()); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to HipChat", e); } } }
HipChatNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = seyrenConfig.getHipChatAuthToken(); String from = seyrenConfig.getHipChatUsername(); String[] roomIds = subscription.getTarget().split(","); try { if (check.getState() == AlertType.ERROR) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.RED, roomIds, from, token, true); } else if (check.getState() == AlertType.WARN) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.YELLOW, roomIds, from, token, true); } else if (check.getState() == AlertType.OK) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.GREEN, roomIds, from, token, true); } else { LOGGER.warn("Did not send notification to HipChat for check in state: {}", check.getState()); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to HipChat", e); } } @Inject  HipChatNotificationService(SeyrenConfig seyrenConfig); protected  HipChatNotificationService(SeyrenConfig seyrenConfig, String baseUrl); }
HipChatNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = seyrenConfig.getHipChatAuthToken(); String from = seyrenConfig.getHipChatUsername(); String[] roomIds = subscription.getTarget().split(","); try { if (check.getState() == AlertType.ERROR) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.RED, roomIds, from, token, true); } else if (check.getState() == AlertType.WARN) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.YELLOW, roomIds, from, token, true); } else if (check.getState() == AlertType.OK) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.GREEN, roomIds, from, token, true); } else { LOGGER.warn("Did not send notification to HipChat for check in state: {}", check.getState()); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to HipChat", e); } } @Inject  HipChatNotificationService(SeyrenConfig seyrenConfig); protected  HipChatNotificationService(SeyrenConfig seyrenConfig, String baseUrl); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType); }
HipChatNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = seyrenConfig.getHipChatAuthToken(); String from = seyrenConfig.getHipChatUsername(); String[] roomIds = subscription.getTarget().split(","); try { if (check.getState() == AlertType.ERROR) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.RED, roomIds, from, token, true); } else if (check.getState() == AlertType.WARN) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.YELLOW, roomIds, from, token, true); } else if (check.getState() == AlertType.OK) { String message = getHipChatMessage(check); sendMessage(message, MessageColor.GREEN, roomIds, from, token, true); } else { LOGGER.warn("Did not send notification to HipChat for check in state: {}", check.getState()); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to HipChat", e); } } @Inject  HipChatNotificationService(SeyrenConfig seyrenConfig); protected  HipChatNotificationService(SeyrenConfig seyrenConfig, String baseUrl); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType);  }