Script: get running/active servers in weblogic (wlst/python)

  • Given a weblogic server.
  • We would like to get list of running servers in current domain using python script.
  • We would following the trailing steps to get list of active servers (WLST).
    • Connect to admin server using t3 protocol.
    • Get list of all servers (RUNNING, SHUTDOWN, STARTING etc) in current domain.
    • Loop through all servers to filter out RUNNING servers.
    • Disconnect from admin server

List of running servers in weblogic domain (WLST /example)

def runningServers():

    #Get list of servers in current domain
    servers = cmo.getServers()
    domainRuntime()
   
    print "List of running servers in current domain: "
    for server in servers:
        cd("/ServerLifeCycleRuntimes/" + server.getName())
        state = cmo.getState()
        if state == "RUNNING":
            print server.getName()
    print "End of script"

connect("weblogic","welcome2","myAdminServer:7001")

runningServers()

disconnect()

List server status in weblogic domain (WLST/example):

c:\fmw_12.2.1.3.0\wls12213\oracle_common\common\bin>wlst.cmd d:\code\ListRunningServers.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://myAdminServer:7001 with userid weblogic ...
Successfully connected to Admin Server "AdminServer" that belongs to domain "osb_domain".

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.

Location changed to domainRuntime tree. This is a read-only tree
with DomainMBean as the root MBean.
For more help, use help('domainRuntime')

List of running servers in current domain:
AdminServer
pro_server1
pro_server3
pro_server9

End of script
Disconnected from weblogic server: AdminServer
Scroll to Top