Skip to content

WebLogic: Using a WLST script to find a specific word in an object

On a WebLogic Server, I had to write a WLST script to find the current number of consumers accessing a specific JMS Queue destination as this is not monitored by Oracle Grid Control 11g or Oracle Cloud Control 12c. Knowing only the short name of the queue, I uses a regular expression in my WLST script to find the needed information.

To find the correct queue destination I had to search the Queue Destination Name. But in the Runtime tree, the fully-qualified name of this queue resource is preceded by the parent module name, separated by an exclamation point (!) (e.g DocumentApplicationJMSSystemModule!SOAReqMSQ). So how can I find an object using the short name SOAReqMSQ?

Finding the object via WLST script

To achieve this task, you have to:

Step 1: Use a regular expression by adding in your WLST script:

import re

 

Step 2: Use the primitive operation:

re.search(pattern, string[, flags])

 

Step 3: Search only for the defined word and not more:

If you search for SOAReqMSQ using…

cQueueName='SOAReqMSQ'
result = re.search(cQueueName,destination.getName());
...the result will be:
DocumentApplicationJMSSystemModule!SOAReqMSQDocumentApplicationJMSSystemModule!SOAReqMSQ_ErrorQ
 To find the correct one, use the $ to match the end of the string
cQueueName='SOAReqMSQ$'
result = re.search(cQueueName,destination.getName());

This way, DocumentApplicationJMSSystemModule!SOAReqMSQ may be found.

Step 4: In the end, your script should look similar to this (the important information related to the search issue is underlined):

import re


# check queue name
cQueueName='SOAReqMSQ$'


# check only the queue for the Managed Server Name containing soa01
cServer='soa01'

connect(userConfigFile='/opt/user_projects/domains/testdomain/security/uc',userKeyFile='/opt/user_projects/domains/testdomain/security/uk',url='t3://testhost:8101')

# get server list
servers = domainRuntimeService.getServerRuntimes();

if (len(servers) > 0):
for server in servers:
# find if ServerName contains soa01
result = re.search(cServer,server.getName());
if result != None:
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
jmsName = jmsRuntime.getName();
print 'n';
print 'Name',jmsName;
print '----------------------------';
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();
for destination in destinations:
result = re.search(cQueueName,destination.getName());
if result != None:
print 'DESTINATION:',destination.getName();
print 'JMS Server:',jmsServer.getName();
print 'ConsumersCurrentCount:',destination.getConsumersCurrentCount()

Step 5: Here is the script output:

Name testdomainsoa01.jms
----------------------------
DESTINATION: DocumentApplicationJMSSystemModule!SOAReqMSQ
JMS Server: DocumentApplicationJMSServer
ConsumersCurrentCount: 0

This python script can be then called by a shell script that will be integrated, for instance, as a UDM script in Grid Control 11g.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Gérard Wisson

Gérard Wisson

Gérard Wisson has more than twenty years of experience in Enterprise Content Management (ECM) with Documentum and in Oracle WebLogic and Java EE infrastructures. He specializes in ECM infrastructure services, including installation, upgrade, high availability, and administration, and in Oracle WebLogic installation, configuration, and management. He also monitors and optimizes Java EE infrastructures with Grid/Cloud Control and JVMD. Prior to joining dbi services, Gérard was Senior Consultant at Solfit in Basel. He holds a diploma in Electrical Engineering from the University of Strasbourg. His industry experience covers financial services and banking, chemicals, and pharmaceuticals.View Author posts

23 posts since May 2012

Most read in Application Server

The Application Server posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *