com.ebay.carad.os.vitalsigns.listeners
Class EmailAlertListener

java.lang.Object
  extended by com.ebay.carad.os.vitalsigns.listeners.AbstractReportingListener
      extended by com.ebay.carad.os.vitalsigns.listeners.EmailAlertListener
All Implemented Interfaces:
IReportingListener

public class EmailAlertListener
extends AbstractReportingListener

Report listener that can send email alerts for ReportingExceptions and for data that is recorded that is out of the expected range.

Version:
$Id$
Author:
Jeremy Thomerson

Field Summary
private  float lastObservedValue
           
private  float mDataLevel
           
private  java.lang.String mErrorType
           
private  java.text.Format mExceptionMessageFormat
           
private  java.lang.String mFromAddress
           
private  java.text.Format mLevelMessageFormat
           
private  java.lang.String mMailServer
           
private  java.lang.String mMessageSubject
           
private  java.lang.String[] mToAddresses
           
private  boolean rememberValues
           
 
Constructor Summary
EmailAlertListener()
           
 
Method Summary
 void alert(java.lang.String msg)
           
private  java.lang.String getExceptionString(ReportingException exception)
           
private  java.lang.String getLocalMachineName()
           
private  boolean isAlertNeeded(IDashboardReport report)
           
 void reportingException(ReportingException exception, IReportingListenerContainer agent, IDashboardReport report)
          Receives parameters:
 void reportRan(IDashboardAgent agent, IDashboardReport report)
          Receives parameters:
 void setErrorType(java.lang.String errorType)
           
 void setFromAddress(java.lang.String address)
          Sets the address that mail alerts will appear to come from.
 void setMailServer(java.lang.String server)
          Sets the address of the SMTP relay to use.
 void setRememberValues(boolean rememberValues)
          If true, the listener will only send an email if the currently observed value is outside the threshold, AND is "worse" than the last observed value.
 void setSubject(java.lang.String inSubject)
          Sets the subject line for alerts sent by this handler.
 void setThreshold(float dataLevel)
           
 void setToAddresses(java.lang.String[] inToAddresses)
          Sets the addresses that mail alerts will be sent to.
 
Methods inherited from class com.ebay.carad.os.vitalsigns.listeners.AbstractReportingListener
reportingComplete, reportingPreStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mDataLevel

private float mDataLevel

mErrorType

private java.lang.String mErrorType

mExceptionMessageFormat

private java.text.Format mExceptionMessageFormat

mLevelMessageFormat

private java.text.Format mLevelMessageFormat

mMailServer

private java.lang.String mMailServer

mToAddresses

private java.lang.String[] mToAddresses

mFromAddress

private java.lang.String mFromAddress

mMessageSubject

private java.lang.String mMessageSubject

rememberValues

private boolean rememberValues

lastObservedValue

private float lastObservedValue
Constructor Detail

EmailAlertListener

public EmailAlertListener()
Method Detail

setRememberValues

public void setRememberValues(boolean rememberValues)
If true, the listener will only send an email if the currently observed value is outside the threshold, AND is "worse" than the last observed value. This is usually desired in situations where observed values are long-lived. For example, if your report observes number of order exceptions in last 24 hours, but you want an email to be sent when any errors are detected, you probably do not want to receive an email every time the report is run for 24 hours after the first error is detected. Instead, you want to get an alert if any more errors are received than the last time you looked. If enabled, the listener will compare the currently observed value to the last observed value, and send an email only if the current value is outside of the threshold and worse than the last one. This option is OFF by default.

Parameters:
rememberValues - if true, emails will only be sent when values got "worse" than last observation

setMailServer

public void setMailServer(java.lang.String server)
Sets the address of the SMTP relay to use.

Parameters:
server - IP address or hostname of SMTP relay

setFromAddress

public void setFromAddress(java.lang.String address)
Sets the address that mail alerts will appear to come from.

Parameters:
address - the address to send from

setToAddresses

public void setToAddresses(java.lang.String[] inToAddresses)
Sets the addresses that mail alerts will be sent to.

Parameters:
inToAddresses - the "to" e-mail addresses

setSubject

public void setSubject(java.lang.String inSubject)
Sets the subject line for alerts sent by this handler.

Parameters:
inSubject - subject line for alerts

alert

public void alert(java.lang.String msg)

reportingException

public void reportingException(ReportingException exception,
                               IReportingListenerContainer agent,
                               IDashboardReport report)
Receives parameters:
 
 {
  0 : report.getPreviousData(), 
  1 : report.getThisRunData(), 
  2 : report.getTitle(),
  3 : report.getID(),
  4 : exception.getMessage(),
  5 : full exception details, including stack trace, as string
  6 : new Date().toString()
 }
 

Specified by:
reportingException in interface IReportingListener
Overrides:
reportingException in class AbstractReportingListener

reportRan

public void reportRan(IDashboardAgent agent,
                      IDashboardReport report)
Receives parameters:
 
 {
  0 : report.getPreviousData(), 
  1 : report.getThisRunData(), 
  2 : this.errorType (i.e. WARNING / ERROR),
  3 : report.getTitle(),
  4 : report.getID(),
  5 : this.dataLevel
  6 : new Date().toString()
 }
 

Specified by:
reportRan in interface IReportingListener
Overrides:
reportRan in class AbstractReportingListener

getLocalMachineName

private java.lang.String getLocalMachineName()

isAlertNeeded

private boolean isAlertNeeded(IDashboardReport report)

getExceptionString

private java.lang.String getExceptionString(ReportingException exception)

setErrorType

public void setErrorType(java.lang.String errorType)

setThreshold

public void setThreshold(float dataLevel)


Copyright © 2004-2009. All Rights Reserved.