Skip to content

Commit

Permalink
Merge pull request #136 from thalesgroup-cert/v2
Browse files Browse the repository at this point in the history
Fix false positives in domain monitoring module
  • Loading branch information
ygalnezri authored Jun 27, 2024
2 parents 0793476 + bea8854 commit f6c0a4b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Watcher/Watcher/site_monitoring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,14 @@ def create_alert(alert, site, new_ip, new_ip_second, score):
if site.monitored and alert != 0:
alert_data = alert_types[alert]

# Get current time
now = datetime.now()
# Retrieve the two latest alerts for this site within the last hour
one_hour_ago = datetime.now() - timedelta(hours=1)
last_two_alerts = Alert.objects.filter(site=site, created_at__gte=one_hour_ago).order_by('-created_at')[:2]

# Retrieve the two latest alerts for this site
last_two_alerts = Alert.objects.filter(site=site).order_by('-created_at')[:2]

# Check if the new alert is identical to the last two alerts created at the exact same time
# Check if the information of the new alert is identical to the last two alerts
for previous_alert in last_two_alerts:
if all(getattr(previous_alert, key) == value for key, value in alert_data.items()) and previous_alert.created_at == now:
if all(getattr(previous_alert, key) == value for key, value in alert_data.items()):
# If the information is identical to one of the last two alerts, do not create a new alert
return

# Create a new alert
Expand Down

0 comments on commit f6c0a4b

Please sign in to comment.