Ravish Mody

Many times we need some alert mails which can let us know the current status of the JMS resources. Jay had written a pretty good WLST script to monitor the JMS WebLogic JMS Monitoring Using WLS , Today we have created another WLST script which would send an alert mail when the Message Current Count has been exceeded.

The same WLST script can be used and modified as per your requirements and get an alert email when a Pending Message Count, Messages High Count etc gets exceeded. Following is the WLST script which would check if the count has  been exceeded the given count and would send a mail to the respective administrator and alert them about this issue.

Steps to Create an Eamil Alert for JMS

Step-1)  Create a WLST Script somewhere in your file system with some name like Alert_JMS.py”   inside “C:WLST_JMS” contents will be something like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################

import os

def sendMail(count,dest):
   str3 = 'Queue with the NAME: '+  dest +' , has exceeded the Messages Current Count and now the CONUT is: ' + str(count)
   cmd = "echo " + str3 + " > rw_file"
   os.system(cmd)
   os.system('/bin/mailx -s  "ALERT: Messages Current Count Exceeded Limit !!! " admin@company.com < rw_file')
   print '*********  ALTERT MAIL HAS BEEN SENT  ***********'

connect('weblogic','weblogic','t3://localhost:8001')
servers = domainRuntimeService.getServerRuntimes();
if (len(servers) > 0):
	for server in servers:
		jmsRuntime = server.getJMSRuntime();
		jmsServers = jmsRuntime.getJMSServers();
		for jmsServer in jmsServers:
			destinations = jmsServer.getDestinations();
			for destination in destinations:
				if destination.getMessagesCurrentCount() > 3:
					count=destination.getMessagesCurrentCount()
					dest = destination.getName()
					print '.....Queue Exceeded the Message Current Count : ' , count
					print ''
					sendMail(count , dest)

Step-2) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh”  to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH%    or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492

Step-3) Now run the WLST Script in the same command prompt like following:

java   weblogic.WLST  Alert_JMS.py

You will see the following kind of results in the command prompt

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:8001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_8001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

.....Queue Exceeded the Message Current Count :  5

*********  ALTERT MAIL HAS BEEN SENT  ***********

Email Alert

You can run this python script in your cron-job at the background and so the it keeps on running and send you the mails whenever the counts gets exceeded. Hope this would help all the administrators and make there job easier.

NOTE: This script is using mailx (i.e. but Windows box does not have mailx utility) so please do check if you mailx is configured properly or else script would run properly but the mail would not be sent.

Regards,

Ravish Mody

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.