Tuesday, May 31, 2016

WLST script to get coherence server status


If coherence is installed on weblogic server, we can monitor the status of the coherence server using below WLST script. In this script I am passing connection details as a parameter, you can follow any other approach or simply provide details in "connect()" function.

save below script as getCoherenceHealth.py 

#redirect wlst's own output to null, print lines in the script itself
redirect('/dev/null', 'false')

wlsuser = sys.argv[1]
wlspassword = sys.argv[2]
wlsurl = sys.argv[3]
#targetServer = sys.argv[4]

connect(wlsuser,wlspassword,wlsurl)

servers = cmo.getCoherenceServers()
domainRuntime()
stoppedServers = []

for server in servers:
    try:
        cd('/CoherenceServerLifeCycleRuntimes/' + server.getName())
        currentState = cmo.getState()
        if currentState == 'RUNNING':
            print server.getName() + ': ' + 'RUNNING'
        else:
            print server.getName() + ': ' + 'DOWN (' + currentState + ')'

    except WLSTException, e:
        print server.getName() + ': ' + 'SHUTDOWN'
        stoppedServers.append(server.getName())

disconnect()
#rm ./wlst.log
exit()


you can call this script by passing required arguments:
java -cp $WL_HOME/server/lib/weblogic.jar weblogic.WLST getCoherenceHealth.py $WebUSER $WebPass $WL_URL