public void clearAlert(short alertType, long dataCenterId, Long podId) { if (alertType != -1) { AlertVO alert = _alertDao.getLastAlert(alertType, dataCenterId, podId, null); if (alert != null) { AlertVO updatedAlert = _alertDao.createForUpdate(); updatedAlert.setResolved(new Date()); _alertDao.update(alert.getId(), updatedAlert); } } }
// TODO: make sure this handles SSL transport (useAuth is true) and regular public void sendAlert( short alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException, UnsupportedEncodingException { AlertVO alert = null; if ((alertType != AlertManager.ALERT_TYPE_HOST) && (alertType != AlertManager.ALERT_TYPE_USERVM) && (alertType != AlertManager.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.ALERT_TYPE_CONSOLE_PROXY) && (alertType != AlertManager.ALERT_TYPE_STORAGE_MISC) && (alertType != AlertManager.ALERT_TYPE_MANAGMENT_NODE)) { alert = _alertDao.getLastAlert(alertType, dataCenterId, podId, clusterId); } if (alert == null) { // set up a new alert AlertVO newAlert = new AlertVO(); newAlert.setType(alertType); newAlert.setSubject(subject); newAlert.setClusterId(clusterId); newAlert.setPodId(podId); newAlert.setDataCenterId(dataCenterId); newAlert.setSentCount(1); // initialize sent count to 1 since we are now sending an alert newAlert.setLastSent(new Date()); _alertDao.persist(newAlert); } else { if (s_logger.isDebugEnabled()) { s_logger.debug( "Have already sent: " + alert.getSentCount() + " emails for alert type '" + alertType + "' -- skipping send email"); } return; } if (_smtpSession != null) { SMTPMessage msg = new SMTPMessage(_smtpSession); msg.setSender(new InternetAddress(_emailSender, _emailSender)); msg.setFrom(new InternetAddress(_emailSender, _emailSender)); for (InternetAddress address : _recipientList) { msg.addRecipient(RecipientType.TO, address); } msg.setSubject(subject); msg.setSentDate(new Date()); msg.setContent(content, "text/plain"); msg.saveChanges(); SMTPTransport smtpTrans = null; if (_smtpUseAuth) { smtpTrans = new SMTPSSLTransport( _smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword)); } else { smtpTrans = new SMTPTransport( _smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword)); } smtpTrans.connect(); smtpTrans.sendMessage(msg, msg.getAllRecipients()); smtpTrans.close(); } }