Using alarms
The com.apama.cumulocity.Alarm is sent on an alarm from a device. This event is sent to the com.apama.cumulocity.Alarm.SUBSCRIBE_CHANNEL (same as cumulocity.alarms) channel. This event contains the identifier of the source, a timestamp (same form as currentTime), message text, and optional parameters.
Example of an alarm:
com.apama.cumulocity.Alarm("44578840","c8y_UnavailabilityAlarm","44578839",
1529496204.346,"No data received from device within required interval",
Alarm.STATUS_ACTIVE,Alarm.SEVERITY_MAJOR,1,{"creationTime":any(float,1529496204.067)})
Example
The following is a simple example of how to receive, update, create and send alarms:
// Subscribe to receive all the alarms published from Cumulocity IoT
monitor.subscribe(Alarm.SUBSCRIBE_CHANNEL);
// Consume all the alarms from Cumulocity IoT
on all Alarm() as alarm {
log alarm.toString() at INFO;
// Example for updating an alarm
// Set alarm severity to MAJOR
alarm.severity := Alarm.SEVERITY_MAJOR;
send alarm to Alarm.SEND_CHANNEL;
}
// Create a new alarm
Alarm alarm := new Alarm;
alarm.source := "<MANAGED_OBJECT_ID>";
alarm.type := "TestAlarm";
alarm.severity := Alarm.SEVERITY_MINOR;
alarm.status := Alarm.STATUS_ACTIVE;
alarm.time := currentTime;
alarm.text := "This is a sample alarm";
send alarm to Alarm.SEND_CHANNEL;