mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-04 08:06:37 +00:00
@@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -11,6 +12,11 @@ import (
|
|||||||
"github.com/netbirdio/netbird/management/server/status"
|
"github.com/netbirdio/netbird/management/server/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isEnabled() bool {
|
||||||
|
response := os.Getenv("NB_EVENT_ACTIVITY_LOG_ENABLED")
|
||||||
|
return response == "" || response == "true"
|
||||||
|
}
|
||||||
|
|
||||||
// GetEvents returns a list of activity events of an account
|
// GetEvents returns a list of activity events of an account
|
||||||
func (am *DefaultAccountManager) GetEvents(ctx context.Context, accountID, userID string) ([]*activity.Event, error) {
|
func (am *DefaultAccountManager) GetEvents(ctx context.Context, accountID, userID string) ([]*activity.Event, error) {
|
||||||
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID)
|
unlock := am.Store.AcquireWriteLockByUID(ctx, accountID)
|
||||||
@@ -56,20 +62,20 @@ func (am *DefaultAccountManager) GetEvents(ctx context.Context, accountID, userI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *DefaultAccountManager) StoreEvent(ctx context.Context, initiatorID, targetID, accountID string, activityID activity.ActivityDescriber, meta map[string]any) {
|
func (am *DefaultAccountManager) StoreEvent(ctx context.Context, initiatorID, targetID, accountID string, activityID activity.ActivityDescriber, meta map[string]any) {
|
||||||
|
if isEnabled() {
|
||||||
go func() {
|
go func() {
|
||||||
_, err := am.eventStore.Save(ctx, &activity.Event{
|
_, err := am.eventStore.Save(ctx, &activity.Event{
|
||||||
Timestamp: time.Now().UTC(),
|
Timestamp: time.Now().UTC(),
|
||||||
Activity: activityID,
|
Activity: activityID,
|
||||||
InitiatorID: initiatorID,
|
InitiatorID: initiatorID,
|
||||||
TargetID: targetID,
|
TargetID: targetID,
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// todo add metric
|
// todo add metric
|
||||||
log.WithContext(ctx).Errorf("received an error while storing an activity event, error: %s", err)
|
log.WithContext(ctx).Errorf("received an error while storing an activity event, error: %s", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user