From 0bca2416806b3e5cfa246746b0cf2a5b9b9f617e Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky Date: Tue, 2 Apr 2024 16:03:51 -0500 Subject: [PATCH] Mark calendar webhook as errored so that it doesn't get stuck in pending and keeps logging warnings. --- server/fleet/calendar_events.go | 1 + server/service/osquery.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/fleet/calendar_events.go b/server/fleet/calendar_events.go index 3152ee65b..4574d2372 100644 --- a/server/fleet/calendar_events.go +++ b/server/fleet/calendar_events.go @@ -18,6 +18,7 @@ const ( CalendarWebhookStatusNone CalendarWebhookStatus = iota CalendarWebhookStatusPending CalendarWebhookStatusSent + CalendarWebhookStatusError ) type HostCalendarEvent struct { diff --git a/server/service/osquery.go b/server/service/osquery.go index 379afafd6..31e4e33d2 100644 --- a/server/service/osquery.go +++ b/server/service/osquery.go @@ -1133,16 +1133,22 @@ func processCalendarPolicies( now := time.Now() if now.Before(calendarEvent.StartTime) { level.Warn(logger).Log("msg", "results came too early", "now", now, "start_time", calendarEvent.StartTime) + if err = ds.UpdateHostCalendarWebhookStatus(context.Background(), host.ID, fleet.CalendarWebhookStatusError); err != nil { + level.Error(logger).Log("msg", "mark webhook as errored early", "err", err) + } return nil } // // TODO(lucas): Discuss. // - const allowedTimeBeforeEndTime = 5 * time.Minute // up to 5 minutes before the end_time + const allowedTimeRelativeToEndTime = 5 * time.Minute // up to 5 minutes after the end_time to allow for short (0-time) event times - if now.After(calendarEvent.EndTime.Add(-allowedTimeBeforeEndTime)) { + if now.After(calendarEvent.EndTime.Add(allowedTimeRelativeToEndTime)) { level.Warn(logger).Log("msg", "results came too late", "now", now, "end_time", calendarEvent.EndTime) + if err = ds.UpdateHostCalendarWebhookStatus(context.Background(), host.ID, fleet.CalendarWebhookStatusError); err != nil { + level.Error(logger).Log("msg", "mark webhook as errored late", "err", err) + } return nil }