mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 23:27:58 +02:00
Add system activity tracking and event store (#636)
This PR adds system activity tracking. The management service records events like add/remove peer, group, rule, route, etc. The activity events are stored in the SQLite event store and can be queried by the HTTP API.
This commit is contained in:
33
management/server/event.go
Normal file
33
management/server/event.go
Normal file
@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/netbirdio/netbird/management/server/activity"
|
||||
)
|
||||
|
||||
// GetEvents returns a list of activity events of an account
|
||||
func (am *DefaultAccountManager) GetEvents(accountID, userID string) ([]*activity.Event, error) {
|
||||
events, err := am.eventStore.Get(accountID, 0, 10000, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// this is a workaround for duplicate activity.UserJoined events that might occur when a user redeems invite.
|
||||
// we will need to find a better way to handle this.
|
||||
filtered := make([]*activity.Event, 0)
|
||||
dups := make(map[string]struct{})
|
||||
for _, event := range events {
|
||||
if event.Activity == activity.UserJoined {
|
||||
key := event.TargetID + event.InitiatorID + event.AccountID + fmt.Sprint(event.Activity)
|
||||
_, duplicate := dups[key]
|
||||
if duplicate {
|
||||
continue
|
||||
} else {
|
||||
dups[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, event)
|
||||
}
|
||||
|
||||
return filtered, nil
|
||||
}
|
Reference in New Issue
Block a user