@Test public void testSendMessageToSlackChannel() throws SQLException { mockDB(SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL, "https: List <HealthCheckVO> hcs = new ArrayList<HealthCheckVO>(); HealthCheckVO hc = getHealthCheckVO(); hcs.add(hc); hc.setFailureStatusMessage("Failed message"); MailSenderUtil.sendMailForHealthCheckVos(hcs); dbMock.tearDown(); }
public static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject) { ObjectMapper mapper = new ObjectMapper(); String postSlackMessageURL; String slackMessage = subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')); try { postSlackMessageURL = propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_URL) + SurveillerConstants.POST_SLACK_MESSAGE + "?token=" + propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_TOKEN) + "&channel=" + URLEncoder.encode(slackChannelName, ENCODE_UTF_8) + "&text=" + URLEncoder.encode(slackMessage, ENCODE_UTF_8) + "&username=" + URLEncoder.encode("CCP Service Health Dashboard" , ENCODE_UTF_8) + "&icon_emoji=" + URLEncoder.encode(":satellite_antenna:", ENCODE_UTF_8); String postSlackMessageJson = RestCommunicationHandler.postRequest(postSlackMessageURL, false, null, null); JsonNode rootMsgNode = mapper.readTree(postSlackMessageJson); JsonNode okNode = rootMsgNode.get("ok"); if (okNode.asBoolean()) { logger.debug("Message pushed to slack channnel: " + slackChannelName); } else { logger.info("Message pushed to slack channnel Failed: " + slackChannelName); } } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } catch (IOException e) { logger.error("IOException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } }
MailSenderUtil { public static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject) { ObjectMapper mapper = new ObjectMapper(); String postSlackMessageURL; String slackMessage = subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')); try { postSlackMessageURL = propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_URL) + SurveillerConstants.POST_SLACK_MESSAGE + "?token=" + propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_TOKEN) + "&channel=" + URLEncoder.encode(slackChannelName, ENCODE_UTF_8) + "&text=" + URLEncoder.encode(slackMessage, ENCODE_UTF_8) + "&username=" + URLEncoder.encode("CCP Service Health Dashboard" , ENCODE_UTF_8) + "&icon_emoji=" + URLEncoder.encode(":satellite_antenna:", ENCODE_UTF_8); String postSlackMessageJson = RestCommunicationHandler.postRequest(postSlackMessageURL, false, null, null); JsonNode rootMsgNode = mapper.readTree(postSlackMessageJson); JsonNode okNode = rootMsgNode.get("ok"); if (okNode.asBoolean()) { logger.debug("Message pushed to slack channnel: " + slackChannelName); } else { logger.info("Message pushed to slack channnel Failed: " + slackChannelName); } } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } catch (IOException e) { logger.error("IOException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } } }
MailSenderUtil { public static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject) { ObjectMapper mapper = new ObjectMapper(); String postSlackMessageURL; String slackMessage = subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')); try { postSlackMessageURL = propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_URL) + SurveillerConstants.POST_SLACK_MESSAGE + "?token=" + propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_TOKEN) + "&channel=" + URLEncoder.encode(slackChannelName, ENCODE_UTF_8) + "&text=" + URLEncoder.encode(slackMessage, ENCODE_UTF_8) + "&username=" + URLEncoder.encode("CCP Service Health Dashboard" , ENCODE_UTF_8) + "&icon_emoji=" + URLEncoder.encode(":satellite_antenna:", ENCODE_UTF_8); String postSlackMessageJson = RestCommunicationHandler.postRequest(postSlackMessageURL, false, null, null); JsonNode rootMsgNode = mapper.readTree(postSlackMessageJson); JsonNode okNode = rootMsgNode.get("ok"); if (okNode.asBoolean()) { logger.debug("Message pushed to slack channnel: " + slackChannelName); } else { logger.info("Message pushed to slack channnel Failed: " + slackChannelName); } } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } catch (IOException e) { logger.error("IOException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } } private  MailSenderUtil(); }
MailSenderUtil { public static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject) { ObjectMapper mapper = new ObjectMapper(); String postSlackMessageURL; String slackMessage = subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')); try { postSlackMessageURL = propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_URL) + SurveillerConstants.POST_SLACK_MESSAGE + "?token=" + propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_TOKEN) + "&channel=" + URLEncoder.encode(slackChannelName, ENCODE_UTF_8) + "&text=" + URLEncoder.encode(slackMessage, ENCODE_UTF_8) + "&username=" + URLEncoder.encode("CCP Service Health Dashboard" , ENCODE_UTF_8) + "&icon_emoji=" + URLEncoder.encode(":satellite_antenna:", ENCODE_UTF_8); String postSlackMessageJson = RestCommunicationHandler.postRequest(postSlackMessageURL, false, null, null); JsonNode rootMsgNode = mapper.readTree(postSlackMessageJson); JsonNode okNode = rootMsgNode.get("ok"); if (okNode.asBoolean()) { logger.debug("Message pushed to slack channnel: " + slackChannelName); } else { logger.info("Message pushed to slack channnel Failed: " + slackChannelName); } } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } catch (IOException e) { logger.error("IOException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject); }
MailSenderUtil { public static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject) { ObjectMapper mapper = new ObjectMapper(); String postSlackMessageURL; String slackMessage = subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')); try { postSlackMessageURL = propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_URL) + SurveillerConstants.POST_SLACK_MESSAGE + "?token=" + propertyUtil.getValue(SurveillerConstants.CONFIG_SLACK_TOKEN) + "&channel=" + URLEncoder.encode(slackChannelName, ENCODE_UTF_8) + "&text=" + URLEncoder.encode(slackMessage, ENCODE_UTF_8) + "&username=" + URLEncoder.encode("CCP Service Health Dashboard" , ENCODE_UTF_8) + "&icon_emoji=" + URLEncoder.encode(":satellite_antenna:", ENCODE_UTF_8); String postSlackMessageJson = RestCommunicationHandler.postRequest(postSlackMessageURL, false, null, null); JsonNode rootMsgNode = mapper.readTree(postSlackMessageJson); JsonNode okNode = rootMsgNode.get("ok"); if (okNode.asBoolean()) { logger.debug("Message pushed to slack channnel: " + slackChannelName); } else { logger.info("Message pushed to slack channnel Failed: " + slackChannelName); } } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } catch (IOException e) { logger.error("IOException in Senting Slack Messageto Channel URL = " + slackChannelName, e); } } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject);  }