@Test public void testSendSlackAlertByWebHook() throws SQLException { mockDB(SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK, "https: List <HealthCheckVO> hcs = new ArrayList<HealthCheckVO>(); HealthCheckVO hc = getHealthCheckVO(); hcs.add(hc); hc.setFailureStatusMessage("Failed message"); MailSenderUtil.sendMailForHealthCheckVos(hcs); dbMock.tearDown(); }
private static void sendSlackAlertByWebHook(HealthCheckVO hVo, String slackURL, String subject) throws IOException { String slackMessage = "{\"username\": \"CCP Service Health Dashboard\", \"text\": \"" + subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')) + "\n\", \"icon_emoji\": \":satellite_antenna:\"}"; logger.debug("Slack Message : " + slackMessage); URL myurl = new URL(slackURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(slackMessage.length())); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(slackMessage); output.flush(); output.close(); logger.debug("Message pushed to slack channnel : " + slackURL); logger.debug("Resp Code:" + con.getResponseCode()); logger.debug("Resp Message:" + con.getResponseMessage()); }
MailSenderUtil { private static void sendSlackAlertByWebHook(HealthCheckVO hVo, String slackURL, String subject) throws IOException { String slackMessage = "{\"username\": \"CCP Service Health Dashboard\", \"text\": \"" + subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')) + "\n\", \"icon_emoji\": \":satellite_antenna:\"}"; logger.debug("Slack Message : " + slackMessage); URL myurl = new URL(slackURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(slackMessage.length())); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(slackMessage); output.flush(); output.close(); logger.debug("Message pushed to slack channnel : " + slackURL); logger.debug("Resp Code:" + con.getResponseCode()); logger.debug("Resp Message:" + con.getResponseMessage()); } }
MailSenderUtil { private static void sendSlackAlertByWebHook(HealthCheckVO hVo, String slackURL, String subject) throws IOException { String slackMessage = "{\"username\": \"CCP Service Health Dashboard\", \"text\": \"" + subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')) + "\n\", \"icon_emoji\": \":satellite_antenna:\"}"; logger.debug("Slack Message : " + slackMessage); URL myurl = new URL(slackURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(slackMessage.length())); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(slackMessage); output.flush(); output.close(); logger.debug("Message pushed to slack channnel : " + slackURL); logger.debug("Resp Code:" + con.getResponseCode()); logger.debug("Resp Message:" + con.getResponseMessage()); } private  MailSenderUtil(); }
MailSenderUtil { private static void sendSlackAlertByWebHook(HealthCheckVO hVo, String slackURL, String subject) throws IOException { String slackMessage = "{\"username\": \"CCP Service Health Dashboard\", \"text\": \"" + subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')) + "\n\", \"icon_emoji\": \":satellite_antenna:\"}"; logger.debug("Slack Message : " + slackMessage); URL myurl = new URL(slackURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(slackMessage.length())); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(slackMessage); output.flush(); output.close(); logger.debug("Message pushed to slack channnel : " + slackURL); logger.debug("Resp Code:" + con.getResponseCode()); logger.debug("Resp Message:" + con.getResponseMessage()); } 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 { private static void sendSlackAlertByWebHook(HealthCheckVO hVo, String slackURL, String subject) throws IOException { String slackMessage = "{\"username\": \"CCP Service Health Dashboard\", \"text\": \"" + subject + ".\n" + "Current Status : " + hVo.getStatus().getStatus().getStatusDesc() + "\nMessage : " + (hVo.getFailureStatusMessage() == null ? "" : hVo.getFailureStatusMessage().replace('\"', '\'')) + "\n\", \"icon_emoji\": \":satellite_antenna:\"}"; logger.debug("Slack Message : " + slackMessage); URL myurl = new URL(slackURL); HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-length", String.valueOf(slackMessage.length())); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); con.setDoInput(true); DataOutputStream output = new DataOutputStream(con.getOutputStream()); output.writeBytes(slackMessage); output.flush(); output.close(); logger.debug("Message pushed to slack channnel : " + slackURL); logger.debug("Resp Code:" + con.getResponseCode()); logger.debug("Resp Message:" + con.getResponseMessage()); } 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);  }