aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events/AlertEventHandler.java
diff options
context:
space:
mode:
authorKevin Goos <kevingoos@telenet.be>2018-03-16 13:24:17 +0100
committerGitHub <noreply@github.com>2018-03-16 13:24:17 +0100
commit25a36fe2fb8045e455de5e936c286c4db8b40563 (patch)
tree074a212284fdc3e8779ca55f8694f8e92c24e8a7 /src/org/traccar/events/AlertEventHandler.java
parent1216e3bee2abfecedfe1250a9dd5d45c83a2fc02 (diff)
parent38c1ff9bccc1c417a0c2b412271aa7240a3b7db7 (diff)
downloadtrackermap-server-25a36fe2fb8045e455de5e936c286c4db8b40563.tar.gz
trackermap-server-25a36fe2fb8045e455de5e936c286c4db8b40563.tar.bz2
trackermap-server-25a36fe2fb8045e455de5e936c286c4db8b40563.zip
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/events/AlertEventHandler.java')
-rw-r--r--src/org/traccar/events/AlertEventHandler.java24
1 files changed, 20 insertions, 4 deletions
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;
}