Search code examples
complex-event-processingcumulocity

CEP List as single items (iterate over managed obejects)


in CEP, I can get managed objects as a list, for example with the function "...ManagedObjectByType". After getting the list, I use the AllOf function to filter the list. Now, I would like to put every single Mangaged Object from the list into a new stream ({A,B,C} -> A,B,C), so they are seperated from each other in order to generate for example alarms in the next stage. Unfortunately, I have no clue how I can produce single events (Managed Objects) from a List. Can someone help?

Best, Nico


Solution

  • You can do something like this:

    create schema Device as ManagedObject;
    
    create schema CollectedDevices(
        devices List
    );
    
    create schema SingleDevice(
        device Device
    );
    
    insert into CollectedDevices
    select
        findAllManagedObjectByFragmentType("c8y_IsDevice") as devices
    from pattern[timer:interval(10 seconds)];
    
    insert into SingleDevice
    select
        singleDevice as device
    from 
        CollectedDevices as devices unidirectional,
        CollectedDevices[devices@type(Device)] as singleDevice;
    

    The last statement will then be triggered for each element int the list.

    You can find the esper documentation for the joins here: http://esper.espertech.com/release-5.4.0/esper-reference/html/epl_clauses.html#epl-join