diff --git a/satellite/nodeevents/mocknotifier.go b/satellite/nodeevents/mocknotifier.go index f600b71b8..d2a4f6f2d 100644 --- a/satellite/nodeevents/mocknotifier.go +++ b/satellite/nodeevents/mocknotifier.go @@ -7,7 +7,6 @@ import ( "context" "strings" - "github.com/zeebo/errs" "go.uber.org/zap" ) @@ -34,34 +33,10 @@ func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []No } nodeIDs = strings.TrimSuffix(nodeIDs, ",") - eventString, err := typeToString(events[0].Event) + name, err := events[0].Event.Name() 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)) + m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", name), 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 -} diff --git a/satellite/nodeevents/types.go b/satellite/nodeevents/types.go index 6901d4663..0fa71353c 100644 --- a/satellite/nodeevents/types.go +++ b/satellite/nodeevents/types.go @@ -3,6 +3,8 @@ package nodeevents +import "github.com/zeebo/errs" + // Type is a type of node event. type Type int @@ -23,4 +25,38 @@ const ( OfflineUnsuspended // BelowMinVersion indicates that the node's software is below the minimum version. BelowMinVersion + + onlineName = "online" + offlineName = "offline" + disqualifiedName = "disqualified" + unknownAuditSuspendedName = "unknown audit suspended" + unknownAuditUnsuspendedName = "unknown audit unsuspended" + offlineSuspendedName = "offline suspended" + offlineUnsuspendedName = "offline unsuspended" + belowMinVersionName = "below minimum version" ) + +// Name returns the name of the node event Type. +func (t Type) Name() (name string, err error) { + switch t { + case Online: + name = onlineName + case Offline: + name = offlineName + case Disqualified: + name = disqualifiedName + case UnknownAuditSuspended: + name = unknownAuditSuspendedName + case UnknownAuditUnsuspended: + name = unknownAuditUnsuspendedName + case OfflineSuspended: + name = offlineSuspendedName + case OfflineUnsuspended: + name = offlineUnsuspendedName + case BelowMinVersion: + name = belowMinVersionName + default: + err = errs.New("invalid Type") + } + return name, err +} diff --git a/satellite/satellitedb/nodeevents.go b/satellite/satellitedb/nodeevents.go index bfc2da15e..31b0cba21 100644 --- a/satellite/satellitedb/nodeevents.go +++ b/satellite/satellitedb/nodeevents.go @@ -31,12 +31,16 @@ func (ne *nodeEvents) Insert(ctx context.Context, email string, nodeID storj.Nod if err != nil { return nodeEvent, err } + name, err := eventType.Name() + if err != nil { + return nodeEvent, err + } entry, err := ne.db.Create_NodeEvent(ctx, dbx.NodeEvent_Id(id.Bytes()), dbx.NodeEvent_Email(email), dbx.NodeEvent_NodeId(nodeID.Bytes()), dbx.NodeEvent_Event(int(eventType)), dbx.NodeEvent_Create_Fields{}) if err != nil { return nodeEvent, err } - ne.db.log.Info("node event inserted", zap.Int("type", int(eventType)), zap.String("email", email), zap.String("node ID", nodeID.String())) + ne.db.log.Info("node event inserted", zap.String("name", name), zap.String("email", email), zap.String("node ID", nodeID.String())) return fromDBX(entry) }