Monday, July 18, 2011

Script to get the status of the server instances and their health

Hi,

This script will give you the server status as well as their health status for all servers in a domain.

please change the user credentials as per your requirement and correct me if i'm wrong.

Server_status.py
****************
#######################################################################################
# This script gets the health status and server status in a domain #
# Author: Krishna Sumanth Naishadam #
#######################################################################################
import os
import time
import sys

# To get the health status of the servers
def healstat(server_name):
try:
cd('/ServerRuntimes/'+server_name+'/ThreadPoolRuntime/ThreadPoolRuntime')
s=get('HealthState')
x=s.toString().split(',')[1].split(':')[1]
print server.getName() + ': ' + x
print '============================================='
except WLSTException,e:
print dumpStack()

# Main
if __name__== "main":
global s,x
connect("username","password","t3://WL-ADMIN-HOST:port")
domainConfig()
servers = cmo.getServers()
domainRuntime()

# To get the status of the servers
for server in servers:
try:
print '============================================='
cd('/ServerLifeCycleRuntimes/' + server.getName())
print server.getName() + ': ' + get('State')
healstat(server.getName())
except WLSTException,e:
print dumpStack()

disconnect()

server_status.sh
****************

We are using this shell script to call the above script
WL_HOME="Weblogic Home Path"

# set up common environment
. "${WL_HOME}/server/bin/setWLSEnv.sh"

CLASSPATH="${CLASSPATH}:${WL_HOME}/common/eval/pointbase/lib/pbembedded51.jar:${WL_HOME}/common/eval/pointbase/lib/pbtools51.jar:${WL_HOME}/common/eval/pointbase/lib/pbclient51.jar"

"${JAVA_HOME}/bin/java" -Xmx124m -Dprod.props.file=${WL_HOME}/.product.properties weblogic.WLST server_status.py $*



Output:
=======================
admin: RUNNING
admin: HEALTH_OK
=======================
=======================
man1: RUNNING
man1: HEALTH_WARN
=======================

3 comments:

  1. Hello Krishna did u made complete subsystems HealthStatus?

    ReplyDelete
  2. Hi Krishna,

    We are trying to get the server health using below commands. But unfortunately it is giving “HELATH_OK” for all server even though they are in warning state.
    Could you please help me here.

    serverHealth = get(‘HealthState’)
    Health = serverHealth.toString().split(‘,’)[1].split(‘:’)[1]

    Regards,
    Naveen

    ReplyDelete
  3. I am getting this syntax error in the script:


    Problem invoking WLST - Traceback (innermost last):
    (no code object) at line 0
    File "/home/user/path/wl_status1.py", line 11
    try:
    ^
    SyntaxError: invalid syntax


    Any Ideas?
    Thanks,
    P

    ReplyDelete