WebLogic 12c WLST Examples & WLSDM WLST Console

WLSDM for WebLogic
WLSDM for WebLogic
Published in
3 min readMar 27, 2020

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

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: https://wlsdm.com/weblogic-wlst-scripting-vs-wlsdm

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:

--

--