Skip to Content
Technical Articles
Author's profile photo Anil Yakkali

CPI Runtime Artifacts Error Alert Process

In my previous blog I had discussed about interface for message monitoring excel report generation but I recently got a question from one of my client as what happens when a deployed interface failed in runtime with any issue? This blog will provide the solution for this behavior.

An Integration flow created for error alert notification process which will monitor runtime artifacts deployed in CPI tenant. In case of an artifact went to error state, this Iflow will send an alert to distribution list or mailing list configured in interface.

The interface zip file can be download from Git repository click here

Design pointers:

Timer is externalized and set to run for every 1 hour, change it as necessary.

OData entity: IntegrationRuntimeArtifacts to get artifact information and status.

Filter = Status equals to ERROR.

In case of error, the iflow ID will be captured using content modifier and pass to HTTP channel.

HTTP channel URL: https://<<CPI Tenant Host>>/api/v1/IntegrationRuntimeArtifacts(‘${property.id}’)/ErrorInformation/$value

Response from HTTP channel is in JSON format. Use groovy script to parse JSON data and capture error information. Message body for alert notification prepared in the same script.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*;

def Message processData(Message message) {
    //Get Body 
    def body = message.getBody(String.class);
    def jsonSlurper = new JsonSlurper()
    def payload = jsonSlurper.parseText(body)
    def error = payload.childInstances.parameter
    
    //Get Properties
    def map = message.getProperties();
    def if_name = map.get("name")
    
    //prepare message body
    body = "<HTML><BODY>"+
                        "<P>Hi Team<BR><BR>"+
                        "An Interface is in Error in CPI. Please find the details below.<BR><BR>"+
                        "<B>IFlow Name: </B>"+ map.get("name") +"<BR>"+ "<B>ErrorMessage: </B>"+error+"<BR><BR>"+"Regards,<BR>"+"SAP CPI Admin <BR><BR>" +
                 "***This is an autogenerated email for Errors in SAP CPI tenant***"+
                       "</P></BODY></HTML>";   
    
    //set message body
    message.setBody(body);
    return message;
}

Message body prepared in HTML format. So used the Body content type as Text/HTML. The sample error notification as below.

Hope this will be useful for consultants and suggestions are welcome. Happy Learning!

Assigned tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sanjaya Kumar Bihari
      Sanjaya Kumar Bihari

      Excellent. This is really helpful

      Author's profile photo Anil Yakkali
      Anil Yakkali
      Blog Post Author

      Thanks Sanjay.

      Author's profile photo Syambabu Allu
      Syambabu Allu

      Hi Anil,

      Good Blog.Thanks for sharing info.

      Thank you,

      Syam

      Author's profile photo Anil Yakkali
      Anil Yakkali
      Blog Post Author

      Thanks Syam.

      Author's profile photo Rajasekhar Reddy Kanchamreddy
      Rajasekhar Reddy Kanchamreddy

      Hi Anil,

       

      Helpful blog.

      Thanks for sharing.

       

      Thank you,

      Rajasekhar K.

      Author's profile photo Anil Yakkali
      Anil Yakkali
      Blog Post Author

      Thanks Rajasekhar.

      Author's profile photo Shoukat Ali
      Shoukat Ali

      Thanks for sharing this helpful blog

      Author's profile photo Chiranjeevi M
      Chiranjeevi M

      Hi Anil,

      I have deployed your artifact , after deployment, if message failed also i am not getting any error email it is stoping in router step itself. Can you please check and help me to resolve this issue. More than 10 messages are failed , but it skipping from routing logic and not picking the error one.

       

      Author's profile photo Pooja Tiwari
      Pooja Tiwari

      Hi Anil,

       

      Thanks for this blog.

      But there might be some issue with Groovy script as there is no Payload which will generate Message Body.

      When I removed it, it was working fine but still need error details specific to failed iflow.

      could you please check and confirm if there is any update in the iflow over the time.

       

      Thanks,

      Pooja