Saturday, April 18, 2015

Searching Oracle Service Bus Pipeline Alert contents

There are several ways monitor messages passing through the Service Bus. Using pipeline alerts is one of them. Pipeline alerts can be searched in the Enterprise Manager based on several parameters such as summary or when they have occurred. Usually an important part of the message payload is saved in the content of the alert. This content can not be searched from the Enterprise Manager. In this post I will provide an example for logging Service Bus request and response messages using pipeline alerts and a means to search alert contents for a specific occurrence. The example provided has been created in SOA Suite 12.1.3 but the script also works in SOA Suite

Service Bus Pipeline Alerts

The Oracle Service Bus provides several monitoring mechanisms. These can be tweaked in the Enterprise Manager.

In this example I'm going to use Pipeline Alerts. Where you can find them in the Enterprise Manager has been described on: I've created a small sample process called HelloWorld. This process can be called with a name and returns 'Hello name' as a response. The process itself has a single AlertDestination and has two pipeline alerts. One for the request and one for the response. These pipeline alerts write the content of the header en body variables to the content field of the alert.

When I call this service with 'Maarten' and with 'John', I can see the created pipeline alerts in the Enterprise Manager.

Next I want to find the requests done by 'Maarten'. I'm not interested in John. I can search for the summary, but this only indicates the location in the pipeline where the alert occurred. I want to search the contents or description as it is called in the Enterprise Manager. Since clicking on every entry is not very time efficient, I want to use a script for that.

Search for pipeline alerts using WLST

At first I thought I could use a method like on: in combination with the location of the file-store which is used for the alerts; servers/[servername]/data/store/diagnostics. The dump however of this filestore was not readable enough for me and this method required access to the filesystem of the applicationserver. I decided to walk the WLST path.

The below WLST lists the pipeline alerts where 'Maarten' is in the contents / description. I used the following script. The script works on Service Bus and 12.1.3. You should of course replace the obvious variables like username, password, url, servername and searchfor.

 import datetime  
 #Conditionally import wlstModule only when script is executed with jython  
 if __name__ == '__main__':  
   from wlstModule import *#@UnusedWildImport  
 print 'starting the script ....'  
 username = 'weblogic'  
 password = 'Welcome01'  
 def get_children():  
   return ls(returnMap='true')  
 for server in servers:  
   #print server  
   if server == servername:  
     end = cmo.getLatestAvailableTimestamp()  
     start = cmo.getEarliestAvailableTimestamp()  
     cursorname = cmo.openCursor(start,end,"")  
     if cmo.hasMoreData(cursorname):  
       for record in records:  
                     #print record  
                     if searchfor in record[9]:  
                          print datetime.datetime.fromtimestamp(record[1]/1000).strftime('%Y-%m-%d %H:%M:%S')+' : '+record[3]+' : '+record[13]  

The output in my case looks like:

 2015-04-18 12:59:21 : Pipeline$HelloWorld$HelloWorldPipeline : HelloWorldPipelineRequest  
 2015-04-18 12:59:21 : Pipeline$HelloWorld$HelloWorldPipeline : HelloWorldPipelineResponse  
 2015-04-18 13:18:39 : Pipeline$HelloWorld$HelloWorldPipeline : HelloWorldPipelineRequest  
 2015-04-18 13:18:39 : Pipeline$HelloWorld$HelloWorldPipeline : HelloWorldPipelineResponse  

Now you can extend the script to provide more information or lookup the relevant requests in the Enterprise Manager.