Search This Blog

Oracle Fusion Middleware Administration Course

Oracle Fusion Middleware Administration Course
OFMW Admin Course

Friday, May 28, 2010

Mail from WLST when abnormal state for Server

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.

Python network library smtplib in WLST

WLST supports multiple the network libraries such as

  1. ftplib 
  2. poplib 
  3. imaplib 
  4. smtplib 
  5. telnetlib 
these are  network capabilities in their process, scripting we need to import the libraries and you can use the built-in functions. Before using this smtp libraries you need to check the SMTP service enabled on the machine.

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 with mailing address of your supporting WebLogic Administrators (WLA) list by comma separation.
# Script File :
# Author      : Pavan Devarakonda
# Updated on  : 29th April 2010
import smtplib
import time

From = ""
To   =[""]
Date = time.ctime(time.time())

def getServerNames():
   return cmo.getServers()

def mailing(name, stat):
    if stat == 'SHUTDOWN':
        Subject = ' major: '
        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())

    if rCode:
        print 'Fail to send message...'

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

def checkStatus():
        serverNames= getServerNames()
        for name in serverNames:
            print name        
            serverState = serverStatus(name)
            if serverState == "SHUTDOWN": 
                mailing(name, serverState)
            elif serverStat == 'UNKNOWN':
                mailing(name, serverState)
        mailing('AdminServer','Connection Fail')

if __name__== "main":
    redirect('./logs/status.log', 'false')
    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

Keep posting your valuable comments and suggestions on this post.




  1. Its very helpful, Bhavani...
    U really rocking...

  2. Great script 1! Can you Send me how to run this script in windows machine.. ?

    1. Hi Ashok,

      I am also looking for how to run similar script in Windows environment. Could you please help me if u have already achieved it. Thanks in advance.


  3. @Ashok Thanks for your comment.

    On Unix Cronjob/at command, similarly in windows you have Schedulers you can configure them by one of Windows schtasks. You can put the above line of code in a .cmd file it is like shell script in UNIX, invoked as per the scheduled time you assigned in schtasks.
    Hope this link: might help you to automatic calling your script in Windows.

  4. This comment has been removed by the author.

  5. Hi,

    Can you plesae let me know what needs to be updated on lines 7 & 8. I am getting error as below:

    Problem invoking WLST - Traceback (innermost last):
    (no code object) at line 0
    File "D:\", line 2
    import smtplib
    SyntaxError: invalid syntax

  6. Hitesh,

  7. Hitesh,

    There was a earlier post about Errors & Exceptions in Python that makes you trouble in WLST scripting.

    As per your error it could be happen due to indentation problem.

    Read more: WLST errors and Exceptions

  8. Error: get() cannot be applied at this point of path
    Error: get() cannot be applied at this point of path
    Problem invoking WLST - Traceback (innermost last):
    File "/app_data/scripts/monitoring/", line 56, in ?
    File "", line 586, in redirect
    File "", line 552, in raiseWLSTException
    WLSTException: Error occurred while performing redirect : Could not find the file to redirect wlst output to: ./logs/status.log : ./logs/status.log (No such file or directory)
    Use dumpStack() to view the full stacktrace :

  9. Hi Dear,

    we are facing below error, so please can you check.

    D:\UpGrade_WLS\Oracle\Middleware\user_projects\domains\base_domain>java weblogic.WLST

    Initializing WebLogic Scripting Tool (WLST) ...

    Welcome to WebLogic Server Administration Scripting Shell

    Type help() for help on available commands

    Error: get() cannot be applied at this point of path
    Error: get() cannot be applied at this point of path
    Problem invoking WLST - Traceback (innermost last):
    File "D:\UpGrade_WLS\Oracle\Middleware\user_projects\domains\base_domain\", line 56, in ?
    File "", line 682, in redirect
    File "", line 648, in raiseWLSTException
    WLSTException: Error occured while performing redirect : Could not find the file to redirect wlst output to: .\logs\status.log : .\logs\status.log (The system cannot find the path specified)
    Use dumpStack() to view the full stacktrace

  10. BlueHost is ultimately the best website hosting provider for any hosting services you might need.


Please write your comment here

Popular Posts

Oracle WebLogic Administration Course

Oracle WebLogic Administration Course
WebLogic Training