diff --git a/node/pkg/logscribe/logprocessor/logprocessor.go b/node/pkg/logscribe/logprocessor/logprocessor.go index b15c09159..f75c6ed9c 100644 --- a/node/pkg/logscribe/logprocessor/logprocessor.go +++ b/node/pkg/logscribe/logprocessor/logprocessor.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "bisonai.com/miko/node/pkg/alert" "bisonai.com/miko/node/pkg/db" errorsentinel "bisonai.com/miko/node/pkg/error" "bisonai.com/miko/node/pkg/secrets" @@ -299,12 +300,17 @@ func (p *LogProcessor) StartProcessingCronJob(ctx context.Context) error { log.Error().Err(err).Msg("Failed to get services") return } + var slackMessage strings.Builder for _, service := range services { processedLogs := ProcessLogs(ctx, service.Service) if len(processedLogs) > 0 { + addLogsToSlackMessage(&slackMessage, processedLogs) p.CreateGithubIssue(ctx, processedLogs, service.Service) } } + if slackMessage.Len() > 0 { + alert.SlackAlert("Logscribe report:\n" + slackMessage.String()) + } }) if err != nil { log.Error().Err(err).Msg("Failed to start processing cron job") @@ -315,3 +321,14 @@ func (p *LogProcessor) StartProcessingCronJob(ctx context.Context) error { p.cron.Start() return nil } + +func addLogsToSlackMessage(slackMessage *strings.Builder, processedLogs []LogInsertModelWithCount) { + for _, entry := range processedLogs { + entryJson, err := json.MarshalIndent(entry, "", " ") + if err != nil { + log.Warn().Err(err).Msg("Failed to marshal log") + continue + } + slackMessage.WriteString(string(entryJson) + "\n") + } +}