In most of production environments there could be possibility of a WebLogic server instances go on overload and crash or it could reach to a non RUNNING state due to many reasons. But if we know the state of that WebLogic server instance then we can act immediately for further harm to be predicated and confidently control that could happen in that WebLogic domain.

Here I am trying to send the alert mail message when one of the WebLogic Managed Server goes to SHUTDOWN state or UNKNOWN state or some other state which is not RUNNING.
-->Python network library smtplib in WLST
WLST supports multiple the network libraries such as- ftplib
- poplib
- imaplib
- smtplib
- telnetlib
Here I am trying to send the alert mail message when one of the WebLogic Managed Server goes to SHUTDOWN state or UNKNOWN state or some other state which is not RUNNING.
Assuming that your machine have SMTP mail service must enabled. Check before creating this script on the box. Here in the following script you can replace the 'To' address value given as pavanwla@MAILSERVER.com with mailing address of your supporting WebLogic Administrators (WLA) list by comma separation.
#====================================================== # Script File : StatusMail.py # Author : Pavan Devarakonda # Updated on : 29th April 2010 #====================================================== import smtplib import time From = "wla@WLSERVER.com" To =["pavanwla@MAILSERVER.com"] Date = time.ctime(time.time()) URL='t3://'+get('ListenAddress')+':'+str(get('ListenPort')) def getServerNames(): domainConfig() return cmo.getServers() def mailing(name, stat): serverRuntime() serverConfig() if stat == 'SHUTDOWN': Subject = ' major: ' else: Subject= 'Critical:' Subject= Subject + 'The Weblogic server instance ' +name + ' is ' + stat Text='The Server ' +name +' in the '+ stat+' Listening at URL ' + URL Msg = ('From: %s\r\nTo: %s\r\nDate: \%s\r\nSubject: %s\r\n\r\n%s\r\n' %(From, To, Date, Subject, Text)) s = smtplib.SMTP('YOURSMTP.DOMAIN.COM') rCode = s.sendmail(From, To, Msg.as_string()) s.quit() if rCode: print 'Fail to send message...' def serverStatus(server): cd('/ServerLifeCycleRuntimes/' +server) return cmo.getState() def checkStatus(): try: connect('username','******','t3://adminIP:AdminPort') serverNames= getServerNames() domainRuntime() for name in serverNames: print name serverState = serverStatus(name) if serverState == "SHUTDOWN": mailing(name, serverState) elif serverStat == 'UNKNOWN': mailing(name, serverState) except: mailing('AdminServer','Connection Fail') if __name__== "main": redirect('./logs/status.log', 'false') checkStatus() print 'done'To make you more comfortable here you need to update few lines 7, 8 10, 27, and 40. Hope you have idea what need to replace in these lines! for your environment.
Cronjob schedule
If you need this script need to run for every 30 mins you can schedule the following line into a shell script. map the shell script to crontab by giving the -e option. If got any trouble please write back to me :)To test run this script in UNIX/Windows/MacOS/anyother...
prompt> java weblogic.WLST StatusMail.py
Keep posting your valuable comments and suggestions on this post.
References: