WebLogic Notifications – Watch the Log and Send Email

emailCan WebLogic send an email when a certain message shows up in the WLS log?  The answer is yes and it is pretty straight-forward to configure.  In this case, my colleague Sherwood wanted to get an email when the message indicating that an SSL certificate is going to expire within 30 days is written to the log.  The WebLogic Diagnostic Framework or WLDF enables this capability with a sub-feature called Watches and Notifications.  Here is a real simple example to get an email when the server starts in a RUNNING state.

Configure a Mail Session

The console docs give you the step-by-step.  Here’s what mine looks like – don’t forget to target it at all of your servers.  I use Apache James as mail server on my localhost.  Click to enlarge.

mailSession

Configure a Diagnostic System Module

The console docs again give you the step-by step, make sure you target it at your server.

Once you have the system module in place, then configure a Notifcation that references the Mail Session you set up previously.  You can see from the screenshot that there is an easy way to change the subject and body of the email.  Click to enlarge.

emailSettings

Then configure a Log Watch that uses the Notification.  In my server log, the message looks like this:

####<Jul 15, 2010 8:16:46 PM CDT> <Notice> <WebLogicServer> <jbayer-us> <AdminServer> <main> <<WLS Kernel>> <> <> <1279243006546> <BEA-000360> <Server started in RUNNING mode>


So that means we should use the expression builder to look for this particular message id.  Remember, WebLogic is multi-lingual, so instead of looking for the hard-coded text, just search for the unique ID of the untranslated log message.

ruleExpression ruleExpression [2]

The last step is a gotcha I missed the first time.  The log message we are searching for is at a “Notice” level.  By default Log Watches only are fired against “Warning” and higher (I think – I forgot what the default was).  You need to change it on the “Watches and Notifications” tab of the Diagnostic System Module.  Click to enlarge.

logWatchServerity

That should be it, restart the server so that the message is logged and check your email.  Click to enlarge.

thunderbirdEmail

Of course WLDF can do a lot more sophisticated notifications too.  In addition to email possible notifcation actions are JMS, JMX, SNMP traps, and capturing a system diagnostic image.  The watches can be more sophisticated too, such as watching JMX attributes which is described in this other blog.  If you have any issues, it can be useful to enable “Debug” of the parts of the diagnostics subsystem in your Server configuration and check out the log messages.

Screencast following the procedure above


Comments:

James, Thanks for this detailed steps. Do you how do we pass the password for the smtp server which requires the authentication? I tried mail.smtp.user and mail.smtp.password, it does'nt seems to work

Posted by Rai on July 17, 2010 at 04:20 AM PDT #

Rai, I'm not sure the WebLogic Mail Session can be configured to use SMTP Auth without making some API calls since it simply uses java mail properties. Looking at the Java Mail properties page, there isn't a property for the password, just the mail.smtp.auth=true and mail.smtp.user=username So it looks like you can do it with the API calls by calling the Transport.connect(username,password) method. You can get the Transport reference from the Session. You may also be able to use an Authenticator, here's what I would try first. 1) Use JNDI to get the reference to the Mail Session 2) Get the Transport object and call connect Transport tr = session.getTransport("smtp"); tr.connect(username, password); .... msg.saveChanges(); // don't forget this tr.sendMessage(msg, msg.getAllRecipients()); tr.close(); ... See here: http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html and here: http://download.oracle.com/docs/cd/E14571_01/web.1111/e13706/javamail.htm#i1063041 and here: http://java.sun.com/products/javamail/javadocs/javax/mail/Service.html#connect%28java.lang.String,%20java.lang.String%29 Good luck, James

Posted by james.bayer on July 18, 2010 at 12:14 PM PDT #

I could do this programmatically, however we could not make use of the bulit-in wldf notification option. Also I tried to create JMS notification for an event and put this email notification code inside an MDB. That works, However In-case of JMS notification jms message content has just jms Message ID. Is there any way we can include the error/warning code BEA-36000, BEA-000337 etc?

Posted by Rai on July 18, 2010 at 02:20 PM PDT #

Rai, That's a good point about WLDF email notification and I'll check with the team about that and the JMS message contents. I'll let you know what I find out. Thanks, James

Posted by james.bayer on July 18, 2010 at 09:16 PM PDT #

Hi, Do you know how to access the Health State, not the State (Running)? The health state usually says 'OK' but I want to be notified of when it's NOT OK. Thanks,

Posted by Craig on August 02, 2010 at 09:46 PM PDT #

Craig, I have two thoughts without having had time to try anything. 1) See if you can adjust the log level to get Health changes logged and take action whenever the Health is not ok 2) if #1 has issues, try using the JMX Watch mechanism instead of the Log Watch I'll update this if I have a chance to try any of these in the future. Good luck, James

Posted by james.bayer on August 03, 2010 at 01:56 PM PDT #

Hi James, Thanks for the response. As I am a newbie to wls please bare with me - sorry. Adjust the log level - is through the admin console? If so could do with a little more info. I should be OK with JMX watch. Thanks, Craig

Posted by Craig on August 03, 2010 at 07:00 PM PDT #

Craig, It probably depends on what your use-case is. Can you describe it? For example, if your Watch is on the managed server that has ownership of the log, then you can probably look at this page: http://download.oracle.com/docs/cd/E14571_01/apirefs.1111/e14397/T3Srvr.html Search for WL-000385 There are other relevant log messages there that also cover various failure conditions. But if the server health is bad, you may not want to depend on that server to notify you of issues. In this case the log for server health is CRITICAL - so I don't think log level adjustment is required. If you want the Admin Server to Watch and Notifiy when the state of one of it's managed servers is not OK, then the Harvester Watch (for JMX attribute monitoring) is likely what you want. See: http://download.oracle.com/docs/cd/E14571_01/web.1111/e13714/config_watches.htm#i1066444 I'm pretty tied up, but if I spend some time on this later on and can give a better example I will. Thanks, James

Posted by james.bayer on August 04, 2010 at 03:17 AM PDT #

Hi James, Thanks for the video... I have a SOA Suite 11g (11.1.1.4) instance installed and had an issue where a problem occurred with the domain, causing the soa-infra composite application to go to a "Failed" state on my soa managed server. I could see the message from the FMW EM console but I'd like to get an Email notification sent out if this occurs in Production. Can this be used for that purpose? and if so, I could use some help in configuring and setting this up.

Posted by Phil on March 24, 2011 at 05:27 AM PDT #

Phil, I have not tried this with a SOA Suite application, but it sounds like you're not talking about a composite so much as the soa-infra application itself. I think configuring a Harvester Watch and Notification that looks at the application MBean state (which is what is showing in the FMW EM console) is how you would do this. http://download.oracle.com/docs/cd/E17904_01/web.1111/e13714/config_watches.htm#i1066444 For example, here is WLST showing that MBean: wls:/base_domain/serverRuntime/ApplicationRuntimes/HelloWorldEJB> cmo [MBeanServerInvocationHandler]com.bea:ServerRuntime=AdminServer,Name=HelloWorldEJB,Type=ApplicationRuntime wls:/base_domain/serverRuntime/ApplicationRuntimes/HelloWorldEJB> cmo.getHealthState() Component:null,State:HEALTH_OK,MBean:null,ReasonCode:[] Now you'd just have to write the correct Watch Rule, which I'm not sure exactly how to do in this case. You may want to ask the SOA Suite OTN forum to see if anyone has done this: http://forums.oracle.com/forums/forum.jspa?forumID=320

Posted by james.bayer on March 24, 2011 at 02:41 PM PDT #

Phil, I found the MBean attributes for State and Health via WLST. In this example my application is called HelloWorldEJB State (ACTIVE, PREPARED, UNPREPARED) is like below, where 2 is ACTIVE in this case, although the docs aren't clear on that (we've filed some doc bugs to make this more clear in the future) wls:/base_domain/serverRuntime/ApplicationRuntimes/HelloWorldEJB> cmo [MBeanServerInvocationHandler]com.bea:ServerRuntime=AdminServer,Name=HelloWorldEJB,Type=ApplicationRuntime wls:/base_domain/serverRuntime/ApplicationRuntimes/HelloWorldEJB> cmo.getActiveVersionState() 2 Health (OK, FAILED, and probably others) is like: wls:/base_domain/serverRuntime/ApplicationRuntimes/HelloWorldEJB> cmo.getHealthState().getState() 0 So now you can configure both a Watch and a Notification based on either of those. I'll probably add a blog entry on that as soon as I get some time. Hopefully this gets you going. You can use an Alarm so that you don't repeatedly get bothered by emails until a time period elapses too. Thanks, James

Posted by James Bayer on March 25, 2011 at 07:15 AM PDT #

Hi James, I am using my company's email client(outlook) to set up smtp info in mail session ; but i haven't received alerts. I did exactly as you suggested....Also, what do i do if i need to set some more different types of alerts. Is there any other blog with all the different alerts i could configure?

Posted by guest on May 11, 2011 at 10:24 AM PDT #

Sid, Your company SMTP server may require authentication, which I don't think is supported. I believe the WLS SMTP support assumes that it is an open SMTP server. Try setting up a test SMTP server like Apache James to test the theory. You may have to check with the email team to see what options you have there. Regarding other types of alerts, you can base it on JMX metric thresholds, etc. I'm not aware of other write-ups in this area. Thanks, James

Posted by james.bayer on May 12, 2011 at 07:57 AM PDT #

Hi James,

Do I need a mail server inorder to work with mailsession feature.
If yes, Please let me know how do I set up the same.
Any help would be very much appreciated.

Regards,
Vijay

Posted by guest on June 28, 2011 at 07:04 PM PDT #

Vijay,

Yes you need to provide access to an SMTP server of some kind because WebLogic Server itself is not a mail server. I use Apache James for my testing. http://james.apache.org/
They've written up how to use it here:
http://wiki.apache.org/james/JamesQuickstart

Thanks, James

Posted by james.bayer on June 29, 2011 at 06:50 AM PDT #

Hello James,

Thanks for the clarification. I have 5 server running on 5 different hosts and Would I be able to monitor all the 5 servers with watches and notification feature? If yes, Please let me know how can I do that.

Appreciate your prompt response!

Cheers,
Vijay R

Posted by guest on July 02, 2011 at 11:31 AM PDT #

Vijay, It's simple. Just follow the same approach described and use the "target" feature of the Mail Session and WLDF System Modules to target them at each of the 5 servers. Thanks, James

Posted by james.bayer on July 04, 2011 at 04:50 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

James Bayer Image
I was formerly a Product Manager on the WebLogic Server team based out of Oracle HQ. You can find my new blog at http://iamjambay.com.
Follow Me on Twitter
Oracle WebLogic

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today