Event to listen when a new device is onboarded

I wanted to listen to the event when a new device is onboarded in Cumulocity in EPL ,how can it be done in EPL ?

Yes you can do that. All new and changed managed objects are sent to Streaming Analytics. So you can do something like this:

monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);
on all ManagedObject() as mo {
  if(mo.isCreate()) {
     // Do something
  }
}

Note that this way, you get all managed objects and not all of them are devices. So you have to decide how you want to determine if something is a device. You could do that by type or checking for the c8y_IsDevice fragment:

on all ManagedObject(type="DEVICE_TYPE") as mo {
  
}

// or

on all ManagedObject() as mo {
  if(mo.isCreate() and mo.params.hasKey("c8y_IsDevice")) {
     // Do something
  }
}


2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.