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 javax.script.ScriptException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrew Shvayka
|
* @author Andrew Shvayka
|
||||||
@ -131,6 +132,16 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
|
|||||||
Alarm existing = null;
|
Alarm existing = null;
|
||||||
if (isActiveAlarm) {
|
if (isActiveAlarm) {
|
||||||
Alarm alarm = buildAlarm(ctx, msg);
|
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);
|
existing = ctx.createOrUpdateAlarm(alarm);
|
||||||
if (existing.getStartTs() == alarm.getStartTs()) {
|
if (existing.getStartTs() == alarm.getStartTs()) {
|
||||||
log.debug("[{}][{}] New Active Alarm detected", ctx.getRuleId(), existing.getId());
|
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());
|
log.debug("[{}][{}] Existing Active Alarm detected", ctx.getRuleId(), existing.getId());
|
||||||
md.put(IS_EXISTING_ALARM, Boolean.TRUE);
|
md.put(IS_EXISTING_ALARM, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
} else if (isClearedAlarm) {
|
} else {
|
||||||
String alarmType = VelocityUtils.merge(alarmTypeTemplate, context);
|
String alarmType = VelocityUtils.merge(alarmTypeTemplate, context);
|
||||||
Optional<Alarm> alarm = ctx.findLatestAlarm(ctx.getDeviceMetaData().getDeviceId(), alarmType);
|
Optional<Alarm> alarm = ctx.findLatestAlarm(ctx.getDeviceMetaData().getDeviceId(), alarmType);
|
||||||
if (alarm.isPresent()) {
|
if (alarm.isPresent()) {
|
||||||
|
|||||||
@ -32,6 +32,7 @@ public class AlarmProcessorConfiguration {
|
|||||||
private String alarmSeverity;
|
private String alarmSeverity;
|
||||||
private String alarmStatus;
|
private String alarmStatus;
|
||||||
private boolean alarmPropagateFlag;
|
private boolean alarmPropagateFlag;
|
||||||
|
private boolean newAlarmFlag;
|
||||||
|
|
||||||
private String alarmDetailsTemplate;
|
private String alarmDetailsTemplate;
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
"newAlarmFlag": {
|
||||||
|
"title": "New Alarm on each event",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"alarmDetailsTemplate": {
|
"alarmDetailsTemplate": {
|
||||||
"title": "Alarm details (JSON)",
|
"title": "Alarm details (JSON)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -106,6 +111,7 @@
|
|||||||
},
|
},
|
||||||
"alarmTypeTemplate",
|
"alarmTypeTemplate",
|
||||||
"alarmPropagateFlag",
|
"alarmPropagateFlag",
|
||||||
|
"newAlarmFlag",
|
||||||
{
|
{
|
||||||
"key": "alarmDetailsTemplate",
|
"key": "alarmDetailsTemplate",
|
||||||
"type": "textarea",
|
"type": "textarea",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user