server shut down Archive

Sending E-Mail Alert on Weblogic Server Shutdown using WLST

I had to develop a simple script to send e-mail alert when the Managed Server goes down. From whatever time I had, I developed a script that does that, it can be enhanced further depending on the requirement.

I used mailx to send mails, you need to get in touch with your System Administrator if its not configured. You can also use the smtplib that comes with Python. However I found mailx simpler as it was preconfigured in my environment

import os

def sendMail(name, state):
string = name+” is in ” + state + ” state”
cmd = “echo ” + string + ” > tmpfile”
os.system(‘/usr/bin/mailx -s ” SERVER STATE” < tmpfile’)

def getServerNames():
return cmo.getServers()

def serverStatus(server):
cd(‘/ServerLifeCycleRuntimes/’ +server)
return cmo.getState()

def sendAlert():
serverNames= getServerNames()


for name in serverNames:
print name.getName()
serverState = serverStatus(name.getName())
print serverState

if serverState == “SHUTDOWN”:
sendMail(name.getName(), serverState)

if __name__== “main”:
print ’sent!’