Skip to content

Commit

Permalink
Option to ignore duplicate alarms
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Mar 13, 2018
1 parent bb49f1e commit 2a30c9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<entry key='logger.file'>./logs/tracker-server.log</entry>

<entry key='event.enable'>true</entry>
<entry key='event.ignoreDuplicateAlerts'>true</entry>
<entry key='processing.computedAttributes.enable'>true</entry>

<entry key='media.path'>./media</entry>
Expand Down
24 changes: 20 additions & 4 deletions src/org/traccar/events/AlertEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Anton Tananaev ([email protected])
* Copyright 2016 - 2018 Anton Tananaev ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,18 +19,34 @@
import java.util.Map;

import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;

public class AlertEventHandler extends BaseEventHandler {

private final boolean ignoreDuplicateAlerts;

public AlertEventHandler() {
ignoreDuplicateAlerts = Context.getConfig().getBoolean("event.ignoreDuplicateAlerts");
}

@Override
protected Map<Event, Position> analyzePosition(Position position) {
Object alarm = position.getAttributes().get(Position.KEY_ALARM);
if (alarm != null) {
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
event.set(Position.KEY_ALARM, (String) alarm);
return Collections.singletonMap(event, position);
boolean ignoreAlert = false;
if (ignoreDuplicateAlerts) {
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) {
ignoreAlert = true;
}
}
if (!ignoreAlert) {
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
event.set(Position.KEY_ALARM, (String) alarm);
return Collections.singletonMap(event, position);
}
}
return null;
}
Expand Down

0 comments on commit 2a30c9d

Please sign in to comment.