Skip to content

Commit

Permalink
[improve] Added event fingerprint, 2 stage
Browse files Browse the repository at this point in the history
  • Loading branch information
gboddin committed May 16, 2021
1 parent eb16efa commit 4a64728
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion l9helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ func (event *L9Event) UpdateFingerprint() error {
return errors.New("event hashing error")
}
for summaryScanner.Scan() {
// Avoid current date headers
if strings.HasPrefix("date:", strings.ToLower(summaryScanner.Text())) {
continue
}
n, err = hasher.Write(summaryScanner.Bytes())
if err != nil || n != len(summaryScanner.Bytes()) {
return errors.New("event hashing error")
}
summaryLines++
// Stop preHash after 3 lines
if summaryLines == 3 {
preHash = hasher.Sum([]byte{})
}
}
// if preHash empty ( > 3 lines in summary )
if len(preHash) != 16 {
//prehash*2 is fingerprint
preHash = hasher.Sum([]byte{})
preHash = append(preHash, preHash...)
event.EventFingerprint = fmt.Sprintf("%x", preHash)
} else {
//prehash+fullhash is fingerprint
event.EventFingerprint = fmt.Sprintf("%x", hasher.Sum(preHash))
}
event.EventFingerprint = fmt.Sprintf("%x", hasher.Sum(preHash))
return nil
}

Expand Down

0 comments on commit 4a64728

Please sign in to comment.