EMailAgent.java

File uploaded by adamjava1 on Jan 12, 2011
Version 1Show Document
  • View in full screen mode

EXPERIMENTAL SAMPLE

This is not supported code and meant only to demonstrate the concept of using MAIL NOTIFICATIONS to trigger some action.

 

There is no warranty expressed or implied, use at your own risk.

 

 

WHY USE THIS APPROACH?

> avoid consuming excessive API Counts just to get the status of completed tasks/events

> may offer better response times than polling (but not guaranteed)

 

 

PRE-REQUISITES

> email server that supports imap via SSL

    (should work with pop and polling but not extensively tested)

> email address registered with an API user account, which is set to get ALL notifications

    this is configurable by editing the user account from within QualysGuard

 

> Java JDK to compile

> Java Runtime to run

> mail.jar (java mail support lib)

    http://www.oracle.com/technetwork/java/index-jsp-139225.html

 

 

WHY JAVA?

> I an working on a C# version and a Python version - if you are interested, please send me a private message

> The perl version works on linux, but not on windows due to some library rerference issues

 

 

IMPLEMENTATION DETAILS OF INTEREST:

> single thread attempts to use the IMAP Idle feature

    falls back to polling if not supported (this has not been extensively tested)

> configurable, bounded pool of worker threads with 1 overflow worker thread

> monitors the external process

> uses Regular Expressions to match Email subject lines to a trigger

 

 

RUNNING FROM COMMAND LINE / SHELL:

> create a csv file with the following format:

    <regular expression>,<shell command to run>

    ex:

 

    QualysGuard Report  Summary for.*\(Technical Report\), C:\Perl\bin\perl.exe C:\vboxshare\ping.pl

 

    where: <shell command to run> uses FULLY QUALIFIED PATHS

 

> compile:

 

    javac EMailAgent.java

 

> launch:

 

    java EMailAgent <host> <user> <password> <mbox> <freq> <trigger pattern csv file name> [int: max worker threads]

 

    where: [int: max worker threads] is optional and all preceding inputs are required

 

    ex:

 

    java EMailAgent my.mailserver.com:1234 myId myPw inbox 30 ~/mytriggers.csv

 

    java EMailAgent my.mailserver.com:1234 myId myPw inbox 30 ~/mytriggers.csv 20

 

 

 

JAVA PROJECT:

> import/copy single file to your project

> create an instance of the EMailAgent and pass the required params in the constructor

    see the main method for guidance

> you can use a CSV file if you want to use the default regex -> shell command mapping

> add Triggers by implementing the Trigger interface and mapping them with Regular Expressions

 

 

HELP:

This is not a supported product and was produced in the author's spare time

If you have any questions, feel free to contact me via private message and I will try my best to answer any questions

If you have any improvements, suggestions or alternatives please post them!

Attachments

Outcomes