mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Fix some bugginess with how expired alerts and alert max_duration were handled. Closes #34
This commit is contained in:
@@ -187,6 +187,8 @@ class WebServer:
|
||||
alerts = []
|
||||
for k in alert_ids:
|
||||
alerts.append(self.alerts.get(k))
|
||||
# We never want alerts that seem to be in the past
|
||||
alerts = list(filter(lambda alert: not alert.expired(), alerts))
|
||||
alerts = sorted(alerts, key=lambda alert: (alert.start_time if alert and alert.start_time else 0))
|
||||
for k in query.keys():
|
||||
match k:
|
||||
@@ -195,8 +197,10 @@ class WebServer:
|
||||
alerts = [a for a in alerts if a.received_time > since]
|
||||
case "max_duration":
|
||||
max_duration = int(query.get(k))
|
||||
alerts = [a for a in alerts if (a.end_time and a.end_time - a.start_time <= max_duration) or (
|
||||
not a.end_time and datetime.now(pytz.UTC).timestamp() - a.start_time <= max_duration)]
|
||||
# Check the duration if end_time is provided. If end_time is not provided, assume the activation is
|
||||
# "short", i.e. it always passes this check.
|
||||
alerts = [a for a in alerts if (a.end_time and a.end_time - a.start_time <= max_duration) or
|
||||
not a.end_time]
|
||||
case "source":
|
||||
sources = query.get(k).split(",")
|
||||
alerts = [a for a in alerts if a.source in sources]
|
||||
|
||||
Reference in New Issue
Block a user