protected void processGetRequest(HttpServletRequest request, HttpServletResponse response) { if ((request == null) || (response == null)) { return; } response.setContentType("text/html"); PrintWriter out = null; String name = request.getParameter("Name"); boolean excludeNavbar = StringUtilities.isStringValueBooleanTrue(request.getParameter("ExcludeNavbar")); String notificationGroup_AlertAssociations = getNotificationGroup_AlertAssociations(name, excludeNavbar); try { StringBuilder htmlBuilder = new StringBuilder(); StatsAggHtmlFramework statsAggHtmlFramework = new StatsAggHtmlFramework(); String htmlHeader = statsAggHtmlFramework.createHtmlHeader("StatsAgg - " + PAGE_NAME, ""); String htmlBody = statsAggHtmlFramework.createHtmlBody( "<div id=\"page-content-wrapper\">\n" + "<!-- Keep all page content within the page-content inset div! -->\n" + " <div class=\"page-content inset statsagg_page_content_font\">\n" + " <div class=\"content-header\"> \n" + " <div class=\"pull-left content-header-h2-min-width-statsagg\"> <h2> " + PAGE_NAME + " </h2> </div>\n" + " </div> " + " <div class=\"statsagg_force_word_wrap\">" + notificationGroup_AlertAssociations + " </div>\n" + " </div>\n" + "</div>\n", excludeNavbar); htmlBuilder .append("<!DOCTYPE html>\n<html>\n") .append(htmlHeader) .append(htmlBody) .append("</html>"); Document htmlDocument = Jsoup.parse(htmlBuilder.toString()); String htmlFormatted = htmlDocument.toString(); out = response.getWriter(); out.println(htmlFormatted); } catch (Exception e) { logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e)); } finally { if (out != null) { out.close(); } } }
public void testNotificationGroup(String notificationGroupName) { if (notificationGroupName == null) { logger.info("Failed to send email alert to notification group. Name cannot be null"); return; } NotificationGroupsDao notificationGroupsDao = new NotificationGroupsDao(); NotificationGroup notificationGroup = notificationGroupsDao.getNotificationGroupByName(notificationGroupName); if ((notificationGroup == null) || (notificationGroup.getName() == null) || (notificationGroup.getId() == null)) { String cleanNotificationGroupName = StringUtilities.removeNewlinesFromString(notificationGroupName, ' '); logger.warn( "Failed to send email alert to notification group '" + cleanNotificationGroupName + "'. Notification group does not exist."); return; } String testAlertName = "Notification test - alert"; Alert testAlert = new Alert( 99999, testAlertName, testAlertName.toUpperCase(), "This is a fake alert to test sending email alerts to the notification group named '" + notificationGroup.getName() + "'", 88888, true, true, true, Alert.TYPE_THRESHOLD, false, false, 60l, DatabaseObjectCommon.TIME_UNIT_MINUTES, 77777, 77777, Alert.OPERATOR_GREATER, Alert.COMBINATION_ALL, null, new BigDecimal("100"), 9900L, DatabaseObjectCommon.TIME_UNIT_SECONDS, null, DatabaseObjectCommon.TIME_UNIT_SECONDS, 1, true, new Timestamp(System.currentTimeMillis()), false, null, null, 77777, 77777, Alert.OPERATOR_GREATER, Alert.COMBINATION_ALL, null, new BigDecimal("200"), 91000L, DatabaseObjectCommon.TIME_UNIT_SECONDS, null, DatabaseObjectCommon.TIME_UNIT_SECONDS, 2, true, new Timestamp(System.currentTimeMillis()), false, null, null); String testMetricGroupName = "Notification test - metric group"; MetricGroup metricGroup = new MetricGroup( 88888, testMetricGroupName, testMetricGroupName.toUpperCase(), "This is a fake metric group to test sending email alerts to the notification group named '" + notificationGroup.getName() + "'"); List<String> metricKeys = new ArrayList<>(); metricKeys.add("emailtest.metric2"); metricKeys.add("emailtest.metric1"); metricKeys.add("emailtest.metric3"); metricKeys.add("emailtest.metric4"); metricKeys.add("emailtest.metric5"); Map<String, BigDecimal> alertMetricValues = new HashMap<>(); alertMetricValues.put("emailtest.metric1-99999", new BigDecimal(101)); alertMetricValues.put("emailtest.metric2-99999", new BigDecimal(102)); alertMetricValues.put("emailtest.metric3-99999", new BigDecimal(103)); alertMetricValues.put("emailtest.metric4-99999", new BigDecimal(104)); EmailThread emailThread = new EmailThread( testAlert, EmailThread.WARNING_LEVEL_CAUTION, metricKeys, alertMetricValues, new ConcurrentHashMap<String, String>(), false, false, ApplicationConfiguration.getAlertStatsAggLocation()); emailThread.buildAlertEmail(3, metricGroup); List<String> emailsAddresses = EmailThread.getToEmailsAddressesForAlert(notificationGroup.getId()); emailThread.sendEmail(emailsAddresses, emailThread.getSubject(), emailThread.getBody()); String cleanNotificationGroupName = StringUtilities.removeNewlinesFromString(notificationGroup.getName(), ' '); logger.info("Sent test email alert to notification group '" + cleanNotificationGroupName + "'"); }