Search This Blog

Sunday, May 24, 2009

Cosmotising your WLST output

Here I am with new idea that colored output according to the state of the Server.
Hope most of you(WLA) knows WLST script for displaying Server status, my idea is when the server state is in SHUTDOWN state let it display in red color, STARTING state in YELLOW, and geen for RUNNING state and so on... colors you can specify as per your choice. 

I ran thru google for searching colors in python... it is simple logic print instruction in python putting UNIX shell code way. The color code need to be prefix in the line where color need to appear in the output.



My choice of WLST is that it should have a provision to rerun the script if user wish to run the script after a while. this makes less time to get output because re-initializing of WLST is not required 

CODE Snippet:
#Fetch the state of the every WebLogic instance
        for name in serverNames:
                cd("/ServerLifeCycleRuntimes/" + name.getName())
                serverState = cmo.getState()
                if serverState == "RUNNING":
                        print 'Server ' + name.getName() + ' is :\033[1;32m' + serverState + '\033[0m'
                elif serverState == "STARTING":
                        print 'Server ' + name.getName() + ' is :\033[1;33m' + serverState + '\033[0m'
                elif serverState == "UNKNOWN":
                        print 'Server ' + name.getName() + ' is :\033[1;34m' + serverState + '\033[0m'
                else:
                        print 'Server ' + name.getName() + ' is :\033[1;31m' + serverState + '\033[0m'



Popular Posts