From 9671b4abf936f59b9d04f9d26b301e65fa78753d Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Fri, 8 Aug 2025 13:12:30 -0400 Subject: Log incidents --- internal/api/handlers.go | 10 +++++++--- main.go | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 5a31fa3..2cc2188 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -90,7 +90,7 @@ func CreateLoginHandler(logs *[LogLength]string, n *int, toLogParser chan string var status statusData -func init() { +func InitializeAPI(logs *[LogLength]string, n *int, toLogParser chan string) { // Backfill status // status.overallStatus = overallStatus{ @@ -191,7 +191,7 @@ func init() { runChance(0.5, func() { serviceStatus = StatusDegraded }) - status.incidents = append(status.incidents, incident{ + newIncident := incident{ Id: fmt.Sprintf("%d", incidentId), Title: allIncidentTitles[i], Description: allIncidentDescriptions[i], @@ -199,8 +199,12 @@ func init() { Severity: severity, StartTime: time.Now().UTC(), AffectedServices: []string{}, - }) + } + status.incidents = append(status.incidents, newIncident) incidentId++ + + jsonData, _ := json.Marshal(newIncident) + addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"incidentEvent": %s}`, string(jsonData))) }) status.overallStatus.ActiveIncidents = len(status.incidents) } diff --git a/main.go b/main.go index cc2b3d7..2ae6e3b 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ func main() { go parser(toLogParser, &king) + api.InitializeAPI(&logs, &n, toLogParser) + http.HandleFunc("/", api.CreateFilesHandler(&logs, &n, toLogParser)) http.HandleFunc("/logs", api.CreateGetLogs(&logs)) http.HandleFunc("/api/v1/logs", api.CreateGetLogs(&logs)) -- cgit