Added alert dismiss when sensor starts responding
This commit is contained in:
parent
6f6a764f97
commit
b3c2d195b5
2 changed files with 185 additions and 170 deletions
|
|
@ -19,6 +19,7 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -40,6 +41,9 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
YEAR
|
||||
}
|
||||
|
||||
private HashMap<Long, HalAlert> alertMap = new HashMap<>();
|
||||
|
||||
|
||||
public void initiate(ScheduledExecutorService executor){
|
||||
executor.scheduleAtFixedRate(this, 0, UTCTimeUtility.FIVE_MINUTES_IN_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
|
@ -98,7 +102,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
long periodLatestEndTimestamp = new UTCTimePeriod(aggregationStartTime, aggrPeriodLength).getPreviosPeriod().getEndTimestamp();
|
||||
long periodOldestStartTimestamp = new UTCTimePeriod(aggregationStartTime-ageLimitInMs, aggrPeriodLength).getStartTimestamp();
|
||||
|
||||
// Check if the sensor has stopped responding for 15 min or 3 times the data interval and alert the user
|
||||
// Check if the sensor has stopped responding for 15 min or 3 times the data interval if so alert the user
|
||||
if (aggrPeriodLength == AggregationPeriodLength.FIVE_MINUTES) {
|
||||
long dataInterval = sensor.getDeviceConfig().getDataInterval();
|
||||
if (dataInterval < UTCTimeUtility.FIVE_MINUTES_IN_MS)
|
||||
|
|
@ -106,10 +110,21 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
if (dbMaxRawTimestamp > 0 &&
|
||||
dbMaxRawTimestamp + (dataInterval * 3) < System.currentTimeMillis()) {
|
||||
logger.fine("Sensor \"" + sensorId + "\" stopped sending data at: "+ dbMaxRawTimestamp);
|
||||
HalAlertManager.getInstance().addAlert(new HalAlert(AlertLevel.WARNING,
|
||||
|
||||
if (alertMap.containsKey(sensor.getId()))
|
||||
alertMap.get(sensor.getId()).dismiss();
|
||||
|
||||
HalAlert alert = new HalAlert(AlertLevel.WARNING,
|
||||
"Sensor \"" + sensor.getName() + "\" stopped responding",
|
||||
"at <span class=\"timestamp\">"+dbMaxRawTimestamp+"</span>",
|
||||
AlertTTL.DISMISSED));
|
||||
AlertTTL.DISMISSED);
|
||||
alertMap.put(sensor.getId(), alert);
|
||||
HalAlertManager.getInstance().addAlert(alert);
|
||||
}
|
||||
else {
|
||||
// Sensor has responded remove alert
|
||||
if (alertMap.containsKey(sensor.getId()))
|
||||
alertMap.get(sensor.getId()).dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public class HalAlertManager implements HttpPage {
|
|||
case DISMISSED: this.ttl = Integer.MAX_VALUE; break;
|
||||
}
|
||||
}
|
||||
public void dissmiss(){
|
||||
public void dismiss(){
|
||||
ttl = -1;
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ public class HalAlertManager implements HttpPage {
|
|||
if (obj instanceof HalAlert)
|
||||
return level == ((HalAlert) obj).level &&
|
||||
title.equals(((HalAlert) obj).title);
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue