Skip to content

Commit

Permalink
Merge pull request #166 from 0x2142/fix-topscore-in-notifs
Browse files Browse the repository at this point in the history
fix issue with score percent in notifs being 0%
  • Loading branch information
0x2142 authored Oct 31, 2024
2 parents 34e92d2 + 909c529 commit 76fc3c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 6 additions & 0 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (

// processEvent handles preparing event for alerting
func processEvent(event models.Event) {
// For events collected via API, top-level top_score value is no longer used
// So need to replace it with data.top_score value
if event.TopScore == 0 {
event.TopScore = event.Data.TopScore
}

// Convert to human-readable timestamp
eventTime := time.Unix(int64(event.StartTime), 0)
log.Info().
Expand Down
6 changes: 0 additions & 6 deletions events/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ func checkFilters(event models.Event) bool {
return false
}

// For Web API query, top-level top_score value is no longer used
// So need to replace it with data.top_score value
if event.TopScore == 0 {
event.TopScore = event.Data.TopScore
}

// Check label score
if !aboveMinScore(event.ID, event.TopScore) {
return false
Expand Down
13 changes: 10 additions & 3 deletions events/reviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ func processReview(review models.Review) {
var detection models.Event
json.Unmarshal(response, &detection)

// Store first detection for this review, alerts will be based on this event's data
if firstDetection.ID == "" {
firstDetection = detection
// For events collected via API, top-level top_score value is no longer used
// So need to replace it with data.top_score value
if detection.TopScore == 0 {
detection.TopScore = detection.Data.TopScore
}

// Check that event passes configured filters
detection.CurrentZones = detection.Zones
if !checkFilters(detection) {
reviewFiltered = true
break
}

// Store first detection for this review, alerts will be based on this event's data
if firstDetection.ID == "" {
firstDetection = detection
}
}
// If any detection would be filtered, skip notifying on this review
if reviewFiltered {
Expand Down

0 comments on commit 76fc3c3

Please sign in to comment.