Tuesday, April 23, 2013

Deleting Records From Failed Event Manager In Websphere Application Server [ WESB & WPS ]

The WebSphere application server stores all exception's in failed event manager. If FEM is full, then clearing FEM Records through Admin Console is not possible.

In this situation, we have two options to remove all FEM.

Option 1:

Delete FEM records from WPSDB database . Run the below query in order.

delete from FAILEDEVENTS;

Option 2:

Delete FEM by jython scripts.

The script must be saved in a file and can be run on a single server profile as well as a
clustered environment (run on deployment manager) using the following command:

1.  cd Deployment manager  [ or ] Profile Name/bin 
2.   Run wsadmin.(bat|sh) -lang jython -f jythonScriptName -user wpsAdminUserName -password wpsAdminPassword

Ex: wsadmin.bat -lang jython -f /opt/Websphere/AppServer/scripts/FEMScript.py -user admin -password admin

# lookup the failed event manager
objstr = AdminControl.completeObjectName('WebSphere:*,type=FailedEventManager')
obj = AdminControl.makeObjectName(objstr)

# count the overall number of failed events
fecount = AdminControl.invoke(objstr,"getFailedEventCount")
print "Failed event number before discarding: ", fecount

delnum = 100
fecount = int(fecount)

while (fecount > 0):
    if fecount < 100:
        delnum = fecount
        fecount = 0
        delnum = 100
        fecount = fecount - 100
    # get 100 failed events
    msglist = AdminControl.invoke_jmx(obj,'getAllFailedEvents',[delnum],['int'])

    # discard 100 events in single batch run
    print "Discarding ", delnum, " failed events"
    AdminControl.invoke_jmx(obj,'discardFailedEvents', [msglist],['java.util.List'])

# count the overall number of failed events
fecount2 = AdminControl.invoke(objstr,"getFailedEventCount")
print "Failed event number after discarding: ", fecount2