57be07f60a
Create NodeEvents Chore on satellite core to read nodeevents DB and notify node operators on node events. The chore sends notifications grouped by email and event type: it selects the oldest entry in nodeevents.DB and also any other event with the same email and event type no matter how old it is. The oldest entry of a group must exist for a minimum amount of time before that group can be selected, however. This minimum amount of time is a configurable value: --node-events.selection-wait-period. This wait period allows us to combine events of the same time and same email address into a singular email. Change-Id: I8b444aa324d2dae265cc27d9e9e85faef79195d8
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package nodeevents
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/zeebo/errs"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// MockNotifier implements the Notifier interface.
|
|
type MockNotifier struct {
|
|
log *zap.Logger
|
|
}
|
|
|
|
// NewMockNotifier is a constructor for MockNotifier.
|
|
func NewMockNotifier(log *zap.Logger) *MockNotifier {
|
|
return &MockNotifier{
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
// Notify stores the events in the Notifications field so they can be checked.
|
|
func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []NodeEvent) (err error) {
|
|
var nodeIDs string
|
|
if len(events) == 0 {
|
|
return nil
|
|
}
|
|
for _, e := range events {
|
|
nodeIDs = nodeIDs + e.NodeID.String() + ","
|
|
}
|
|
nodeIDs = strings.TrimSuffix(nodeIDs, ",")
|
|
|
|
eventString, err := typeToString(events[0].Event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", eventString), zap.String("node IDs", nodeIDs))
|
|
return nil
|
|
}
|
|
|
|
func typeToString(event Type) (desc string, err error) {
|
|
switch event {
|
|
case Online:
|
|
desc = "online"
|
|
case Offline:
|
|
desc = "offline"
|
|
case Disqualified:
|
|
desc = "disqualified"
|
|
case UnknownAuditSuspended:
|
|
desc = "unknown audit suspended"
|
|
case UnknownAuditUnsuspended:
|
|
desc = "unknown audit unsuspended"
|
|
case OfflineSuspended:
|
|
desc = "offline suspended"
|
|
case OfflineUnsuspended:
|
|
desc = "offline unsuspended"
|
|
case BelowMinVersion:
|
|
desc = "below minimum version"
|
|
default:
|
|
err = errs.New("event type has no description")
|
|
}
|
|
return desc, err
|
|
}
|