Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROuting entire Json Contents based on json field

I have the following JSON:

{
    "From": "stuart",
    "Payload": {
        "Alert": "Critical",
        "Recipient": "Joe"
    }
}

I want to route this based on if the field in Alert is 'Critical' or not.

I've tried RouteOnAttribute processor and also an EvaluateJson processor. Neither are working.

For RouteOnAttribute I've tried

Alerted: ${Payload:jsonPath('$.Alert'):equals('Critical')}

Then I have a relationship based on Alerted but nothing ever goes into my RouteOnAttribute processor, the queue just sits there till it fills to 10,000.

I need the full JSON to be routed, I can't lose information in the routing.

enter image description here

like image 973
Stuart Avatar asked Dec 23 '22 05:12

Stuart


1 Answers

The issue is with jsonPath function works on flowfile attributes but you are not having Payload attribute associated with the flowfile.

How to add attribute to the flowfile?

After generateflowfile processor use EvaluateJsonPath processor with destination as flowfile-attribute,

Add new property

payload.alert as $.Payload.Alert

enter image description here Then use routeonattribute processor add new property as

Alerted

${payload.alert:equals('Critical')}

Flow:

1.GenerateFlowFile
2.EvaluateJsonPath //extract the value and keep as attribute to the flowfile
3.RouteOnAttribute //check the attribute value
like image 102
notNull Avatar answered Jan 08 '23 23:01

notNull