diff --git a/waflog/read.go b/waflog/read.go index 23633cbd..617187cc 100644 --- a/waflog/read.go +++ b/waflog/read.go @@ -28,16 +28,23 @@ func (ll *FTWLogLines) TriggeredRules() []uint { ruleIds := []uint{} for _, line := range lines { log.Trace().Msgf("ftw/waflog: Looking for any rule in %s", line) - match := regex.FindSubmatch(line) + match := regex.FindAllSubmatch(line, -1) if match != nil { log.Trace().Msgf("ftw/waflog: Found %s at %s", regex.String(), line) - submatch := string(match[1]) - ruleId, err := strconv.ParseUint(submatch, 10, 0) - if err != nil { - log.Error().Msgf("Failed to parse uint from %s", submatch) - continue + for _, nextMatch := range match { + for _, submatchBytes := range nextMatch { + if len(submatchBytes) == 0 { + continue + } + submatch := string(submatchBytes) + ruleId, err := strconv.ParseUint(submatch, 10, 0) + if err != nil { + log.Error().Caller().Msgf("Failed to parse uint from %s", submatch) + continue + } + ruleIds = append(ruleIds, uint(ruleId)) + } } - ruleIds = append(ruleIds, uint(ruleId)) } } ll.triggeredRules = ruleIds diff --git a/waflog/read_test.go b/waflog/read_test.go index 5b8ed3b8..aec9f726 100644 --- a/waflog/read_test.go +++ b/waflog/read_test.go @@ -361,3 +361,36 @@ func (s *readTestSuite) TestFTWLogLines_CheckForLogMarkerIn404() { foundMarker := ll.CheckLogForMarker(stageID, 100) s.Equal(strings.ToLower(markerLine), strings.ToLower(string(foundMarker))) } + +func (s *readTestSuite) TestFindAllIdsInLogs() { + cfg, err := config.NewConfigFromEnv() + s.Require().NoError(err) + s.NotNil(cfg) + + stageID := "dead-beaf-deadbeef-deadbeef-dead" + markerLine := "X-cRs-TeSt: " + stageID + logLines := fmt.Sprint("\n", markerLine, + `[id "1"] something else [id "2"]`, + `"id": 3, something else {"id":4}`+"\n", + "\n", markerLine) + filename, err := utils.CreateTempFileWithContent(logLines, "test-errorlog-") + s.Require().NoError(err) + + cfg.LogFile = filename + log, err := os.Open(filename) + s.Require().NoError(err) + + ll := &FTWLogLines{ + logFile: log, + LogMarkerHeaderName: bytes.ToLower([]byte(cfg.LogMarkerHeaderName)), + } + ll.WithStartMarker([]byte(markerLine)) + ll.WithEndMarker([]byte(markerLine)) + + foundRuleIds := ll.TriggeredRules() + s.Len(foundRuleIds, 4) + s.Contains(foundRuleIds, uint(1)) + s.Contains(foundRuleIds, uint(2)) + s.Contains(foundRuleIds, uint(3)) + s.Contains(foundRuleIds, uint(4)) +}