Monday, February 14, 2011

How to create E-mail notification in Weblogic using WebLogic Diagnostics Framework (WLDF)

Dear All,


Today we will discuss about Weblogic diagnostics and framework. and how to configure mail notification on Weblogic.
Actually i came across one of the requirement where we configure e-mail notifications for different-different purposes, now will discuss about Heap_size notifications.

WebLogic Diagnostics Framework (WLDF) – Watch & Notification

One of the features of WLDF is Watch and Notification. You can configure server(s) with watch condition and respective notification(s) to be sent if the watch conditions are met. For example, if the number of request waiting on a JDBC Data Source to grab a connection exceeds 10 and if the free heap in the server is less than 5% then you can trigger a notification.

The notification can be one or more of the following types:

* JMX Notification - Application(s) can register notification listener with WLDF to receive notifications.
* JMS Notification - WLDF can post a message to JMS destination to alert the situation which can be consumed by a message listener or MDBs to further processing.
* SNMP Notification - SNMP traps can be sent to alert SNMP managers.
* SMTP Notification - Email notifications through a Java Mail session.
* Image Notification - Generates a server image which contains information from different subsystem during the watch.

Creating JavaMail Session

First step is to make sure that the underlying resources for the notification are setup. In this case we are going to use SMTP notification so let us first create the Java Mail Session to connect to Mail Server.

1. Click "Lock & Edit" to acquire a configuration lock

2. Expand Services > Mail Sessions and click "New" to create a new Java Mail Session.

3. Provide Name, JNDI Name and JavaMail Properties as follow:

4. Name - WL-MailSession

5. JNDI Name - com.test.MailSession

6. JavaMail Properties:

mail.transport.protocol=smtp
mail.host=hostname_smtp
mail.user=admin
mail.password=password
mail.port=(port_number)
mail.from=admin@domain.com

(Note : The port number of the mail server for the specified protocol. If not specified the protocol's default port number is used.
mail.protocol.port=port_number)


So We can use following mail property



7. Click next to target the mail session to a server (Eg. AdminServer or mange_server1) and click finish.

8. Activate the changes by clicking "Activate Changes".



Creating WLDF Module

Next step in configuring watch and notification is to create a diagnostic module and target it to the server. You can use console or WLST to create a diagnostic module. The following steps illustrate the steps to create a WLDF system module:

1. Click "Lock & Edit" to acquire a configuration lock

2. Click Diagnostics > Diagnostics Modules and click "New" to create a new diagnostics module. Provide a name and description.

3. Name - Mail_WLDF_Module

4. Description - This is a WLDF module for testing email notifications

5. Select the newly created module and select targets tab. Select the appropriate server for target as before

6. Click "Save" and "Activate"


Creating Watch & Notification

Each WebLogic Server instance can be configured with only one diagnostic module but you can target the same diagnostic module to multiple servers or clusters. Once the WLDF system module is created and targeted to the appropriate server then watches and notifications can be configured. The following steps illustrate how to create a Watch and a Notification.

To create a watch:

1. Click "Lock & Edit" to acquire a configuration lock

2. Navigate to the diagnostic module created above (Mail_WLDF_Module) and select the "Watches and Notifications" tab and "Watches" sub-tab (if not already selected)

3. Click "New" to create a new Watch. Provide the name and select the type as "Collected Metrics" [Select "Collected Metrics" for inspecting Runtime MBean values, "Server Log" to watch log data and "Event Data" to watch instrumented data]

4. Name - Heap_Notification

5. Watch Type - Collected Metrics

6. Enable Watch - Selected

7. Click "Next"

8. Click "Add Expressions"

9. Ensure that "ServerRuntime" is selected and click "Next"

10. If you are running WebLogic Server on Java HotSpot VM, make sure
"Select an MBean Type from the following list" is selected and select "weblogic.management.runtime.JVMRuntimeMBean" and click "Next".

If you are using JRockit VM, make sure "Select an MBean Type from the following list" is selected and select "weblogic.management.runtime. JRockitRuntimeMBean" and click "Next".

11. Select the instance for the appropriate server from the list for "Instance" and click "Next"

12. For "Message Attribute" select "HeapFreePercent", "<" for "Operator" and type "85" for "Value". Click "Finish" twice to create a Watch 13. Activate the changes The above watch will trigger the configured notification if the percentage of free heap is less than 90. You could make complex rule expression by combining multiple attributes from different MBean. For now we haven't configured any notification for this watch. We will create the notification and will associate it to the watch in the following steps. To create a notification:

1. Click "Lock & Edit" to acquire a configuration lock

2. Navigate to the diagnostic module created above and select the "Watches and Notifications" tab and "Notification" sub-tab

3. Click "New" to create a new Notification

4. Select "SMTP (E-Mail) for Type and click "Next"

5. Provide a name - Email_Notification. Make sure the notification is enabled and click "Next".

6. Configure the following properties for the "Config Notification - SMTP Properties" page

7. Mail Session Name - MailSession01

8. E-Mail Recipients - admin@localhost

9. Click "Finish".

10. Activate the changes



To associate the watch and the notification:

1. Click "Lock & Edit" to acquire a configuration lock

2. Navigate to the diagnostic module created above (Mail_WLDF_Module) and select the "Watches and Notifications" tab and "Watches" sub-tab (if not already selected)

3. Select the watch you created earlier - Heap_Notification

4. Select the "Notifications" tab and move the "Email_Notification" from Available to Chosen

5. Click "Save"

6. Select the "Alarms" tab and select "Use an automatic reset alarm". Set the "Automatic reset period" to 6 and click "Save". This will ensure that the notifications are at least 90 seconds apart.

7. Click "Activate Changes"


As we configured the watch type to be Collected Metrics, the attributes involved in the watch rule will be harvested and tested for watch rule expression(s). The default sampling period for the harvester is 300,000 milliseconds (or 5 minutes). So the time between samples will be 5 minutes. To change the sampling period for metrics collection:

1. Click "Lock & Edit" to acquire a configuration lock

2. Navigate to the diagnostic module created above (Mail_WLDF_Module) and select the "Collected Metrics" tab

3. Ensure that "Enabled' check-box is selected

4. Change the "Sampling Period" as "120000" so that it will collect samples once every two minute


I hope it will help you in creating notifications.


[NOTE : change settings/names and properties as per your requirements. It could have some mismatch in above blogs]


Enjoy working in Middleware...... Cheerzzzz

Regards,
Ajinkya

19 comments:

  1. @pavankumar thanks for ur commments...
    clone option is just for cloning mail session.

    if you create one mail session and u need another one you can clone the same with same mail properties but different JNDI name.

    I hope it resolves your queries.

    ReplyDelete
  2. @pavankumar i hope u clear you doubt...

    ReplyDelete
  3. Thank you so much ajinkya it help me alot!!!!!!!
    kindly answer my future queries ........

    Regards,
    Apurva

    ReplyDelete
  4. @apurva thanks for following my blog...

    N will always be there to help you all....

    Enjoyy working in middleware..

    ReplyDelete
  5. Hello and thank you for this information. I have set up notification for stuck thread messages. Is there a way I can test to make sure it works? And can the JNDI Name for the Mail Session be anything of my choosing or does it need to be something specific?

    ReplyDelete
    Replies
    1. Just came across this question, if you want to test the notification you can create an application that creates a stuck thread and then just hist the jsp page. the notification triggers.I have tested in my test env.let me know if you need details.

      Delete
    2. Hi.

      I will appriciate if you share details for our others friends who wants to work on the same,,

      Regards,
      Ajinkya

      Delete
  6. Thank you for review of my blog...

    and about your queries you have asked :

    1) We can test it only at the real time... I didn't find any other alternate way to test the Mail session notifications..

    Mail session JNDI name could be any thing but if you are using it in any of the application then that should be identical and unique..

    I hope it helps, if you find any more information kindly update us as well...

    ReplyDelete
  7. Ajinkya, thank you for your prompt response. I created a new watch for HeapFreePercent < 50 just to test the email notification. Success! Maybe Oracle will add a Test in future release. Thanks again.

    ReplyDelete
  8. Hi Ajinkya,

    I want to configure WLDF to capture string like "out of memory" in the logs and send notification.

    Please let me know which mbean type and collected metrics should I use and other details.

    Thanks
    Aj

    ReplyDelete
    Replies
    1. Hi AJ,

      i have not came across requirement which demands mail notification on "OutOfMemory" error.

      But will check the same and revert.

      If you get some solution for the same kindly let me know.

      Regards,
      Ajinkya Vichare

      ajinkya-vichare.blogspot.com

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
  9. Hi,
    which addres we mentionmd in mail host, and port number in creation of mail session?
    Is it our system ip addres or any address

    ReplyDelete
    Replies
    1. Hi..

      following are the details of SMTP properties for mail notification :

      mail.transport.protocol=smtp -- Protocol for Mail
      mail.host=hostname_smtp -- Hostname or IP Address of SMTP Server
      mail.user=admin -- Mail Address of SMTP user
      mail.password=password -- Mail Address password
      mail.port=(port_number) -- Port number SMTP Server
      mail.from=admin@domain.com -- Mail address from which you are going to send mails to mentioned users.

      I hope it solves your queries.

      Regards,
      Ajinkya Vichare

      ajinkya-vichare.blogspot.com

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Hi,
    I have configured email properties like below

    mail.debug=true
    mail.smtp.host=smtp.gmail.com
    mail.smtp.socketFactory.port=465
    mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
    mail.smtp.auth=true
    mail.smtp.port=465
    mail.smtp.user=my@gmail.com
    mail.smtp.password=xxxxx
    mail.smtp.from=my@gmail.com

    and I am getting the following error, Could you please if possible.

    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true

    ReplyDelete
  12. com.bea.diagnostics.notifications.NotificationPropagationException: javax.mail.AuthenticationFailedException
    at com.bea.diagnostics.notifications.SMTPNotificationService.send(SMTPNotificationService.java:253)
    at weblogic.diagnostics.watch.SMTPNotificationListener.processWatchNotification(SMTPNotificationListener.java:218)

    ReplyDelete