From 4773edcc36b1f53f6497ec65fbf2d57258c0f0fb Mon Sep 17 00:00:00 2001 From: tgoldman Date: Wed, 27 Aug 2014 14:43:37 +0300 Subject: [PATCH 1/4] HHQ-5913 - Adding timeout properties to Java Mail Sender --- .../src/main/resources/conf/server-log4j.xml | 26 ++++++++++++++++--- .../src/main/resources/data/hq-server.conf | 12 +++++++++ .../hyperic/hq/common/shared/HQConstants.java | 4 +++ .../server/session/EmailManagerImpl.java | 15 ++++++++--- .../META-INF/spring/mail-context.xml | 2 ++ 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/dist/bootstrap/src/main/resources/conf/server-log4j.xml b/dist/bootstrap/src/main/resources/conf/server-log4j.xml index 09a8ade944..72a8890bbc 100644 --- a/dist/bootstrap/src/main/resources/conf/server-log4j.xml +++ b/dist/bootstrap/src/main/resources/conf/server-log4j.xml @@ -232,14 +232,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + From be2a4fd44e80af9f861bf72af02e927377aa1960 Mon Sep 17 00:00:00 2001 From: tgoldman Date: Thu, 28 Aug 2014 12:37:52 +0300 Subject: [PATCH 3/4] [HHQ-5913]: Adding timeout properties to mail-config.properties --- hq-server/src/main/resources/mail-config.properties | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hq-server/src/main/resources/mail-config.properties b/hq-server/src/main/resources/mail-config.properties index e59d5c0341..8c3fd76181 100644 --- a/hq-server/src/main/resources/mail-config.properties +++ b/hq-server/src/main/resources/mail-config.properties @@ -32,6 +32,7 @@ mail.password=mypassword #maps to mail.smtp.host, but kept existing prop name from hq-server.conf for upgrade server.mail.host=localhost +#maps to SMTP connection and read timeout, but kept existing prop name from hq-server.conf for upgrade # Change to SMTP port mail.smtp.port=25 @@ -41,4 +42,8 @@ mail.smtp.socketFactory.class=javax.net.SocketFactory mail.smtp.socketFactory.fallback=false mail.smtp.socketFactory.port=25 mail.smtp.starttls.enable=false +# Connection timeout +mail.smtp.connectiontimeout=20000 +# Read timeout +mail.smtp.timeout=20000 mail.debug=false From 03a58853d36dfaadffcf616d1cf5a1e22baae6d0 Mon Sep 17 00:00:00 2001 From: tgoldman Date: Mon, 29 Sep 2014 13:46:48 +0200 Subject: [PATCH 4/4] [HHQ-5913]: Adding debug messages --- .../bizapp/server/session/EmailManagerImpl.java | 17 +++++++++++++---- .../server/session/EscalationRuntimeImpl.java | 7 ++++--- .../events/server/session/AlertDefinition.java | 10 +++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/hq-server/src/main/java/org/hyperic/hq/bizapp/server/session/EmailManagerImpl.java b/hq-server/src/main/java/org/hyperic/hq/bizapp/server/session/EmailManagerImpl.java index 285092ad2f..5371ebbaff 100644 --- a/hq-server/src/main/java/org/hyperic/hq/bizapp/server/session/EmailManagerImpl.java +++ b/hq-server/src/main/java/org/hyperic/hq/bizapp/server/session/EmailManagerImpl.java @@ -80,12 +80,16 @@ public class EmailManagerImpl implements EmailManager { private Session mailSession; private ConcurrentStatsCollector concurrentStatsCollector; + private int mailSmtpConnectiontimeout; + private int mailSmtpTimeout; + private String mailSmtpHost; + final Log log = LogFactory.getLog(EmailManagerImpl.class); public static final String JOB_GROUP = "EmailFilterGroup"; private static final IntHashMap _alertBuffer = new IntHashMap(); public static final Object SCHEDULER_LOCK = new Object(); - + @Autowired public EmailManagerImpl(JavaMailSender mailSender, ServerConfigManager serverConfigManager, PlatformManager platformManager, ResourceManager resourceManager, @@ -96,6 +100,10 @@ public EmailManagerImpl(JavaMailSender mailSender, ServerConfigManager serverCon this.platformManager = platformManager; this.resourceManager = resourceManager; this.concurrentStatsCollector = concurrentStatsCollector; + + mailSmtpConnectiontimeout = Integer.parseInt(mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_CONNECTIONTIMEOUT)); + mailSmtpTimeout = Integer.parseInt(mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_TIMEOUT)); + mailSmtpHost = mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_HOST); } @PostConstruct @@ -106,6 +114,7 @@ public void initStats() { public void sendEmail(EmailRecipient[] addresses, String subject, String[] body, String[] htmlBody, Integer priority) { MimeMessage mimeMessage = mailSender.createMimeMessage(); final StopWatch watch = new StopWatch(); + try { InternetAddress from = getFromAddress(); if (from == null) { @@ -166,9 +175,9 @@ public void sendEmail(EmailRecipient[] addresses, String subject, String[] body, log.debug("Sending email using mailServer=" + mailSession.getProperties() + " took " + watch.getElapsed() + " ms."); } - if (watch.getElapsed() >= Integer.parseInt(mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_CONNECTIONTIMEOUT)) - || (watch.getElapsed() >= Integer.parseInt(mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_TIMEOUT)))) { - log.warn("Sending email using mailServer=" + mailSession.getProperties().getProperty(HQConstants.MAIL_SMTP_HOST) + + if (watch.getElapsed() >= mailSmtpConnectiontimeout + || (watch.getElapsed() >= mailSmtpTimeout)) { + log.warn("Sending email using mailServer=" + mailSmtpHost + " took " + watch.getElapsed() + " ms. Please check with your mail administrator."); } } diff --git a/hq-server/src/main/java/org/hyperic/hq/escalation/server/session/EscalationRuntimeImpl.java b/hq-server/src/main/java/org/hyperic/hq/escalation/server/session/EscalationRuntimeImpl.java index 89b2555c9f..6c57eb0b9a 100644 --- a/hq-server/src/main/java/org/hyperic/hq/escalation/server/session/EscalationRuntimeImpl.java +++ b/hq-server/src/main/java/org/hyperic/hq/escalation/server/session/EscalationRuntimeImpl.java @@ -49,6 +49,7 @@ import org.hyperic.hq.authz.server.session.AuthzSubject; import org.hyperic.hq.authz.server.session.Resource; import org.hyperic.hq.authz.shared.AuthzSubjectManager; +import org.hyperic.hq.events.ActionExecuteException; import org.hyperic.hq.events.ActionExecutionInfo; import org.hyperic.hq.events.AlertDefinitionInterface; import org.hyperic.hq.events.AlertInterface; @@ -604,8 +605,9 @@ public void executeState(Integer stateId) { // HQ-1348: End escalation if alert is already fixed if (esc.getAlertInfo().isFixed()) { + if (debug) + log.debug("alert cannot be escalated, since it is already fixed."); endEscalation(escalationState); - return; } @@ -618,7 +620,7 @@ public void executeState(Integer stateId) { if (debug) { log.debug("Moving onto next state of escalation, but waiting for " - + escalationAction.getWaitTime() + " ms"); + + nextTime + " ms"); } escalationState.setNextAction(actionIdx + 1); @@ -635,7 +637,6 @@ public void executeState(Integer stateId) { ActionExecutionInfo execInfo = new ActionExecutionInfo(esc .getShortReason(), esc.getLongReason(), esc.getAuxLogs()); String detail = action.executeAction(esc.getAlertInfo(), execInfo); - type.changeAlertState(esc, overlord, EscalationStateChange.ESCALATED); type.logActionDetails(esc, action, detail, null); diff --git a/hq-server/src/main/java/org/hyperic/hq/events/server/session/AlertDefinition.java b/hq-server/src/main/java/org/hyperic/hq/events/server/session/AlertDefinition.java index a644e909b0..640fee7a02 100644 --- a/hq-server/src/main/java/org/hyperic/hq/events/server/session/AlertDefinition.java +++ b/hq-server/src/main/java/org/hyperic/hq/events/server/session/AlertDefinition.java @@ -618,7 +618,15 @@ public boolean performsEscalations() { return true; } + @Override public String toString() { - return "alertDef [" + this.getName() + "]"; + return "AlertDefinition [_name=" + _name + ", _ctime=" + _ctime + ", _mtime=" + _mtime + ", _parent=" + _parent + + ", _children=" + _children + ", _description=" + _description + ", _priority=" + _priority + + ", _active=" + _active + ", _enabled=" + _enabled + ", _frequencyType=" + _frequencyType + + ", _count=" + _count + ", _range=" + _range + ", _willRecover=" + _willRecover + ", _notifyFiltered=" + + _notifyFiltered + ", _controlFiltered=" + _controlFiltered + ", _deleted=" + _deleted + + ", _conditions=" + _conditions + ", _triggers=" + _triggers + ", _actions=" + _actions + + ", _escalation=" + _escalation + ", _resource=" + _resource + ", _state=" + _state + ", _value=" + + _value + "]"; } }