jsonwso2siddhiwso2-streaming-integrator

Is it posible to remove enclosing element using json mapping in siddhi?


I got a working code of siddhi and i want to know if its posible to output the events using a json format without an enclosing element.

I tried it putting a null enclosing.element and $. , but none of them seems to work.

@sink(type = 'file', file.uri = "/var/log/cert/output/{{name}}", 
    @map(type = 'json', fail.on.missing.attibute = "false",enclosing.element="$."))
define stream AlertStream (timestamp long, name string, ipsrc string, ipdst string, evento string, tipoAmenaza string, eventCategory string, severity string, network string, threatId string, eventTech string, eventArea string, urlOriginal string, eventID string, tag string);

i got the following result

{"event":{"timestamp":1562232334157,"name":"client_name","ipsrc":"192.168.1.1","ipdst":"192.168.1.2","evento":"threat","tipoAmenaza":"file","eventCategory":"alert","severity":"medium","network":"192.168.0.0-192.168.255.255","threatId":"spyware","eventTech":"firewall","eventArea":"fwaas","urlOriginal":"undefined","eventID":"901e1155-5407-48ce-bddb-c7469fcf5c48","tag":"[Spyware-fwaas]"}}

and the expect output is

{"timestamp":1562232334157,"name":"client_name","ipsrc":"192.168.1.1","ipdst":"192.168.1.2","evento":"threat","tipoAmenaza":"file","eventCategory":"alert","severity":"medium","network":"192.168.0.0-192.168.255.255","threatId":"spyware","eventTech":"firewall","eventArea":"fwaas","urlOriginal":"undefined","eventID":"901e1155-5407-48ce-bddb-c7469fcf5c48","tag":"[Spyware-fwaas]"}

Solution

  • You have to use custom mapping facilitated with @payload annotation. For more information please refer https://siddhi-io.github.io/siddhi-map-json/api/5.0.2/#json-sink-mapper

    @sink(type='inMemory', topic='{{symbol}}', 
         @map(type='json', 
             @payload( """{"StockData":{"Symbol":"{{symbol}}","Price":{{price}}}""")))
    define stream BarStream (symbol string, price float, volume long);