Merge pull request #302 from thingsboard/feature/rpc-rule
Alarm Processor improvement to trigger alarm on each incoming message
This commit is contained in:
commit
5274de80a9
@ -41,6 +41,7 @@ import javax.script.Bindings;
|
||||
import javax.script.ScriptException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @author Andrew Shvayka
|
||||
@ -131,6 +132,16 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
|
||||
Alarm existing = null;
|
||||
if (isActiveAlarm) {
|
||||
Alarm alarm = buildAlarm(ctx, msg);
|
||||
if (configuration.isNewAlarmFlag()) {
|
||||
Optional<Alarm> oldAlarmOpt = ctx.findLatestAlarm(alarm.getOriginator(), alarm.getType());
|
||||
if (oldAlarmOpt.isPresent() && !oldAlarmOpt.get().getStatus().isCleared()) {
|
||||
try {
|
||||
ctx.clearAlarm(oldAlarmOpt.get().getId(), oldAlarmOpt.get().getEndTs()).get();
|
||||
} catch (Exception e) {
|
||||
throw new RuleException("Failed to clear old alarm", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
existing = ctx.createOrUpdateAlarm(alarm);
|
||||
if (existing.getStartTs() == alarm.getStartTs()) {
|
||||
log.debug("[{}][{}] New Active Alarm detected", ctx.getRuleId(), existing.getId());
|
||||
@ -140,7 +151,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
|
||||
log.debug("[{}][{}] Existing Active Alarm detected", ctx.getRuleId(), existing.getId());
|
||||
md.put(IS_EXISTING_ALARM, Boolean.TRUE);
|
||||
}
|
||||
} else if (isClearedAlarm) {
|
||||
} else {
|
||||
String alarmType = VelocityUtils.merge(alarmTypeTemplate, context);
|
||||
Optional<Alarm> alarm = ctx.findLatestAlarm(ctx.getDeviceMetaData().getDeviceId(), alarmType);
|
||||
if (alarm.isPresent()) {
|
||||
|
||||
@ -32,6 +32,7 @@ public class AlarmProcessorConfiguration {
|
||||
private String alarmSeverity;
|
||||
private String alarmStatus;
|
||||
private boolean alarmPropagateFlag;
|
||||
private boolean newAlarmFlag;
|
||||
|
||||
private String alarmDetailsTemplate;
|
||||
|
||||
|
||||
@ -30,6 +30,11 @@
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"newAlarmFlag": {
|
||||
"title": "New Alarm on each event",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"alarmDetailsTemplate": {
|
||||
"title": "Alarm details (JSON)",
|
||||
"type": "string",
|
||||
@ -106,6 +111,7 @@
|
||||
},
|
||||
"alarmTypeTemplate",
|
||||
"alarmPropagateFlag",
|
||||
"newAlarmFlag",
|
||||
{
|
||||
"key": "alarmDetailsTemplate",
|
||||
"type": "textarea",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user