Trigger an Alarm only once the status changes

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);
			}
		}
	}

You can use bitwise operations (ex: xor) on integer type (see integer) and identify which bits changed.

To keep track of the bits changed I made an array where I keep track of them, do you have a better idea?

  • store previous value for the source to a dictionary
  • xor previous value and current value to get the bits that changed
  • and the outcome of the xor and the current value to identify alarms that are active. or use not current value and outcome of xor to identify alarms that are no longer active
  • use the bitwise shift operations to identify the bits that are set and raise appropriate trigger

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