Hello all,
I have a 64 bit integer where each bit represent an alarm (1 means active, while 0 means inactive). The problem is with my current EPL if this integer is more than 0 the alarm + email is triggered every time. As you can imagine, in matter of minutes you can receive hundreds of emails.
So, my question is how would you write the EPL that triggers the Alarms only when the bit/s changes their status from 0 to 1 and vice versa?
I know I could write a logic that checks if the current bits that are on are still the same or changed but I am asking this in case there is a better way of doing it.
My current code is the following:
action onload() {
monitor.subscribe(Measurement.SUBSCRIBE_CHANNEL);
on all Measurement(type=MEASUREMENT_TYPE) as measurement
{
// Get the message content
float value := measurement.measurements.getOrDefault(MEASUREMENT_TYPE).getOrDefault("Alarms").value;
integer messageData := (value.toString()).toInteger();
// Check if alarms are active (0 is equal to no active alarm)
if (messageData > 0 ) {
// Loop trough every bit of the message
// trigger alarm if a bit is 1
integer i := 0;
while i < MESSAGE_BIT_LENGTH {
integer bit := (1 and (messageData >> i));
if bit = 1 {
log "ALARM: " + i.toString();
TriggerCloudAlarmMessage(i, measurement, INDEX_ERROR_FOUND);
}
i := i + 1;
}
TriggerEmailAlarmMessage(measurement.source, response.managedObject.name,INDEX_ERROR_FOUND);
}
}
}