0

I'm trying to write a custom CEP rule that creates an operation for an agent to gather the measurement that caused the rule to trigger. The CEP rule looks like this:

insert into CreateOperation
select
  OperationStatus.PENDING as status,
  "5345" as deviceId,
  {
    "c8y_GetData", {
        "name": "get measurement data",
        "measurementID": measurementEvent.measurement.id.value,
        "measurementType": measurementEvent.measurement.type
    }
  } as fragments
from MeasurementCreated measurementEvent
where measurementEvent.measurement.type = "c8y_TemperatureMeasurement";

When I'm using simple strings for the measurementEvent.measurement... fields (e.g. "testString") the rule works. But those lines cause errors when typed like in this example. Changing the ":" to "," like in examples from the documentation makes the rule work but the result is

"name",
"get measurement data",
"measurementID",
"176438",
"measurementType",
"c8y_TemperatureMeasurement"

which doesn't work as key,value pair like "name": "get measurement data" would have. Trying to encapsulate fragments within fragments doesn't seem to work either.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
Lee Kebum
  • 37
  • 3

1 Answers1

1

The fragments parameter in CEL is not an object. It is a list of key/value where the key is a JSONPath. Everything separated by commas (I know it looks weird). The curly braces in Esper actually indicate an array not an object.

Your statement should look like this:

insert into CreateOperation
select
  "5345" as deviceId,
  {
    "c8y_GetData.name", "get measurement data",
    "c8y_GetData.measurementID", measurementEvent.measurement.id.value,
    "c8y_GetData.measurementType", measurementEvent.measurement.type
  } as fragments
from MeasurementCreated measurementEvent
where measurementEvent.measurement.type = "c8y_TemperatureMeasurement";

Also note that I dropped the line with OperationStatus. On POST of an operation you cannot set the status. It will be automatically in status PENDING. Only on PUT you can change it. Keeping the line will result in an error on the API when trying to POST it.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23