WebLogic 12c WLST Examples & WLSDM WLST Console

WLSDM for WebLogic
Mar 27, 2020 · 3 min read

The Oracle Weblogic Scripting Tool (WLST) is stand for monitoring, managing, and configuring Oracle WebLogic Server from the command line.

While monitoring WebLogic domains mostly administrators prefer to use WLST (WebLogic Scripting Tool) scripts but there are more efficient and robust way available to monitor WebLogic domain resources like health status and states of servers (JVMs), deployments, data sources and JMS resources etc.

WLSDM has own WLST console and below options are available in WLSDM console.

-Save WLST scripts in “scripts” tab.
-Save WLST connections.
-Change WLST console theme

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

WebLogic scripting language related their environment needs by following the Jython language commands.

Monitoring Oracle WebLogic Server State using WLST Script

# Node Manager needs to be running to run this script.

import thread
import time

def checkHealth(serverName):
while 1:
slBean = getSLCRT(serverName)
status = slBean.getState()
print ‘Status of Managed Server is ‘+status
if status != “RUNNING”:
print ‘Starting server ‘+serverName
start(serverName, block=”true”)
time.sleep(5)

def getSLCRT(svrName):
domainRuntime()
slrBean = cmo.lookupServerLifecycleRuntime(svrName)
return slrBean

checkHealth(“myserver”)

Monitoring Oracle WebLogic Server JVM Heap Size using WLST Script

waitTime=180000
THRESHOLD=300000000
uname = “adminusername”
pwd = “adminpassword”
url = “t3://localhost:7001”
def monitorJVMHeapSize():
connect(uname, pwd, url)
while 1:
serverNames = getRunningServerNames()
domainRuntime()
for name in serverNames:
print ‘Now checking ‘+name.getName()
try:
cd(“/ServerRuntimes/”+name.getName()+”/JVMRuntime/”+name.getName())
heapSize = cmo.getHeapSizeCurrent()
if heapSize > THRESHOLD:
# do whatever is neccessary, send alerts, send email etc
print ‘WARNING: The HEAPSIZE is Greater than the Threshold’
else:
print heapSize
except WLSTException,e:
# this typically means the server is not active, just ignore
# pass
print “Ignoring exception “ + e.getMessage()
java.lang.Thread.sleep(waitTime)

def getRunningServerNames():
# only returns the currently running servers in the domain
return domainRuntimeService.getServerRuntimes()

if __name__== “main”:
monitorJVMHeapSize()

WLST Commands: Shutdown and Start Managed Server

connect(‘weblogic’, ‘welcome1’, ‘t3://localhost:7001’)
domainRuntime()
cd(‘ServerRuntimes’)
cd(‘ManagedServer_1’)
cmo.stop()

WLST Commands: Create LDAP Provider

# variables
url = ‘t3://localhost:7001’
domainname = ‘WLSDMLabDmn_12212’
username = ‘weblogic’
password = ‘welcome1’
realmname = ‘myrealm’
providername = ‘CompanyLDAP’
defaultprovidername = ‘DefaultAuthenticator’
controlflag = ‘SUFFICIENT’
providerhost = ‘localhost’
providerport = 389
principal = ‘cn=Manager,dc=maxcrc,dc=com’
credential = ‘secret’
userbasedn = ‘ou=users,dc=maxcrc,dc=com’
usernameattrib = ‘cn’
groupbasedn = ‘ou=Groups,dc=maxcrc,dc=com’
groupnameattrib = ‘cn’

# Connect to administration server
connect(username, password, url)

# Check if provider already exists
try:
cd(‘/SecurityConfiguration/’ + domainname + ‘/Realms/’ + realmname + ‘/AuthenticationProviders/’ + providername)
print ‘>>>The Authentication Provider ‘ + providername + ‘ already exists.’
exit()
except WLSTException:
pass

print ‘>>>Creating new Authentication Provider named ‘ + providername + ‘.’

edit()
startEdit()
cd(‘/’)

# Create provider
realm = getMBean(‘/SecurityConfiguration/’ + domainname + ‘/Realms/’ + realmname)
provider = realm.createAuthenticationProvider(providername, ‘weblogic.security.providers.authentication.LDAPAuthenticator’)
provider.setControlFlag(controlflag)
provider.setHost(providerhost)
provider.setPort(providerport)
provider.setPrincipal(principal)
provider.setCredential(credential)
provider.setUserBaseDN(userbasedn)
provider.setUserNameAttribute(usernameattrib)
provider.setGroupBaseDN(groupbasedn)
provider.setStaticGroupNameAttribute(groupnameattrib)
provider.setCacheEnabled(false)

# Change the control flag of the default authentication provider
cd(‘/SecurityConfiguration/’ + domainname + ‘/Realms/’ + realmname + ‘/AuthenticationProviders/’ + defaultprovidername)
cmo.setControlFlag(controlflag)

# Reorder the authentication providers (new one, embedded LDAP, default asserter)
cd(‘/SecurityConfiguration/’ + domainname + ‘/Realms/’ + realmname)
set(‘AuthenticationProviders’,jarray.array([ObjectName(‘Security:Name=myrealmCompanyLDAP’), ObjectName(‘Security:Name=myrealmDefaultAuthenticator’), ObjectName(‘Security:Name=myrealmDefaultIdentityAsserter’)], ObjectName))

# Activate changes
save()
activate(block=’true’)
print ‘>>>Authentication Provider created successfully.’
exit()

Reference and more examples:

Installation is really easy and you can setup a complete monitoring infrastructure in less than 5 minutes. If you want to try then go to download page below URL:

Image for post
Image for post

WLSDM for WebLogic

WLSDM is a WebLogic console extension which enables…

WLSDM for WebLogic

Written by

WLSDM for WebLogic

Native Oracle WebLogic Monitoring WLSDM is developed by the best WebLogic developers for the best WebLogic administrators to support mission critical HA domains. Supports all plain WebLogic and Fusion Middleware (FMW) WebLogic domains. Download now! https://wlsdm.com/download

WLSDM for WebLogic

Written by

WLSDM for WebLogic

Native Oracle WebLogic Monitoring WLSDM is developed by the best WebLogic developers for the best WebLogic administrators to support mission critical HA domains. Supports all plain WebLogic and Fusion Middleware (FMW) WebLogic domains. Download now! https://wlsdm.com/download

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface.

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox.

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store