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 ***********
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
January 27th, 2011 on 11:58 pm
Hey Ravish,
Nice writeup.
Can you please tell me the basic difference between domainRuntime() vs domainRuntimeService()??
January 28th, 2011 on 4:12 pm
Hi Vidhan,
domainRuntimeService:
Provides a common access point for navigating to all runtime and configuration MBeans in the domain as well as to MBeans that provide domain-wide services such as controlling and monitoring the life cycles of servers, coordinating the migration of migratable services etc. and it has the following Child MBeans
* DomainRuntime
* DomainPending
* DomainConfiguration
* ServerRuntimes
domainRuntime:
domainRuntime comes under domainRuntimeService. This MBean provides access to the special service interfaces that exist only on the Administration Server and provide life cycle control over the domain and this can do the following Operations
* findConfiguration
* findDomainConfiguration
* findRuntime
* findRuntimes
* findServerConfiguration
* findService
* getServices
April 13th, 2011 on 9:27 pm
Hi Ravish,
the above script is not working for me. i confirm that mailx is working (i tested). find the script that i executed and the output. (ofcource no email sent, even though i had 15 messages in one of my DistributedQueue)
Please help me, what is the issue
SCRIPT:
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 !!! ” pavankumar.mattipa@xyz.com 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)
====================================================
OUTPUT:
java weblogic.WLST /home/Email_Alert_JMS.py t3://localhost:7001
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
======================================================
April 13th, 2011 on 10:23 pm
Hi Pavan,
It would be really difficult you make out the aliments in the above given script hence would suggest you to send your script by mail to contact@middlewaremagic.com
Also I have noticed that after your email address ( we have changed your email address for maintaining your privacy) you have give “0” instead of ” < rw_file ' " try this change and if still it does not work then send us the script which you are using on our email address.
Regards,
Ravish Mody
April 14th, 2011 on 2:05 pm
Hi Ravish,
Now the script is working. Thank you so much.
Regards,
Pavan
April 14th, 2011 on 6:52 pm
Hi Ravish,
I donot want to hard code the username and password with in the script. Please suggest me the alternative approach for this (script snap shot).
Regards,
Pavan
April 14th, 2011 on 8:52 pm
Hi Pavan,
You can use storeUserConfig to create an encrypted password userconfig and key file which can then be used in the WLST script something as shown below.
Example:
#To create the user configuration file and key file:
connect(‘weblogic’, ‘weblogic’, ‘localhost:7001’)
storeUserConfig(‘c:/myFiles/myuserconfigfile.secure’,’c:/myFiles/myuserkeyfile.secure’)
#To use the user configuration file and key file:
connect(userConfigFile=’c:/myfiles/myuserconfigfile.secure’,userKeyFile=’c:/myfiles/myuserkeyfile.secure’,url=’t3://localhost:7001′)
Regards,
Ravish Mody
April 15th, 2011 on 7:14 pm
Thanks Ravish.
1. Is there any way that we can use the admin server credentials by default?
2. I have 4 Distributed queues in my environment and i need to have different alert sent out when each queue exceeded its own count.
please help me how can i get these.
Thanks,
pavan
August 9th, 2011 on 5:01 pm
Hi Ravish,
Can you sugest me how can i add the time stamp of when the alert sent out.
Thanks,
August 9th, 2011 on 7:04 pm
Hi mpkbang,
You can import the “Date” from the “java.util” and then get the date as well as time out of it. Following things has to be done
1) Add the below line in the top of the script
from java.util import Date
2) Then add this line
today = Date()
3) Use “today” in the string format during sending writing on the file which would be used to send the read and send the mail something like below
str3 = ‘Queue with the NAME: ‘+ dest +’ , has exceeded the Messages Current Count and now the CONUT is: ‘ + str(count)+” Time = ” + today.toString()
That should work. However I have not tested it my self. Do test it and let us know if that works fine.
Regards,
Ravish Mody
January 16th, 2012 on 11:04 am
Hi,
Thanks for the post. It work Fine in single instance.
But how to use it in a cluster. I think the same script will work. I have not yet tried it yet in cluster.
I have 2 instance along with admin server running in machine1 and another 2 instance running in machine2.
Thanks in advance
January 19th, 2012 on 10:07 am
Hi kannanmugundan,
The same script should work fine for Clustered Environment.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
January 20th, 2012 on 10:59 pm
Hi Middleware Team,
I am getting “The object that you were viewing has been deleted, either by you or another user. Please make another selection” while trying to access the monitoring tab of jms queue.
Navigation through console:-
Home–>JMS Modules–>ModuleName–>jms queue – monitoring.
I am using weblogic 9.2 .could you please help to navigate the jms queue monitoring tab through WLST?
Thanks,
Ravi Shankar Kumar.
April 10th, 2012 on 2:00 am
Hi Ravish,
could you please let me know how to just monitor specific Topics/Queues and not all of them.
Cheers,
Mgalal
June 15th, 2012 on 12:27 am
Greetings…
I noticed that you’re making a OS call to send mail…
os.system(‘/bin/mailx -s “ALERT: Messages Current Count Exceeded Limit !!! ” admin@company.com < rw_file') I'm wondering why you chose to use this as opposed to a Jython smtp call?? Thanks Jeff B