Build Analyzer
This sample demonstrates how complex event processor works for REST requests with Email Broker.
In this example CEP will receive a set of information regarding the build process and notify when build failure occurred in the the project "Complex Event Processor"
from buildfailStatisticsStream[status=='fail' and project=='Complex Event Processor'] insert into outbuildfailStream userID ,timestamp, project,team , userName; Â
Prerequisites
- Apache Ant to build & deploy the Sample & Service, and to run the client. Refer Installation Prerequisites for instructions to install Apache Ant.Â
- cURL to send REST request to CEP. cURL can be downloaded from http://curl.haxx.se/download.html.
- (Optional) Edit the <CEP_HOME>/repository/conf/axis2/axis2_client.xml to use your Email account to send email notifications as mentioned in the "Configuring E-mail Broker" Section.
Here we will publish events using an REST API client and notifications are send using the email client.
Following is the configuration used in this sample.
Above file can be found, in Linux: cd <CEP_HOME>/samples/cep-samples/conf/buckets/BuildFailAnalysisBucket.xml
Configuring Topics for E-Mail Broker
The topic used when using e-mail broker will look like :Â <e-mail id>,<e-mail id>,...,<e-mail id>/<subject>
E.g.        admin@foo.com,user@bar.com/System Notification
In the above configuration we have set a default email address to send email notification. You have to change the email address to view the actual process of this example.
Change the "topic" attribute of the output tag  (<cep:output brokerName="emailBroker" topic="wso2cep.demo@gmail.com/Build Failed">)
- Provide a valid email address(s) by changing the given default mail address.Â
Deploying the Configurations
The steps are as follows :
- Install the WSO2 Complex Event Processor, but do not start the server,  Refer to the Installation and Deploymentfor instructions.
- In a command prompt, switch to the sample directory: <CEP_HOME>/samples/cep-samplesÂ
For example, in Linux: cd <CEP_HOME>/samples/cep-samples - From there, type ant deploy-build,
This will copy the broker-manager-config.xml to <CEP_HOME>/repository/conf directory and the bucket configuration to <CEP_HOME>/repository/deployment/server/cepbuckets directory. - Now start the WSO2 Complex Event Processor. Refer to the Running the Product for instructions.
Defining Stream in CEP engine
Here we are going to define events using the REST API with the help of curl commands.
Following file will post stream definitions  as the body of the POST request.
{ "name":"buildfail_Statistics", "version":"1.3.2", "nickName": "Analytics Statistics Information", "description": "Details of Analytics Statistics", "metaData":[ { "name":"ipAdd","type":"STRING" } ], "payloadData":[ { "name":"userID","type":"STRING" }, { "name":"timestamp","type":"STRING" }, { "name":"userName","type":"STRING" }, { "name":"project","type":"STRING" }, { "name":"status","type":"STRING" }, { "name":"team","type":"STRING" } ] }
- Curl command for defining stream definition.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/streams/ --data @streamdefn1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST
You can see the server logs when defining the stream as shown in the below figure.
Defining events for stream
Now we need to pass events for above mentioned stream using the Rest API.
Following file will post events as the body of the POST request.
[ { "payloadData" : ["abc@org1.com", "120d", "abc", "Complex Event Processor", "fail", "Data Team"] , "metaData" : ["192.168.1.1"] } , { "payloadData" : ["anne@org2.com", "2342d", "anne", "Complex Event Processor", "fail", "Data Team"] , "metaData" : ["192.168.1.1"] } , { "payloadData" : ["sam@org1.com", "12414d", "sam", "Business Activity Monitor", "success", "Data Team"] , "metaData" : ["192.168.1.3"] } , { "payloadData" : ["anne@org1.com", "489d", "anne", "Business Activity Monitor", "success","Data Team"] , "metaData" : ["192.168.1.2"] } , { "payloadData" : ["ann@org3.com", "21324d", "anne", "Stratos", "fail","Platform Team"] , "metaData" : ["192.168.1.3"] } , { "payloadData" : ["paul@org3.com", "423d", "paul", "Application Server", "success","Development Team"] , "metaData" : ["192.168.1.2"] } , { "payloadData" : ["john@org1.com", "3324d", "john", "App Factory", "success","Solutions Team"] , "metaData" : ["192.168.1.1"] } , { "payloadData" : ["abraham@org1.com", "324d", "abraham", "Governance Registry", "success","Integration Team"] , "metaData" : ["192.168.2.1"] } , { "payloadData" : ["mathew@org1.com", "123d", "mathew", "Identity Server", "success","Integration Team"] , "metaData" : ["192.168.3.1"] } , { "payloadData" : ["suho@org1.com", "1432d", "suho", "Gadget Server", "success","Development Team"] , "metaData" : ["192.168.1.1"] } , { "payloadData" : ["tony@org1.com", "165d", "tony", "Enterprise Service Bus", "success","Integration Team"] , "metaData" : ["192.168.2.1"] } , { "payloadData" : ["helm@org1.com", "234d", "helm", "Enterprise Service Bus", "success","Integration Team"] , "metaData" : ["192.168.1.3"] } , { "payloadData" : ["greig@org1.com", "213d", "greig", "Complex Event Processor", "success","Data Team"] , "metaData" : ["192.168.1.2"] } ]
- Curl command to pass events for stream that mentioned in the streamdefn1.json
Â
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/stream/buildfail_Statistics/1.3.2/ --data @events1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST
Observation
Now you can see the email notifications in the mail box that you mentioned in above.
Â
Â
Â
Copyright © WSO2 Inc. 2005-2014