@Test public void checkingOutTheHappyPath() throws Exception { Check check = new Check() .withId("test-check-id") .withEnabled(true) .withName("test-check") .withState(AlertType.ERROR); Subscription subscription = new Subscription() .withEnabled(true) .withType(SubscriptionType.VICTOROPS) .withTarget("routingurl"); Alert alert = new Alert() .withFromType(AlertType.OK) .withToType(AlertType.ERROR); List<Alert> alerts = Arrays.asList(alert); BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture(); clientDriver.addExpectation( onRequestTo("/restapi/routingurl") .withMethod(Method.POST) .capturingBodyIn(bodyCapture), giveResponse("success", "text/plain")); service.sendNotification(check, subscription, alerts); JsonNode node = bodyCapture.getContent(); assertThat(node, hasJsonPath("$.entity_id", is(check.getId()))); assertThat(node, hasJsonPath("$.message_type", is(VictorOpsNotificationService.MessageType.CRITICAL.name()))); }
@Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint(); String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default"); if (victorOpsRestEndpoint == null) { LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications"); return; } URI victorOpsUri = null; try { victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey)); } catch (URISyntaxException use) { LOGGER.warn("Invalid endpoint is given."); return; } HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(victorOpsUri); try { HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); if(responseEntity!=null) { LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity)); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to VictorOps", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } }
VictorOpsNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint(); String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default"); if (victorOpsRestEndpoint == null) { LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications"); return; } URI victorOpsUri = null; try { victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey)); } catch (URISyntaxException use) { LOGGER.warn("Invalid endpoint is given."); return; } HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(victorOpsUri); try { HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); if(responseEntity!=null) { LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity)); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to VictorOps", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } }
VictorOpsNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint(); String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default"); if (victorOpsRestEndpoint == null) { LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications"); return; } URI victorOpsUri = null; try { victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey)); } catch (URISyntaxException use) { LOGGER.warn("Invalid endpoint is given."); return; } HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(victorOpsUri); try { HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); if(responseEntity!=null) { LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity)); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to VictorOps", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  VictorOpsNotificationService(SeyrenConfig seyrenConfig); }
VictorOpsNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint(); String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default"); if (victorOpsRestEndpoint == null) { LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications"); return; } URI victorOpsUri = null; try { victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey)); } catch (URISyntaxException use) { LOGGER.warn("Invalid endpoint is given."); return; } HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(victorOpsUri); try { HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); if(responseEntity!=null) { LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity)); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to VictorOps", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  VictorOpsNotificationService(SeyrenConfig seyrenConfig); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType); }
VictorOpsNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint(); String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default"); if (victorOpsRestEndpoint == null) { LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications"); return; } URI victorOpsUri = null; try { victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey)); } catch (URISyntaxException use) { LOGGER.warn("Invalid endpoint is given."); return; } HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(victorOpsUri); try { HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity responseEntity = response.getEntity(); if(responseEntity!=null) { LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity)); } } catch (Exception e) { throw new NotificationFailedException("Failed to send notification to VictorOps", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  VictorOpsNotificationService(SeyrenConfig seyrenConfig); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType);  }