Mar 14, 2015

Setting up Watches and Notifications in Weblogic Server

If you are only using the Weblogic Administration console for monitoring your Weblogic platform, you can still set up alerts to inform you about the state of your system. This post will cover just such a setup that will send email notifications to the administrators, although SNMP traps, JMX, and JMS are also supported.
To set up your email alerts you will need to cover these main steps:
  1. In our specific case of email notifications, you need to set up a JavaMailSession object, that will actually be used by the Notifications to send the alerts through the specified email server;
  2. Set up a diagnostic module and define any metrics that you would like to collect;
  3. Define the Watches you are interested in – this is the situation that you want to trigger your alert. It can be a certain message in the log files, or a certain value of a collected metric, or a certain event occurring in the system.
  4. Define the Notifications you would like to receive and associate the Watch to a Notification;
In the below example, we will set up alerts on the state of the Weblogic Managed Server, so the admin will get a notification when a server is not in the RUNNING state.

1.       Set up the Mail Session object.

Note that the JavaMailSession itself does not offer email server capabilities, but it only provides the JavaMail API so that applications can send and receive email from an already existing server.
a)      Click “Lock & Edit” to acquire a configuration lock
b)      Expand Services -> Mail Sessions and click “New” to create a new Java Mail Session object
c)       Provide Name, JNDI Name and JavaMail Properties as follow:
Name – WLSAlertsMailSession
JNDI Name – WLSAlertsMailSession
(You may enter whatever value here, but it’s best to keep the same value for the two names)
JavaMail Properties:
mail.debug=”true” – not mandatory, but recommended should you want to troubleshoot why your alerts are not getting through
mail.smtp.port=25
mail.smtp.from=”soa_admin@example.com”
mail.smtp.host=email.server.example.com
d)      Click next to target the mail session to a server (either managed or AdminServer) and click finish. You need to do this so that the MailSession is exposed on the servers JNDI tree.
e)      Activate the changes by clicking “Activate Changes”.



2.  Set up a Diagnostic Module and define a metric of interest as a Collected Metric.

a)      Expand Diagnostics -> Diagnostics Modules and click “New” to create a new diagnostics module. Provide a name and description.
Name – DiagModuleWLDF
Description – This is a WLDF module for testing email notifications
b)      Select the newly created module and select “Targets” tab. Select the appropriate server for target as before
c)       Click “Save” and “Activate”
d)      Click “Lock & Edit” to acquire a new configuration lock
e)      Click on the “Collected Metrics” tab and click “New”
f)       Select “ServerRuntime” and click “Next”
g)      Select “ServerRuntimeMBean” from the dropdown
h)      From the list of collected attributes select “State” and move it in the “Chosen” category; Click “Next”
i)        From the instances list select the servers you would like to be informed about by selecting an instances and moving it to the “Chosen” category
j)        Click “Finish”
k)      Click “Save” and “Activate”
Notice that this metric is collected at a configurable interval, by default 300000ms

3.       Set up a new Watch rule

a)      Click “Lock & Edit” to acquire a configuration lock
b)      Navigate to the diagnostic module created above (DiagModuleWLDF) and select the “Watches and Notifications” tab and “Watches” sub-tab (if not already selected)
c)       Click “New” to create a new Watch. Provide the name and select the type as “Collected Metrics”. Also make sure the watch is enabled.
Name – ServerStateWatch
d)      Click “Next”
e)      Click “Add Expressions”
f)       Ensure that “ServerRuntime” is selected and click “Next”
g)      From the dropdown, select “ServerRuntimeMBean” again. The click “Next”
h)      Select the instance for the appropriate server from the list for “Instance” and click “Next”
i)        For “Message Attribute” select “State”, “!=” for “Operator” and type “RUNNING” (all capital letters) for “Value”. Click “Finish” the Watch
j)        Activate the changes
This Watch will now be triggered every time the server state is other than RUNNING. Please note that this is dependent on the Collected Metric’s sampling period as well.

 4.       Setting up the Notification and associating it with a certain Watch

a)      Click “Lock & Edit” to acquire a configuration lock
b)      Navigate to the diagnostic module created above and select the “Watches and Notifications” tab and “Notification” sub-tab
c)       Click “New” to create a new Notification
d)      Select “SMTP (E-Mail) for Type and click “Next”
e)      Provide a name – ServerStateNotification. The notification must be enabled, of course. Click “Next”.
f)       Configure the following properties for the “Config Notification – SMTP Properties” page
g)      Mail Session Name – WLSAlertsMailSession
h)      E-Mail Recipients – admin@example.com
i)        Click “Finish”.
j)        Activate the changes
To associate the watch and the notification:
a)      Click “Lock & Edit” to acquire a configuration lock
b)      Navigate to the diagnostic module created above (DiagModuleWLDF) and select the “Watches and Notifications” tab and “Watches” sub-tab (if not already selected)
c)       Select the watch you created earlier – ServerStateWatch
d)      Select the “Notifications” tab and move the “ServerStateNotification” from Available to Chosen
e)      Click “Save”
f)       Select the “Alarms” tab and select “Use an automatic reset alarm”. Set the “Automatic reset period” so that you don’t get spammed with alerts email  and click “Save”.
g)      Click “Activate Changes
And that’s it. Next time one of your servers is in a state other than RUNNING (and is picked up by the collected metric based on the sampled period), you will receive an email in the form of: