diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-03-14 05:27:23 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-03-14 05:27:23 +1300 |
commit | 2a30c9de983223a3af1070543975165ceb0710f9 (patch) | |
tree | dcc6b4219e14ab8b71d458adb6cd6547c2f50238 | |
parent | bb49f1e2c38e23860e87e1801edc456f30165d5f (diff) | |
download | traccar-server-2a30c9de983223a3af1070543975165ceb0710f9.tar.gz traccar-server-2a30c9de983223a3af1070543975165ceb0710f9.tar.bz2 traccar-server-2a30c9de983223a3af1070543975165ceb0710f9.zip |
Option to ignore duplicate alarms
-rw-r--r-- | setup/default.xml | 1 | ||||
-rw-r--r-- | src/org/traccar/events/AlertEventHandler.java | 24 |
2 files changed, 21 insertions, 4 deletions
diff --git a/setup/default.xml b/setup/default.xml index 81a3cd128..8701ddc4c 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -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> diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java index 003ccb662..7db371c70 100644 --- a/src/org/traccar/events/AlertEventHandler.java +++ b/src/org/traccar/events/AlertEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,34 @@ import java.util.Collections; 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; } |